[feat:] word count (per task and total) integrated
This commit is contained in:
12
InfoWindow.axaml
Normal file
12
InfoWindow.axaml
Normal 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
15
InfoWindow.axaml.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<Label x:Name="LblFilename" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" Content="Ungespeichert *" />
|
<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" />
|
<Button Content="Dark Mode" Click="OnDarkModeClick" x:Name="BtnTheme" HorizontalAlignment="Right" Margin="0,0,0,0" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
|
|||||||
@@ -83,6 +83,32 @@ namespace PLG_Exam
|
|||||||
AddNewTab();
|
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)
|
private async void OnKeyDown(object? sender, Avalonia.Input.KeyEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.KeyModifiers.HasFlag(Avalonia.Input.KeyModifiers.Control))
|
if (e.KeyModifiers.HasFlag(Avalonia.Input.KeyModifiers.Control))
|
||||||
|
|||||||
Reference in New Issue
Block a user