[fix:] fixed several issues and improved performance as well as ux

This commit is contained in:
Elias Fierke
2025-02-27 18:55:49 +01:00
parent 6f7f56acca
commit f321e28473
9 changed files with 122 additions and 35 deletions

View File

@@ -1,14 +1,11 @@
<Application xmlns="https://github.com/avaloniaui" <Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="PLG_Exam.App" x:Class="PLG_Exam.App"
RequestedThemeVariant="Dark"> RequestedThemeVariant="Light">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. --> <!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->
<Application.Styles> <Application.Styles>
<FluentTheme /> <FluentTheme />
</Application.Styles> </Application.Styles>
<Application.Resources>
<x:Double x:Key="DatePickerThemeMinWidth">10</x:Double>
<x:Double x:Key="DatePickerThemeMaxWidth">1000</x:Double>
</Application.Resources>
</Application> </Application>

View File

@@ -1,6 +1,8 @@
using Avalonia; using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Avalonia.Styling;
namespace PLG_Exam; namespace PLG_Exam;
@@ -11,6 +13,13 @@ public partial class App : Application
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
} }
public void ToggleTheme()
{
RequestedThemeVariant = RequestedThemeVariant == ThemeVariant.Dark
? ThemeVariant.Light
: ThemeVariant.Dark;
}
public override void OnFrameworkInitializationCompleted() public override void OnFrameworkInitializationCompleted()
{ {
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)

View File

@@ -7,9 +7,9 @@
Title="PLG Exam"> Title="PLG Exam">
<DockPanel Margin="10"> <DockPanel Margin="10">
<!-- Unterer Teil: Dateiverwaltung --> <!-- Unterer Teil: Dateiverwaltung -->
<Border DockPanel.Dock="Top" Background="#232327" Height="60" Margin="0,0,0,10"> <Border DockPanel.Dock="Top" x:Name="BrdTop" Height="30" Margin="0,0,0,10">
<Grid> <Grid>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="10" VerticalAlignment="Center" Spacing="10"> <StackPanel Orientation="Horizontal" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Center" Spacing="10">
<Button Content="Speichern" Click="OnSaveClick" /> <Button Content="Speichern" Click="OnSaveClick" />
<Button Content="Speichern unter..." Click="OnSaveAsClick" /> <Button Content="Speichern unter..." Click="OnSaveAsClick" />
<Button Content="Öffnen" Click="OnOpenClick" /> <Button Content="Öffnen" Click="OnOpenClick" />
@@ -17,22 +17,23 @@
<Button Content="Abgeben" Click="OnSubmitClick" /> <Button Content="Abgeben" Click="OnSubmitClick" />
</StackPanel> </StackPanel>
<Label x:Name="LblFilename" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,10" Content="Ungespeichert *" /> <Label x:Name="LblFilename" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,0" Content="Ungespeichert *" />
<Button Content="Dark Mode" Click="OnDarkModeClick" x:Name="BtnTheme" HorizontalAlignment="Right" Margin="0,0,0,0" />
</Grid> </Grid>
</Border> </Border>
<!-- Überoberer Teil: Title --> <!-- Überoberer Teil: Title -->
<Border DockPanel.Dock="Top" Background="#232327" Height="82" Margin="0,0,0,10"> <Border DockPanel.Dock="Top" x:Name="BrdTitle" Height="82" Margin="0,0,0,10">
<Grid Margin="10"> <Grid Margin="10">
<StackPanel Grid.Column="0" Margin="5" Spacing="5"> <StackPanel Grid.Column="0" Margin="5" Spacing="5">
<TextBlock Text="Titel der Arbeit" FontWeight="Bold" Foreground="White" /> <TextBlock Text="Titel der Arbeit" FontWeight="Bold" />
<TextBox Name="TitleField" Height="33"/> <TextBox Name="TitleField" Height="33"/>
</StackPanel> </StackPanel>
</Grid> </Grid>
</Border> </Border>
<!-- Oberer Teil: Name, Vorname, Datum --> <!-- Oberer Teil: Name, Vorname, Datum -->
<Border DockPanel.Dock="Top" Background="#232327" Height="82" Margin="0,0,0,10"> <Border DockPanel.Dock="Top" x:Name="BrdName" Height="82" Margin="0,0,0,10">
<Grid Margin="10"> <Grid Margin="10">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="*" /> <ColumnDefinition Width="*" />
@@ -40,22 +41,22 @@
<ColumnDefinition Width="350" /> <ColumnDefinition Width="350" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Margin="5" Spacing="5"> <StackPanel Grid.Column="0" Margin="5" Spacing="5">
<TextBlock Text="Name" FontWeight="Bold" Foreground="White" /> <TextBlock Text="Name" FontWeight="Bold" />
<TextBox Name="NameField" Height="33"/> <TextBox Name="NameField" Height="33"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Column="1" Margin="5" Spacing="5"> <StackPanel Grid.Column="1" Margin="5" Spacing="5">
<TextBlock Text="Vorname" FontWeight="Bold" Foreground="White" /> <TextBlock Text="Vorname" FontWeight="Bold" />
<TextBox Name="VornameField" Height="33"/> <TextBox Name="VornameField" Height="33"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Column="2" Margin="5" Spacing="5"> <StackPanel Grid.Column="2" Margin="5" Spacing="5">
<TextBlock Text="Datum" HorizontalAlignment="Stretch" FontWeight="Bold" Foreground="White" /> <TextBlock Text="Datum" HorizontalAlignment="Stretch" FontWeight="Bold" />
<DatePicker Name="DatumField" Width="340" Height="33" /> <DatePicker Name="DatumField" Width="340" Height="33" />
</StackPanel> </StackPanel>
</Grid> </Grid>
</Border> </Border>
<!-- Mittlerer Teil: Tabansicht --> <!-- Mittlerer Teil: Tabansicht -->
<Border Background="#232327" Margin="0,0,0,0"> <Border x:Name="BrdMid" Margin="0,0,0,0">
<DockPanel> <DockPanel>
<Button Content="Weitere Aufgabenlösung hinzufügen" DockPanel.Dock="Top" HorizontalAlignment="Center" Margin="10,10,10,0" Click="OnAddTabClick" /> <Button Content="Weitere Aufgabenlösung hinzufügen" DockPanel.Dock="Top" HorizontalAlignment="Center" Margin="10,10,10,0" Click="OnAddTabClick" />
<TabControl Name="TabView" Margin="10"> <TabControl Name="TabView" Margin="10">

View File

@@ -19,9 +19,8 @@ using PdfSharp.Fonts;
using System.Globalization; using System.Globalization;
using MigraDoc.DocumentObjectModel; using MigraDoc.DocumentObjectModel;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using Avalonia.Styling;
// ToDo using Avalonia.Themes.Fluent;
// - White Mode Access
namespace PLG_Exam namespace PLG_Exam
@@ -41,6 +40,41 @@ namespace PLG_Exam
this.KeyDown += OnKeyDown; this.KeyDown += OnKeyDown;
GlobalFontSettings.FontResolver = new CustomFontResolver(); GlobalFontSettings.FontResolver = new CustomFontResolver();
RenewColors();
this.Closing += MainWindow_Closing;
}
private void OnDarkModeClick(object? sender, RoutedEventArgs e)
{
if (Application.Current is App app)
{
app.ToggleTheme();
RenewColors();
}
}
private void RenewColors(){
if(Application.Current.ActualThemeVariant == ThemeVariant.Dark){
BrdMid.Background = new SolidColorBrush(Avalonia.Media.Color.FromRgb(35,35,39)); // #232327
//BrdTop.Background = new SolidColorBrush(Avalonia.Media.Color.FromRgb(35,35,39)); // #232327
BrdTitle.Background = new SolidColorBrush(Avalonia.Media.Color.FromRgb(35,35,39)); // #232327
BrdName.Background = new SolidColorBrush(Avalonia.Media.Color.FromRgb(35,35,39)); // #232327
} else {
BrdMid.Background = new SolidColorBrush(Avalonia.Media.Color.FromRgb(230,230,230)); // #232327
//BrdTop.Background = new SolidColorBrush(Avalonia.Media.Color.FromRgb(230,230,230)); // #232327
BrdTitle.Background = new SolidColorBrush(Avalonia.Media.Color.FromRgb(230,230,230)); // #232327
BrdName.Background = new SolidColorBrush(Avalonia.Media.Color.FromRgb(230,230,230)); // #232327
}
if(Application.Current.ActualThemeVariant == ThemeVariant.Dark){
BtnTheme.Content="🌞";
} else {
BtnTheme.Content="🌙";
}
} }
// Event für "Neuen Tab hinzufügen" // Event für "Neuen Tab hinzufügen"
@@ -296,7 +330,9 @@ namespace PLG_Exam
_currentFilePath = filePath; _currentFilePath = filePath;
_isSaved = true; _isSaved = true;
LblFilename.Content = !_currentFilePath.IsValueNullOrEmpty() ? Path.GetFileName(_currentFilePath) : "Ungespeichert "; LblFilename.Content = !_currentFilePath.IsValueNullOrEmpty() ? Path.GetFileName(_currentFilePath) : "Ungespeichert *";
SaveToFile(filePath);
} }
private StackPanel ReturnTabHeaderContent(string name, TabItem curr_tab){ private StackPanel ReturnTabHeaderContent(string name, TabItem curr_tab){
@@ -347,6 +383,30 @@ namespace PLG_Exam
return headerStackPanel; return headerStackPanel;
} }
private async void MainWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
if (!_isSaved)
{
MessageBoxResult result = await MessageBox.Show(this, "Möchten Sie die aktuellen Änderungen speichern?",
"Nicht gespeicherte Änderungen", MessageBoxButton.YesNoCancel);
if (result == MessageBoxResult.Cancel) {
e.Cancel = true;
return;
}
if (result == MessageBoxResult.Yes) {
//SaveToFile(_currentFilePath);
OnSaveClick(null,null);
if(_isSaved == false){
e.Cancel = true;
return;
}
}
}
e.Cancel = false;
Environment.Exit(0);
}
// Neu // Neu
private async void OnNewClick(object? sender, RoutedEventArgs e) private async void OnNewClick(object? sender, RoutedEventArgs e)
{ {
@@ -371,7 +431,7 @@ namespace PLG_Exam
_currentFilePath = null; _currentFilePath = null;
_isSaved = true; _isSaved = true;
LblFilename.Content = (!_currentFilePath.IsValueNullOrEmpty() ? Path.GetFileName(_currentFilePath) : "Ungespeichert ") + " *"; LblFilename.Content = !_currentFilePath.IsValueNullOrEmpty() ? Path.GetFileName(_currentFilePath) : "Ungespeichert *";
} }
private Grid CreateTabContent(string? aufgabennummer = null, string? ueberschrift = null, string? beschreibung = null) private Grid CreateTabContent(string? aufgabennummer = null, string? ueberschrift = null, string? beschreibung = null)

View File

@@ -42,12 +42,12 @@ public partial class MessageBox : Window
AddButton("Ok", MessageBoxResult.Ok, true); AddButton("Ok", MessageBoxResult.Ok, true);
if (buttons == MessageBoxButton.YesNo || buttons == MessageBoxButton.YesNoCancel) if (buttons == MessageBoxButton.YesNo || buttons == MessageBoxButton.YesNoCancel)
{ {
AddButton("Yes", MessageBoxResult.Yes); AddButton("Ja", MessageBoxResult.Yes);
AddButton("No", MessageBoxResult.No, true); AddButton("Nein", MessageBoxResult.No, true);
} }
if (buttons == MessageBoxButton.OkCancel || buttons == MessageBoxButton.YesNoCancel) if (buttons == MessageBoxButton.OkCancel || buttons == MessageBoxButton.YesNoCancel)
AddButton("Cancel", MessageBoxResult.Cancel, true); AddButton("Abbrechen", MessageBoxResult.Cancel, true);

16
ThemeManager.cs Normal file
View File

@@ -0,0 +1,16 @@
using System;
using Avalonia;
namespace PLG_Exam;
public static class ThemeManager
{
public static string CurrentBackgroundColor
{
get
{
return nameof(Application.RequestedThemeVariant) + "ModeBackground";
//return isDarkMode ? "DarkModeBackground" : "LightModeBackground";
}
}
}

View File

@@ -54,6 +54,8 @@
"version": "[11.2.1, )" "version": "[11.2.1, )"
}, },
"Avalonia.Diagnostics": { "Avalonia.Diagnostics": {
"include": "None",
"suppressParent": "All",
"target": "Package", "target": "Package",
"version": "[11.2.1, )" "version": "[11.2.1, )"
}, },

View File

@@ -114,12 +114,12 @@
"Avalonia.Remote.Protocol": "11.2.1" "Avalonia.Remote.Protocol": "11.2.1"
}, },
"compile": { "compile": {
"lib/net8.0/Avalonia.Controls.ColorPicker.dll": { "lib/net8.0/_._": {
"related": ".xml" "related": ".xml"
} }
}, },
"runtime": { "runtime": {
"lib/net8.0/Avalonia.Controls.ColorPicker.dll": { "lib/net8.0/_._": {
"related": ".xml" "related": ".xml"
} }
} }
@@ -131,12 +131,12 @@
"Avalonia.Remote.Protocol": "11.2.1" "Avalonia.Remote.Protocol": "11.2.1"
}, },
"compile": { "compile": {
"lib/net8.0/Avalonia.Controls.DataGrid.dll": { "lib/net8.0/_._": {
"related": ".xml" "related": ".xml"
} }
}, },
"runtime": { "runtime": {
"lib/net8.0/Avalonia.Controls.DataGrid.dll": { "lib/net8.0/_._": {
"related": ".xml" "related": ".xml"
} }
} }
@@ -170,12 +170,12 @@
"Avalonia.Themes.Simple": "11.2.1" "Avalonia.Themes.Simple": "11.2.1"
}, },
"compile": { "compile": {
"lib/net8.0/Avalonia.Diagnostics.dll": { "lib/net8.0/_._": {
"related": ".xml" "related": ".xml"
} }
}, },
"runtime": { "runtime": {
"lib/net8.0/Avalonia.Diagnostics.dll": { "lib/net8.0/_._": {
"related": ".xml" "related": ".xml"
} }
} }
@@ -292,12 +292,12 @@
"Avalonia": "11.2.1" "Avalonia": "11.2.1"
}, },
"compile": { "compile": {
"lib/net8.0/Avalonia.Themes.Simple.dll": { "lib/net8.0/_._": {
"related": ".xml" "related": ".xml"
} }
}, },
"runtime": { "runtime": {
"lib/net8.0/Avalonia.Themes.Simple.dll": { "lib/net8.0/_._": {
"related": ".xml" "related": ".xml"
} }
} }
@@ -6388,6 +6388,8 @@
"version": "[11.2.1, )" "version": "[11.2.1, )"
}, },
"Avalonia.Diagnostics": { "Avalonia.Diagnostics": {
"include": "None",
"suppressParent": "All",
"target": "Package", "target": "Package",
"version": "[11.2.1, )" "version": "[11.2.1, )"
}, },

View File

@@ -1,6 +1,6 @@
{ {
"version": 2, "version": 2,
"dgSpecHash": "YIPRJ6ABhso=", "dgSpecHash": "mnXgl9Kb58w=",
"success": true, "success": true,
"projectFilePath": "/home/fierke/Nextcloud/Documents/source/repos/PLG_Exam/PLG-Exam/PLG-Exam.csproj", "projectFilePath": "/home/fierke/Nextcloud/Documents/source/repos/PLG_Exam/PLG-Exam/PLG-Exam.csproj",
"expectedPackageFiles": [ "expectedPackageFiles": [