From cbf85f6cd1780e57ab46b5a3cf845438adfd2d69 Mon Sep 17 00:00:00 2001
From: XanatosX <10531466+XanatosX@users.noreply.github.com>
Date: Mon, 1 Jan 2024 14:28:53 +0100
Subject: [PATCH 1/4] Add possibility for all modals to be closed with escc Add
code to precent modal resize by user
---
src/ModularToolManager/ViewModels/AboutViewModel.cs | 11 +++++++++++
.../ViewModels/HotkeysViewModel.cs | 13 +++++++++++++
.../ViewModels/ModalWindowViewModel.cs | 7 +++++++
src/ModularToolManager/Views/AboutView.axaml | 1 +
src/ModularToolManager/Views/AllPluginsView.axaml | 2 +-
src/ModularToolManager/Views/HotkeysView.axaml | 5 ++++-
src/ModularToolManager/Views/ModalWindow.axaml | 1 +
7 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/src/ModularToolManager/ViewModels/AboutViewModel.cs b/src/ModularToolManager/ViewModels/AboutViewModel.cs
index 27c4656..7b8368d 100644
--- a/src/ModularToolManager/ViewModels/AboutViewModel.cs
+++ b/src/ModularToolManager/ViewModels/AboutViewModel.cs
@@ -1,6 +1,8 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
+using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.DependencyInjection;
+using ModularToolManager.Models.Messages;
using ModularToolManager.Services.IO;
using ModularToolManagerModel.Services.Dependency;
using ModularToolManagerModel.Services.IO;
@@ -83,4 +85,13 @@ private void OpenUrl(string url)
{
urlOpenerService.OpenUrl(url);
}
+
+ ///
+ /// Command to use to close the modal
+ ///
+ [RelayCommand]
+ private void Abort()
+ {
+ WeakReferenceMessenger.Default.Send(new CloseModalMessage(this));
+ }
}
diff --git a/src/ModularToolManager/ViewModels/HotkeysViewModel.cs b/src/ModularToolManager/ViewModels/HotkeysViewModel.cs
index f5b21e0..61fb425 100644
--- a/src/ModularToolManager/ViewModels/HotkeysViewModel.cs
+++ b/src/ModularToolManager/ViewModels/HotkeysViewModel.cs
@@ -1,4 +1,7 @@
using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using CommunityToolkit.Mvvm.Messaging;
+using ModularToolManager.Models.Messages;
using ModularToolManager.Services.IO;
using System.Collections.Generic;
using System.Linq;
@@ -27,4 +30,14 @@ public HotkeysViewModel(GetApplicationInformationService applicationInformationS
.Select(hotkey => new SingleHotkeyViewModel(hotkey))
.ToList();
}
+
+
+ ///
+ /// Command to use to close the modal
+ ///
+ [RelayCommand]
+ private void Abort()
+ {
+ WeakReferenceMessenger.Default.Send(new CloseModalMessage(this));
+ }
}
diff --git a/src/ModularToolManager/ViewModels/ModalWindowViewModel.cs b/src/ModularToolManager/ViewModels/ModalWindowViewModel.cs
index 154f523..2174bd5 100644
--- a/src/ModularToolManager/ViewModels/ModalWindowViewModel.cs
+++ b/src/ModularToolManager/ViewModels/ModalWindowViewModel.cs
@@ -42,6 +42,12 @@ public partial class ModalWindowViewModel : ObservableObject
///
[ObservableProperty]
private float materialOpacity;
+
+ ///
+ /// Can the modal be resized
+ ///
+ [ObservableProperty]
+ public bool canResize;
///
/// The service used to switch the application theme
@@ -74,6 +80,7 @@ public ModalWindowViewModel(
Title = windowInformation.Title;
ModalContent = windowInformation.modalContent;
this.themeService = themeService;
+ CanResize = windowInformation.CanResize;
PathIcon = styleService.GetStyleByName(windowInformation.IconName ?? string.Empty) ?? null;
if (PathIcon is not null)
{
diff --git a/src/ModularToolManager/Views/AboutView.axaml b/src/ModularToolManager/Views/AboutView.axaml
index a828fc2..641d314 100644
--- a/src/ModularToolManager/Views/AboutView.axaml
+++ b/src/ModularToolManager/Views/AboutView.axaml
@@ -24,5 +24,6 @@
+
diff --git a/src/ModularToolManager/Views/AllPluginsView.axaml b/src/ModularToolManager/Views/AllPluginsView.axaml
index ff3da82..024e6df 100644
--- a/src/ModularToolManager/Views/AllPluginsView.axaml
+++ b/src/ModularToolManager/Views/AllPluginsView.axaml
@@ -25,7 +25,7 @@
-
+
diff --git a/src/ModularToolManager/Views/HotkeysView.axaml b/src/ModularToolManager/Views/HotkeysView.axaml
index b75fd70..b350938 100644
--- a/src/ModularToolManager/Views/HotkeysView.axaml
+++ b/src/ModularToolManager/Views/HotkeysView.axaml
@@ -4,5 +4,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="ModularToolManager.Views.HotkeysView">
-
+
+
+
+
diff --git a/src/ModularToolManager/Views/ModalWindow.axaml b/src/ModularToolManager/Views/ModalWindow.axaml
index b58b6f8..c60e528 100644
--- a/src/ModularToolManager/Views/ModalWindow.axaml
+++ b/src/ModularToolManager/Views/ModalWindow.axaml
@@ -10,6 +10,7 @@
ExtendClientAreaToDecorationsHint="True"
WindowStartupLocation="CenterOwner"
SizeToContent="WidthAndHeight"
+ CanResize="{Binding CanResize}"
MinWidth="300">
From 4e53e9ed53bf723fb33652d81f821053ed1d81ff Mon Sep 17 00:00:00 2001
From: XanatosX <10531466+XanatosX@users.noreply.github.com>
Date: Mon, 1 Jan 2024 14:32:25 +0100
Subject: [PATCH 2/4] Add code to prevent user window resize
---
.../ViewModels/MainWindowViewModel.cs | 22 ++++++++++++++-----
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/src/ModularToolManager/ViewModels/MainWindowViewModel.cs b/src/ModularToolManager/ViewModels/MainWindowViewModel.cs
index 144c8a6..3d5a84a 100644
--- a/src/ModularToolManager/ViewModels/MainWindowViewModel.cs
+++ b/src/ModularToolManager/ViewModels/MainWindowViewModel.cs
@@ -194,7 +194,7 @@ private void UpdateShowInTaskbar()
[RelayCommand]
private async Task OpenPlugins()
{
- await OpenModalWindow(Properties.Resources.SubMenu_Plugins, Properties.Properties.Icon_new_function, nameof(AllPluginsViewModel));
+ await OpenModalWindow(Properties.Resources.SubMenu_Plugins, Properties.Properties.Icon_new_function, nameof(AllPluginsViewModel), false);
}
///
@@ -204,7 +204,7 @@ private async Task OpenPlugins()
[RelayCommand]
private async Task NewFunction()
{
- await OpenModalWindow(Properties.Resources.SubMenu_NewFunction, Properties.Properties.Icon_new_function, nameof(AddFunctionViewModel));
+ await OpenModalWindow(Properties.Resources.SubMenu_NewFunction, Properties.Properties.Icon_new_function, nameof(AddFunctionViewModel), false);
WeakReferenceMessenger.Default.Send(new ReloadFunctionsMessage());
}
@@ -228,7 +228,7 @@ private async Task OpenSettings()
[RelayCommand]
private async Task OpenAbout()
{
- await OpenModalWindow(Properties.Resources.SubMenu_About, Properties.Properties.Icon_About, nameof(AboutViewModel));
+ await OpenModalWindow(Properties.Resources.SubMenu_About, Properties.Properties.Icon_About, nameof(AboutViewModel), false);
}
///
@@ -238,7 +238,7 @@ private async Task OpenAbout()
[RelayCommand]
private async Task OpenHotkey()
{
- await OpenModalWindow(Properties.Resources.SubMenu_Hotkeys, Properties.Properties.Icon_Keyboard, nameof(HotkeysViewModel));
+ await OpenModalWindow(Properties.Resources.SubMenu_Hotkeys, Properties.Properties.Icon_Keyboard, nameof(HotkeysViewModel), false);
}
///
@@ -274,6 +274,7 @@ private void SaveOrderMode()
ToggleOrderMode(false);
}
+
///
/// Method to open a modal window
///
@@ -281,20 +282,29 @@ private void SaveOrderMode()
/// The image path to show
/// The name of the modal to show
///
- private async Task OpenModalWindow(string title, string imagePath, string modalName)
+ private async Task OpenModalWindow(string title, string imagePath, string modalName, bool canResize )
{
var modalContent = viewModelLocator.GetViewModel(modalName);
if (modalContent is null)
{
return;
}
- ShowWindowModel modalWindowData = new(title, imagePath, modalContent, WindowStartupLocation.CenterScreen);
+ ShowWindowModel modalWindowData = new(title, imagePath, modalContent, WindowStartupLocation.CenterScreen, canResize);
if (windowManagementService is not null)
{
await windowManagementService.ShowModalWindowAsync(modalWindowData, windowManagementService?.GetMainWindow());
}
}
+ ///
+ /// Method to open a modal window
+ ///
+ /// The title to use
+ /// The image path to show
+ /// The name of the modal to show
+ ///
+ private async Task OpenModalWindow(string title, string imagePath, string modalName) => OpenModalWindow(title, imagePath, modalName, true);
+
///
/// Method to open a modal window
///
From 32f6634577cb747c376a030c80a6bedac9ab9444 Mon Sep 17 00:00:00 2001
From: XanatosX <10531466+XanatosX@users.noreply.github.com>
Date: Mon, 1 Jan 2024 15:40:17 +0100
Subject: [PATCH 3/4] Fix warnings in code Fix left over code issues with
avalonia 10 -> 11 upgrade
---
src/ModularToolManager/App.axaml.cs | 6 +++++-
.../Models/ApplicationStyle.cs | 2 +-
.../Models/Messages/DeleteFunctionMessage.cs | 2 +-
.../Models/Messages/EditFunctionMessage.cs | 2 +-
.../Messages/RequestApplicationVisiblity.cs | 4 ++--
.../Models/ShowOpenFileDialogModel.cs | 7 ++++---
.../Language/ResourceCultureService.cs | 4 ++--
.../Services/Styling/DefaultStyleService.cs | 4 ++++
.../Services/Ui/WindowManagementService.cs | 19 ++++++++-----------
src/ModularToolManager/ViewLocator.cs | 8 ++++++--
.../ViewModels/AddFunctionViewModel.cs | 12 ++++++------
.../ViewModels/AppViewModel.cs | 10 ++++------
.../ViewModels/DependencyViewModel.cs | 10 +++++-----
.../ViewModels/FunctionButtonViewModel.cs | 16 ++++++++--------
.../ViewModels/IntPluginSettingViewModel.cs | 8 ++++----
.../ViewModels/MainWindowViewModel.cs | 4 ++--
.../StringPluginSettingViewModel.cs | 2 +-
.../Views/MainWindow.axaml.cs | 2 +-
.../Data/FunctionModel.cs | 4 +++-
.../Services/Functions/IFunctionService.cs | 4 ++--
.../Services/Language/ILanguageService.cs | 4 ++--
21 files changed, 72 insertions(+), 62 deletions(-)
diff --git a/src/ModularToolManager/App.axaml.cs b/src/ModularToolManager/App.axaml.cs
index be2d0f4..d09b000 100644
--- a/src/ModularToolManager/App.axaml.cs
+++ b/src/ModularToolManager/App.axaml.cs
@@ -81,12 +81,16 @@ public override void OnFrameworkInitializationCompleted()
{
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
+ if (desktop is null || desktop.MainWindow is null)
+ {
+ return;
+ }
desktop.ShutdownMode = Avalonia.Controls.ShutdownMode.OnExplicitShutdown;
if (desktop.MainWindow is IDisposable disposable)
{
disposable.Dispose();
}
- desktop.MainWindow.Close();
+ desktop!.MainWindow!.Close();
SetupMainWindow(provider);
desktop.MainWindow.Show();
desktop.ShutdownMode = Avalonia.Controls.ShutdownMode.OnLastWindowClose;
diff --git a/src/ModularToolManager/Models/ApplicationStyle.cs b/src/ModularToolManager/Models/ApplicationStyle.cs
index 40e0a36..5a649f7 100644
--- a/src/ModularToolManager/Models/ApplicationStyle.cs
+++ b/src/ModularToolManager/Models/ApplicationStyle.cs
@@ -20,7 +20,7 @@ public class ApplicationStyle
/// Is this a dark or light style variant
///
[JsonPropertyName("mode")]
- public ThemeVariant Variant { get; init; }
+ public ThemeVariant? Variant { get; init; }
///
/// The name of the translation key which is getting used for the name
diff --git a/src/ModularToolManager/Models/Messages/DeleteFunctionMessage.cs b/src/ModularToolManager/Models/Messages/DeleteFunctionMessage.cs
index 34a9f38..525a505 100644
--- a/src/ModularToolManager/Models/Messages/DeleteFunctionMessage.cs
+++ b/src/ModularToolManager/Models/Messages/DeleteFunctionMessage.cs
@@ -18,6 +18,6 @@ internal class DeleteFunctionMessage : RequestMessage
/// The function to delete
public DeleteFunctionMessage(FunctionModel functionModel)
{
- Identifier = functionModel.UniqueIdentifier;
+ Identifier = functionModel.Id;
}
}
diff --git a/src/ModularToolManager/Models/Messages/EditFunctionMessage.cs b/src/ModularToolManager/Models/Messages/EditFunctionMessage.cs
index 8818b23..15c51bf 100644
--- a/src/ModularToolManager/Models/Messages/EditFunctionMessage.cs
+++ b/src/ModularToolManager/Models/Messages/EditFunctionMessage.cs
@@ -18,6 +18,6 @@ internal class EditFunctionMessage : AsyncRequestMessage
/// The function model to edit
public EditFunctionMessage(FunctionModel functionModel)
{
- Identifier = functionModel.UniqueIdentifier;
+ Identifier = functionModel.Id;
}
}
diff --git a/src/ModularToolManager/Models/Messages/RequestApplicationVisiblity.cs b/src/ModularToolManager/Models/Messages/RequestApplicationVisiblity.cs
index 8aed441..bc83686 100644
--- a/src/ModularToolManager/Models/Messages/RequestApplicationVisiblity.cs
+++ b/src/ModularToolManager/Models/Messages/RequestApplicationVisiblity.cs
@@ -3,6 +3,6 @@
namespace ModularToolManager.Models.Messages;
///
-/// Get the current visiblilty for the application
+/// Get the current visibility for the application
///
-internal class RequestApplicationVisiblity : RequestMessage { }
+internal class RequestApplicationVisibility : RequestMessage { }
diff --git a/src/ModularToolManager/Models/ShowOpenFileDialogModel.cs b/src/ModularToolManager/Models/ShowOpenFileDialogModel.cs
index a3dff86..c315f60 100644
--- a/src/ModularToolManager/Models/ShowOpenFileDialogModel.cs
+++ b/src/ModularToolManager/Models/ShowOpenFileDialogModel.cs
@@ -1,12 +1,13 @@
using Avalonia.Controls;
+using Avalonia.Platform.Storage;
using System.Collections.Generic;
namespace ModularToolManager.Models;
///
-/// Record for the openinig a file open dialog
+/// Record for the opening a file open dialog
///
/// The filter for the dialog
-/// The directory to start in
+/// The directory to start in
/// Allow selecting multiple files
-public record ShowOpenFileDialogModel(List FileDialogFilters, string? InialDirectory, bool AllowMultipleSelection);
+public record ShowOpenFileDialogModel(List FileDialogFilters, string? InitialDirectory, bool AllowMultipleSelection);
diff --git a/src/ModularToolManager/Services/Language/ResourceCultureService.cs b/src/ModularToolManager/Services/Language/ResourceCultureService.cs
index fc7c328..1b7d55e 100644
--- a/src/ModularToolManager/Services/Language/ResourceCultureService.cs
+++ b/src/ModularToolManager/Services/Language/ResourceCultureService.cs
@@ -84,11 +84,11 @@ public List GetAvailableCultures()
}
logger.LogTrace("Load available cultures from resources");
string applicationLocation = pathService.GetApplicationExecutableString();
- string resoureFileName = Path.GetFileNameWithoutExtension(applicationLocation) + ".resources.dll";
+ string resourceFileName = Path.GetFileNameWithoutExtension(applicationLocation) + ".resources.dll";
DirectoryInfo? rootDirectory = pathService.GetApplicationPath();
availableCultures = rootDirectory?.GetDirectories()
.Where(dir => CultureInfo.GetCultures(CultureTypes.AllCultures).Any(culture => culture.Name == dir.Name))
- .Where(dir => File.Exists(Path.Combine(dir.FullName, resoureFileName)))
+ .Where(dir => File.Exists(Path.Combine(dir.FullName, resourceFileName)))
.Select(dir => CultureInfo.GetCultureInfo(dir.Name))
.ToList() ?? new();
if (!availableCultures.Contains(CultureInfo.GetCultureInfo(Properties.Properties.FallbackLanguage)))
diff --git a/src/ModularToolManager/Services/Styling/DefaultStyleService.cs b/src/ModularToolManager/Services/Styling/DefaultStyleService.cs
index 976c9ae..abfd2d7 100644
--- a/src/ModularToolManager/Services/Styling/DefaultStyleService.cs
+++ b/src/ModularToolManager/Services/Styling/DefaultStyleService.cs
@@ -39,6 +39,10 @@ public IEnumerable