[feat:] word count (per task and total) integrated

This commit is contained in:
Elias Fierke
2025-03-22 18:42:52 +01:00
parent 1997c14890
commit d2de5974c3
4 changed files with 54 additions and 0 deletions

12
InfoWindow.axaml Normal file
View File

@@ -0,0 +1,12 @@
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Width="200" Height="200"
x:Class="PLG_Exam.InfoWindow"
Title="InfoWindow">
<ScrollViewer>
<Label Content="" x:Name="LblInfo" />
</ScrollViewer>
</Window>

15
InfoWindow.axaml.cs Normal file
View File

@@ -0,0 +1,15 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace PLG_Exam;
public partial class InfoWindow : Window
{
public InfoWindow(string cnt)
{
InitializeComponent();
LblInfo.Content=cnt;
}
}

View File

@@ -18,6 +18,7 @@
</StackPanel>
<Label x:Name="LblFilename" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" Content="Ungespeichert *" />
<Button Content="(i)" Click="OnInfoClick" x:Name="BtnInfo" HorizontalAlignment="Right" Margin="0,0,35,0" />
<Button Content="Dark Mode" Click="OnDarkModeClick" x:Name="BtnTheme" HorizontalAlignment="Right" Margin="0,0,0,0" />
</Grid>
</Border>

View File

@@ -83,6 +83,32 @@ namespace PLG_Exam
AddNewTab();
}
private void OnInfoClick(object? sender, RoutedEventArgs e)
{
new InfoWindow(CountTotalWords()).Show();
}
public int CountWords(string s)
{
s = s.Trim();
if (s == "")
return 0;
return s.Split(new char[] { ' ', '.', '?', '!', ',', '\n' }, StringSplitOptions.RemoveEmptyEntries).Length;
}
public string CountTotalWords(){
_ = GetCurrentExamDataAsJson();
string toReturn = "";
int totalWords = 0;
foreach (var tab in _currentExam.Tabs)
{
totalWords += CountWords(tab.Inhalt);
toReturn += "Aufgabe " + tab.Aufgabennummer + ": " + CountWords(tab.Inhalt) + "\n";
}
return $"Anzahl Wörter (insg.): {totalWords}\n" + toReturn;
}
private async void OnKeyDown(object? sender, Avalonia.Input.KeyEventArgs e)
{
if (e.KeyModifiers.HasFlag(Avalonia.Input.KeyModifiers.Control))