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 @@ +