From 252c8eaaf2f73697e70691e75434de875f21784c Mon Sep 17 00:00:00 2001 From: BornToBeRoot <16019165+BornToBeRoot@users.noreply.github.com> Date: Wed, 12 Nov 2025 21:32:30 +0100 Subject: [PATCH 1/5] Feature: More child dialogs --- .../ViewModels/PowerShellHostViewModel.cs | 33 ++++++---- .../ViewModels/RemoteDesktopHostViewModel.cs | 4 +- ...xaml => PowerShellConnectChildWindow.xaml} | 64 ++++++++++--------- .../PowerShellConnectChildWindow.xaml.cs | 21 ++++++ .../Views/PowerShellConnectDialog.xaml.cs | 16 ----- .../RemoteDesktopConnectChildWindow.xaml.cs | 2 +- 6 files changed, 77 insertions(+), 63 deletions(-) rename Source/NETworkManager/Views/{PowerShellConnectDialog.xaml => PowerShellConnectChildWindow.xaml} (62%) create mode 100644 Source/NETworkManager/Views/PowerShellConnectChildWindow.xaml.cs delete mode 100644 Source/NETworkManager/Views/PowerShellConnectDialog.xaml.cs diff --git a/Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs b/Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs index 7836fb0e0b..701b42e3ef 100644 --- a/Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs @@ -1,6 +1,7 @@ using Dragablz; using log4net; using MahApps.Metro.Controls.Dialogs; +using MahApps.Metro.SimpleChildWindow; using NETworkManager.Controls; using NETworkManager.Localization.Resources; using NETworkManager.Models; @@ -579,16 +580,15 @@ private void TryFindExecutable() Log.Warn("Install PowerShell or configure the path in the settings."); } - private async Task Connect(string host = null) + private Task Connect(string host = null) { - var customDialog = new CustomDialog - { - Title = Strings.Connect - }; + var childWindow = new PowerShellConnectChildWindow(); - var connectViewModel = new PowerShellConnectViewModel(async instance => + var childWindowViewModel = new PowerShellConnectViewModel(instance => { - await _dialogCoordinator.HideMetroDialogAsync(this, customDialog); + childWindow.IsOpen = false; + ConfigurationManager.Current.IsChildWindowOpen = false; + ConfigurationManager.OnDialogClose(); // Create profile info @@ -608,19 +608,24 @@ private async Task Connect(string host = null) // Connect Connect(sessionInfo); - }, async _ => + + }, _ => { - await _dialogCoordinator.HideMetroDialogAsync(this, customDialog); + childWindow.IsOpen = false; + ConfigurationManager.Current.IsChildWindowOpen = false; + ConfigurationManager.OnDialogClose(); }, host); - customDialog.Content = new PowerShellConnectDialog - { - DataContext = connectViewModel - }; + childWindow.Title = Strings.Connect; + + childWindow.DataContext = childWindowViewModel; + + ConfigurationManager.Current.IsChildWindowOpen = true; ConfigurationManager.OnDialogOpen(); - await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog); + + return (Application.Current.MainWindow as MainWindow).ShowChildWindowAsync(childWindow); } private void ConnectProfile() diff --git a/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs b/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs index b56f761f2c..686350506b 100644 --- a/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs @@ -527,7 +527,7 @@ private static void CloseItemAction(ItemActionCallbackArgs args) // Connect via Dialog private Task Connect(string host = null) { - var childWindow = new RemoteDesktopConnectChildWindow(Application.Current.MainWindow); + var childWindow = new RemoteDesktopConnectChildWindow(); var childWindowViewModel = new RemoteDesktopConnectViewModel(instance => { @@ -606,7 +606,7 @@ private Task ConnectProfileAs() var sessionInfo = RemoteDesktop.CreateSessionInfo(profileInfo); - var childWindow = new RemoteDesktopConnectChildWindow(Application.Current.MainWindow); + var childWindow = new RemoteDesktopConnectChildWindow(); var childWindowViewModel = new RemoteDesktopConnectViewModel(instance => { diff --git a/Source/NETworkManager/Views/PowerShellConnectDialog.xaml b/Source/NETworkManager/Views/PowerShellConnectChildWindow.xaml similarity index 62% rename from Source/NETworkManager/Views/PowerShellConnectDialog.xaml rename to Source/NETworkManager/Views/PowerShellConnectChildWindow.xaml index 06930b16a9..6534d96e85 100644 --- a/Source/NETworkManager/Views/PowerShellConnectDialog.xaml +++ b/Source/NETworkManager/Views/PowerShellConnectChildWindow.xaml @@ -1,20 +1,24 @@ - - + + - - + + @@ -42,7 +46,7 @@ + IsOn="{Binding EnableRemoteConsole}" /> diff --git a/Source/NETworkManager/ViewModels/PowerShellConnectViewModel.cs b/Source/NETworkManager/ViewModels/PowerShellConnectViewModel.cs index 2b2a066ac8..64e5ed9e55 100644 --- a/Source/NETworkManager/ViewModels/PowerShellConnectViewModel.cs +++ b/Source/NETworkManager/ViewModels/PowerShellConnectViewModel.cs @@ -18,7 +18,7 @@ public class PowerShellConnectViewModel : ViewModelBase private bool _enableRemoteConsole; - private List _executionPolicies = new(); + private List _executionPolicies = []; private ExecutionPolicy _executionPolicy; diff --git a/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs b/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs index 3223efcfc3..a8b63c3437 100644 --- a/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs @@ -1,6 +1,7 @@ using Dragablz; using log4net; using MahApps.Metro.Controls.Dialogs; +using MahApps.Metro.SimpleChildWindow; using NETworkManager.Controls; using NETworkManager.Localization.Resources; using NETworkManager.Models; @@ -239,7 +240,7 @@ public bool IsProfileFilterSet OnPropertyChanged(); } } - + private readonly GroupExpanderStateStore _groupExpanderStateStore = new(); public GroupExpanderStateStore GroupExpanderStateStore => _groupExpanderStateStore; @@ -504,7 +505,7 @@ public ICommand TextBoxSearchLostFocusCommand private void OpenProfileFilterAction() { ConfigurationManager.Current.IsProfileFilterPopupOpen = true; - + ProfileFilterIsOpen = true; } @@ -524,7 +525,7 @@ private void ClearProfileFilterAction() _searchDisabled = true; Search = string.Empty; _searchDisabled = false; - + foreach (var tag in ProfileFilterTags) tag.IsSelected = false; @@ -547,7 +548,7 @@ private void CollapseAllProfileGroupsAction() { SetIsExpandedForAllProfileGroups(false); } - + public ICommand OpenSettingsCommand => new RelayCommand(_ => OpenSettingsAction()); private static void OpenSettingsAction() @@ -588,16 +589,15 @@ private void TryFindExecutable() Log.Warn("Install PuTTY or configure the path in the settings."); } - private async Task Connect(string host = null) + private Task Connect(string host = null) { - var customDialog = new CustomDialog - { - Title = Strings.Connect - }; + var childWindow = new PuTTYConnectChildWindow(); - var connectViewModel = new PuTTYConnectViewModel(async instance => + var childWindowViewModel = new PuTTYConnectViewModel(instance => { - await _dialogCoordinator.HideMetroDialogAsync(this, customDialog); + childWindow.IsOpen = false; + ConfigurationManager.Current.IsChildWindowOpen = false; + ConfigurationManager.OnDialogClose(); // Create profile info @@ -630,19 +630,23 @@ private async Task Connect(string host = null) AddProfileToHistory(instance.Profile); Connect(sessionInfo); - }, async _ => - { - await _dialogCoordinator.HideMetroDialogAsync(this, customDialog); - ConfigurationManager.OnDialogClose(); - }, host); + }, _ => + { + childWindow.IsOpen = false; + ConfigurationManager.Current.IsChildWindowOpen = false; - customDialog.Content = new PuTTYConnectDialog - { - DataContext = connectViewModel - }; + ConfigurationManager.OnDialogClose(); + }, host); + + childWindow.Title = Strings.Connect; + + childWindow.DataContext = childWindowViewModel; + + ConfigurationManager.Current.IsChildWindowOpen = true; ConfigurationManager.OnDialogOpen(); - await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog); + + return (Application.Current.MainWindow as MainWindow).ShowChildWindowAsync(childWindow); } private void ConnectProfile() @@ -660,7 +664,7 @@ private void ConnectProfileExternal() ProcessStartInfo info = new() { FileName = SettingsManager.Current.PuTTY_ApplicationFilePath, - Arguments = Models.PuTTY.PuTTY.BuildCommandLine(sessionInfo) + Arguments = PuTTY.BuildCommandLine(sessionInfo) }; Process.Start(info); @@ -761,7 +765,7 @@ private void SetIsExpandedForAllProfileGroups(bool isExpanded) foreach (var group in Profiles.Groups.Cast()) GroupExpanderStateStore[group.Name.ToString()] = isExpanded; } - + private void ResizeProfile(bool dueToChangedSize) { _canProfileWidthChange = false; @@ -907,7 +911,7 @@ public void OnProfileFilterClosed() { ConfigurationManager.Current.IsProfileFilterPopupOpen = false; } - + public void OnProfileManagerDialogOpen() { ConfigurationManager.OnDialogOpen(); diff --git a/Source/NETworkManager/Views/PowerShellConnectChildWindow.xaml b/Source/NETworkManager/Views/PowerShellConnectChildWindow.xaml index 6534d96e85..40daf75d76 100644 --- a/Source/NETworkManager/Views/PowerShellConnectChildWindow.xaml +++ b/Source/NETworkManager/Views/PowerShellConnectChildWindow.xaml @@ -13,7 +13,7 @@ CloseButtonCommand="{Binding Path=CancelCommand}" Style="{StaticResource DefaultChildWindow}" Loaded="ChildWindow_OnLoaded" - mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:ProfileViewModel}"> + mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:PowerShellConnectViewModel}"> diff --git a/Source/NETworkManager/Views/PuTTYConnectDialog.xaml b/Source/NETworkManager/Views/PuTTYConnectChildWindow.xaml similarity index 75% rename from Source/NETworkManager/Views/PuTTYConnectDialog.xaml rename to Source/NETworkManager/Views/PuTTYConnectChildWindow.xaml index 1f8396e405..f0f89aee3b 100644 --- a/Source/NETworkManager/Views/PuTTYConnectDialog.xaml +++ b/Source/NETworkManager/Views/PuTTYConnectChildWindow.xaml @@ -1,20 +1,24 @@ - - + + - - + + @@ -72,9 +76,9 @@ + mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleHostnameOrIPAddress}" + Visibility="{Binding UseSerial, Converter={StaticResource BooleanReverseToVisibilityCollapsedConverter}}" + Style="{StaticResource EditableComboBox}"> @@ -85,10 +89,10 @@ + ItemsSource="{Binding SerialLineHistoryView}" + mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleSerialLine}" + Visibility="{Binding UseSerial, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}" + Style="{StaticResource EditableComboBox}"> @@ -111,9 +115,9 @@ + mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExamplePort22}" + Visibility="{Binding UseSerial, Converter={StaticResource BooleanReverseToVisibilityCollapsedConverter}}" + Style="{StaticResource EditableComboBox}"> @@ -124,9 +128,9 @@ + mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleBaud9600}" + Visibility="{Binding UseSerial, Converter={StaticResource BooleanToVisibilityCollapsedConverter}}" + Style="{StaticResource EditableComboBox}"> @@ -138,8 +142,8 @@ + ItemsSource="{Binding UsernameHistoryView}" + mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleUsername}">