diff --git a/src/ModularToolManager/App.axaml.cs b/src/ModularToolManager/App.axaml.cs
index 46915a1..fa73e33 100644
--- a/src/ModularToolManager/App.axaml.cs
+++ b/src/ModularToolManager/App.axaml.cs
@@ -5,23 +5,17 @@
using Avalonia.Markup.Xaml;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.Extensions.DependencyInjection;
-using Microsoft.Extensions.Logging;
using ModularToolManager.DependencyInjection;
using ModularToolManager.Models.Messages;
-using ModularToolManager.Services.IO;
using ModularToolManager.Services.Settings;
-using ModularToolManager.Services.Ui;
using ModularToolManager.ViewModels;
using ModularToolManager.Views;
using ModularToolManagerModel.Services.IO;
using ModularToolManagerModel.Services.Language;
-using ModularToolManagerModel.Services.Logging;
using Serilog;
using System;
-using System.Collections.Generic;
using System.Globalization;
using System.IO;
-using System.Linq;
namespace ModularToolManager;
diff --git a/src/ModularToolManager/Models/Messages/ModalWindowOpened.cs b/src/ModularToolManager/Models/Messages/ModalWindowOpened.cs
new file mode 100644
index 0000000..43591bb
--- /dev/null
+++ b/src/ModularToolManager/Models/Messages/ModalWindowOpened.cs
@@ -0,0 +1,17 @@
+using CommunityToolkit.Mvvm.Messaging.Messages;
+
+namespace ModularToolManager.Models.Messages;
+
+///
+/// Message if a modal window was opened or closed
+///
+internal class ModalWindowOpened : ValueChangedMessage
+{
+ ///
+ /// Create a new instance of this message
+ ///
+ /// Bool if the modal window was opened (true) or closed (false)
+ public ModalWindowOpened(bool isOpen) : base(isOpen)
+ {
+ }
+}
diff --git a/src/ModularToolManager/ViewModels/AppViewModel.cs b/src/ModularToolManager/ViewModels/AppViewModel.cs
index f14411d..db14154 100644
--- a/src/ModularToolManager/ViewModels/AppViewModel.cs
+++ b/src/ModularToolManager/ViewModels/AppViewModel.cs
@@ -1,7 +1,9 @@
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
+using Microsoft.Extensions.Logging;
using ModularToolManager.Models.Messages;
+using Serilog;
using System.Windows.Input;
namespace ModularToolManager.ViewModels;
@@ -21,18 +23,37 @@ public class AppViewModel : ObservableObject
///
public ICommand ShowApplicationCommand { get; }
+ ///
+ /// The current number of modal windows which are open
+ ///
+ private int numberOfOpenModalWindows;
+
+ ///
+ /// Logger to use for the app view
+ ///
+ private readonly ILogger logger;
+
///
/// Create a new instance of this class
///
- public AppViewModel()
+ public AppViewModel(ILogger logger)
{
+ numberOfOpenModalWindows = 0;
+
+ WeakReferenceMessenger.Default.Register(this, (_, message) => numberOfOpenModalWindows += message.Value ? 1 : -1);
+
ShowApplicationCommand = new RelayCommand(() =>
{
+ if (numberOfOpenModalWindows > 0)
+ {
+ logger.LogWarning($"Tried to minimize app while {numberOfOpenModalWindows} where opend");
+ return;
+ }
var response = WeakReferenceMessenger.Default.Send(new RequestApplicationVisiblity());
bool toggleMode = response.HasReceivedResponse ? response.Response : false;
WeakReferenceMessenger.Default.Send(new ToggleApplicationVisibilityMessage(toggleMode));
-
});
ExitApplicationCommand = new RelayCommand(() => WeakReferenceMessenger.Default.Send(new CloseApplicationMessage()));
+ this.logger = logger;
}
}
diff --git a/src/ModularToolManager/Views/ModalWindow.axaml.cs b/src/ModularToolManager/Views/ModalWindow.axaml.cs
index 784f2b8..6b7d985 100644
--- a/src/ModularToolManager/Views/ModalWindow.axaml.cs
+++ b/src/ModularToolManager/Views/ModalWindow.axaml.cs
@@ -4,6 +4,8 @@
using CommunityToolkit.Mvvm.Messaging;
using ModularToolManager.Models.Messages;
using ModularToolManager.ViewModels;
+using System;
+using System.ComponentModel;
namespace ModularToolManager.Views;
@@ -32,4 +34,16 @@ private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
+
+ protected override void OnOpened(EventArgs e)
+ {
+ WeakReferenceMessenger.Default.Send(new ModalWindowOpened(true));
+ base.OnOpened(e);
+ }
+
+ protected override void OnClosing(CancelEventArgs e)
+ {
+ WeakReferenceMessenger.Default.Send(new ModalWindowOpened(false));
+ base.OnClosing(e);
+ }
}