diff --git a/Source/NETworkManager.Profiles/Application/AWSSessionManager.cs b/Source/NETworkManager.Profiles/Application/AWSSessionManager.cs index c51b21dfc0..b9d0f335b6 100644 --- a/Source/NETworkManager.Profiles/Application/AWSSessionManager.cs +++ b/Source/NETworkManager.Profiles/Application/AWSSessionManager.cs @@ -8,7 +8,7 @@ public class AWSSessionManager public static AWSSessionManagerSessionInfo CreateSessionInfo(ProfileInfo profile) { // Get group info - var group = ProfileManager.GetGroup(profile.Group); + var group = ProfileManager.GetGroupByName(profile.Group); return new AWSSessionManagerSessionInfo { diff --git a/Source/NETworkManager.Profiles/Application/PowerShell.cs b/Source/NETworkManager.Profiles/Application/PowerShell.cs index e67efea079..ad9235a1bc 100644 --- a/Source/NETworkManager.Profiles/Application/PowerShell.cs +++ b/Source/NETworkManager.Profiles/Application/PowerShell.cs @@ -8,7 +8,7 @@ public class PowerShell public static PowerShellSessionInfo CreateSessionInfo(ProfileInfo profile) { // Get group info - var group = ProfileManager.GetGroup(profile.Group); + var group = ProfileManager.GetGroupByName(profile.Group); return new PowerShellSessionInfo { diff --git a/Source/NETworkManager.Profiles/Application/PuTTY.cs b/Source/NETworkManager.Profiles/Application/PuTTY.cs index 58c6950203..454e701c8a 100644 --- a/Source/NETworkManager.Profiles/Application/PuTTY.cs +++ b/Source/NETworkManager.Profiles/Application/PuTTY.cs @@ -8,7 +8,7 @@ public static class PuTTY public static PuTTYSessionInfo CreateSessionInfo(ProfileInfo profile) { // Get group info - var group = ProfileManager.GetGroup(profile.Group); + var group = ProfileManager.GetGroupByName(profile.Group); return new PuTTYSessionInfo { diff --git a/Source/NETworkManager.Profiles/Application/RemoteDesktop.cs b/Source/NETworkManager.Profiles/Application/RemoteDesktop.cs index db32006b54..c8240d2a3f 100644 --- a/Source/NETworkManager.Profiles/Application/RemoteDesktop.cs +++ b/Source/NETworkManager.Profiles/Application/RemoteDesktop.cs @@ -73,7 +73,7 @@ public static RemoteDesktopSessionInfo CreateSessionInfo(ProfileInfo profile) var info = CreateSessionInfo(); // Get group info - var group = ProfileManager.GetGroup(profile.Group); + var group = ProfileManager.GetGroupByName(profile.Group); // Override hostname info.Hostname = profile.RemoteDesktop_Host; diff --git a/Source/NETworkManager.Profiles/Application/SNMP.cs b/Source/NETworkManager.Profiles/Application/SNMP.cs index 9fc8582643..7153580901 100644 --- a/Source/NETworkManager.Profiles/Application/SNMP.cs +++ b/Source/NETworkManager.Profiles/Application/SNMP.cs @@ -23,7 +23,7 @@ public static SNMPSessionInfo CreateSessionInfo(ProfileInfo profile) SNMPSessionInfo info = new(); // Get group info - var group = ProfileManager.GetGroup(profile.Group); + var group = ProfileManager.GetGroupByName(profile.Group); info.Host = profile.SNMP_Host; diff --git a/Source/NETworkManager.Profiles/Application/TigerVNC.cs b/Source/NETworkManager.Profiles/Application/TigerVNC.cs index 9e84a72eb9..7faa4f19b7 100644 --- a/Source/NETworkManager.Profiles/Application/TigerVNC.cs +++ b/Source/NETworkManager.Profiles/Application/TigerVNC.cs @@ -8,7 +8,7 @@ public static class TigerVNC public static TigerVNCSessionInfo CreateSessionInfo(ProfileInfo profile) { // Get group info - var group = ProfileManager.GetGroup(profile.Group); + var group = ProfileManager.GetGroupByName(profile.Group); return new TigerVNCSessionInfo { diff --git a/Source/NETworkManager.Profiles/ProfileManager.cs b/Source/NETworkManager.Profiles/ProfileManager.cs index 7288b487c2..0cb792fd01 100644 --- a/Source/NETworkManager.Profiles/ProfileManager.cs +++ b/Source/NETworkManager.Profiles/ProfileManager.cs @@ -1,4 +1,6 @@ -using System; +using NETworkManager.Settings; +using NETworkManager.Utilities; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; @@ -6,8 +8,6 @@ using System.Security; using System.Text; using System.Xml.Serialization; -using NETworkManager.Settings; -using NETworkManager.Utilities; namespace NETworkManager.Profiles; @@ -482,7 +482,7 @@ public static void Save() // Only if the password provided earlier was valid... if (LoadedProfileFile.IsPasswordValid) { - var decryptedBytes = SerializeToByteArray([..Groups]); + var decryptedBytes = SerializeToByteArray([.. Groups]); var encryptedBytes = CryptoHelper.Encrypt(decryptedBytes, SecureStringHelper.ConvertToString(LoadedProfileFile.Password), GlobalStaticConfiguration.Profile_EncryptionKeySize, @@ -493,7 +493,7 @@ public static void Save() } else { - SerializeToFile(LoadedProfileFile.Path, [..Groups]); + SerializeToFile(LoadedProfileFile.Path, [.. Groups]); } ProfilesChanged = false; @@ -579,25 +579,25 @@ private static List SerializeGroup(List groups continue; var profilesSerializable = (from profile in @group.Profiles - where !profile.IsDynamic - select new ProfileInfoSerializable(profile) - { - RemoteDesktop_Password = profile.RemoteDesktop_Password != null - ? SecureStringHelper.ConvertToString(profile.RemoteDesktop_Password) - : string.Empty, - RemoteDesktop_GatewayServerPassword = profile.RemoteDesktop_GatewayServerPassword != null - ? SecureStringHelper.ConvertToString(profile.RemoteDesktop_GatewayServerPassword) - : string.Empty, - SNMP_Community = profile.SNMP_Community != null - ? SecureStringHelper.ConvertToString(profile.SNMP_Community) - : string.Empty, - SNMP_Auth = profile.SNMP_Auth != null - ? SecureStringHelper.ConvertToString(profile.SNMP_Auth) - : string.Empty, - SNMP_Priv = profile.SNMP_Priv != null - ? SecureStringHelper.ConvertToString(profile.SNMP_Priv) - : string.Empty - }).ToList(); + where !profile.IsDynamic + select new ProfileInfoSerializable(profile) + { + RemoteDesktop_Password = profile.RemoteDesktop_Password != null + ? SecureStringHelper.ConvertToString(profile.RemoteDesktop_Password) + : string.Empty, + RemoteDesktop_GatewayServerPassword = profile.RemoteDesktop_GatewayServerPassword != null + ? SecureStringHelper.ConvertToString(profile.RemoteDesktop_GatewayServerPassword) + : string.Empty, + SNMP_Community = profile.SNMP_Community != null + ? SecureStringHelper.ConvertToString(profile.SNMP_Community) + : string.Empty, + SNMP_Auth = profile.SNMP_Auth != null + ? SecureStringHelper.ConvertToString(profile.SNMP_Auth) + : string.Empty, + SNMP_Priv = profile.SNMP_Priv != null + ? SecureStringHelper.ConvertToString(profile.SNMP_Priv) + : string.Empty + }).ToList(); groupsSerializable.Add(new GroupInfoSerializable(group) { @@ -655,58 +655,58 @@ private static List DeserializeGroup(Stream stream) XmlSerializer xmlSerializer = new(typeof(List)); return (from groupSerializable in ((List)xmlSerializer.Deserialize(stream))! - let profiles = groupSerializable.Profiles.Select(profileSerializable => new ProfileInfo(profileSerializable) + let profiles = groupSerializable.Profiles.Select(profileSerializable => new ProfileInfo(profileSerializable) { // Migrate old data NetworkInterface_Subnetmask = - string.IsNullOrEmpty(profileSerializable.NetworkInterface_Subnetmask) && - !string.IsNullOrEmpty(profileSerializable.NetworkInterface_SubnetmaskOrCidr) - ? profileSerializable.NetworkInterface_SubnetmaskOrCidr - : profileSerializable.NetworkInterface_Subnetmask, + string.IsNullOrEmpty(profileSerializable.NetworkInterface_Subnetmask) && + !string.IsNullOrEmpty(profileSerializable.NetworkInterface_SubnetmaskOrCidr) + ? profileSerializable.NetworkInterface_SubnetmaskOrCidr + : profileSerializable.NetworkInterface_Subnetmask, // Convert passwords to secure strings RemoteDesktop_Password = !string.IsNullOrEmpty(profileSerializable.RemoteDesktop_Password) - ? SecureStringHelper.ConvertToSecureString(profileSerializable.RemoteDesktop_Password) - : null, - RemoteDesktop_GatewayServerPassword = - !string.IsNullOrEmpty(profileSerializable.RemoteDesktop_GatewayServerPassword) - ? SecureStringHelper.ConvertToSecureString(profileSerializable - .RemoteDesktop_GatewayServerPassword) + ? SecureStringHelper.ConvertToSecureString(profileSerializable.RemoteDesktop_Password) : null, + RemoteDesktop_GatewayServerPassword = + !string.IsNullOrEmpty(profileSerializable.RemoteDesktop_GatewayServerPassword) + ? SecureStringHelper.ConvertToSecureString(profileSerializable + .RemoteDesktop_GatewayServerPassword) + : null, SNMP_Community = !string.IsNullOrEmpty(profileSerializable.SNMP_Community) - ? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Community) - : null, + ? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Community) + : null, SNMP_Auth = !string.IsNullOrEmpty(profileSerializable.SNMP_Auth) - ? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Auth) - : null, + ? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Auth) + : null, SNMP_Priv = !string.IsNullOrEmpty(profileSerializable.SNMP_Priv) - ? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Priv) - : null + ? SecureStringHelper.ConvertToSecureString(profileSerializable.SNMP_Priv) + : null }) - .ToList() - select new GroupInfo(groupSerializable) - { - Profiles = profiles, - - // Convert passwords to secure strings - RemoteDesktop_Password = !string.IsNullOrEmpty(groupSerializable.RemoteDesktop_Password) - ? SecureStringHelper.ConvertToSecureString(groupSerializable.RemoteDesktop_Password) - : null, - RemoteDesktop_GatewayServerPassword = - !string.IsNullOrEmpty(groupSerializable.RemoteDesktop_GatewayServerPassword) - ? SecureStringHelper.ConvertToSecureString( - groupSerializable.RemoteDesktop_GatewayServerPassword) + .ToList() + select new GroupInfo(groupSerializable) + { + Profiles = profiles, + + // Convert passwords to secure strings + RemoteDesktop_Password = !string.IsNullOrEmpty(groupSerializable.RemoteDesktop_Password) + ? SecureStringHelper.ConvertToSecureString(groupSerializable.RemoteDesktop_Password) : null, - SNMP_Community = !string.IsNullOrEmpty(groupSerializable.SNMP_Community) - ? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Community) - : null, - SNMP_Auth = !string.IsNullOrEmpty(groupSerializable.SNMP_Auth) - ? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Auth) - : null, - SNMP_Priv = !string.IsNullOrEmpty(groupSerializable.SNMP_Priv) - ? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Priv) - : null - }).ToList(); + RemoteDesktop_GatewayServerPassword = + !string.IsNullOrEmpty(groupSerializable.RemoteDesktop_GatewayServerPassword) + ? SecureStringHelper.ConvertToSecureString( + groupSerializable.RemoteDesktop_GatewayServerPassword) + : null, + SNMP_Community = !string.IsNullOrEmpty(groupSerializable.SNMP_Community) + ? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Community) + : null, + SNMP_Auth = !string.IsNullOrEmpty(groupSerializable.SNMP_Auth) + ? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Auth) + : null, + SNMP_Priv = !string.IsNullOrEmpty(groupSerializable.SNMP_Priv) + ? SecureStringHelper.ConvertToSecureString(groupSerializable.SNMP_Priv) + : null + }).ToList(); } #endregion @@ -741,7 +741,7 @@ public static void AddGroup(GroupInfo group) /// /// Name of the group. /// Group as . - public static GroupInfo GetGroup(string name) + public static GroupInfo GetGroupByName(string name) { return Groups.First(x => x.Name.Equals(name)); } diff --git a/Source/NETworkManager/ProfileDialogManager.cs b/Source/NETworkManager/ProfileDialogManager.cs index 94cae98c51..d91c0c0e05 100644 --- a/Source/NETworkManager/ProfileDialogManager.cs +++ b/Source/NETworkManager/ProfileDialogManager.cs @@ -485,8 +485,6 @@ public static Task ShowAddProfileDialog(Window parentWindow, IProfileManagerMini ProfileManager.AddProfile(ParseProfileInfo(instance)); }, _ => { - Debug.WriteLine("Profile dialog closed without saving"); - childWindow.IsOpen = false; Settings.ConfigurationManager.Current.IsChildWindowOpen = false; @@ -607,65 +605,67 @@ public static Task ShowDeleteProfileDialog(Window parentWindow, IProfileManagerM #region Dialog to add, edit and delete group - public static Task ShowAddGroupDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator) + public static Task ShowAddGroupDialog(Window parentWindow, IProfileManagerMinimal viewModel) { - CustomDialog customDialog = new() - { - Title = Strings.AddGroup, - Style = (Style)Application.Current.FindResource(DialogResourceKey) - }; - - GroupViewModel groupViewModel = new(async instance => + var childWindow = new GroupChildWindow(parentWindow); + + GroupViewModel childWindowViewModel = new(instance => { - await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog); + childWindow.IsOpen = false; + Settings.ConfigurationManager.Current.IsChildWindowOpen = false; + viewModel.OnProfileManagerDialogClose(); - + ProfileManager.AddGroup(ParseGroupInfo(instance)); - }, async _ => + }, _ => { - await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog); + childWindow.IsOpen = false; + Settings.ConfigurationManager.Current.IsChildWindowOpen = false; + viewModel.OnProfileManagerDialogClose(); }, ProfileManager.GetGroupNames()); - - customDialog.Content = new GroupDialog - { - DataContext = groupViewModel - }; - + + childWindow.Title = Strings.AddGroup; + + childWindow.DataContext = childWindowViewModel; + viewModel.OnProfileManagerDialogOpen(); - - return dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog); + + Settings.ConfigurationManager.Current.IsChildWindowOpen = true; + + return parentWindow.ShowChildWindowAsync(childWindow); } - public static Task ShowEditGroupDialog(IProfileManagerMinimal viewModel, IDialogCoordinator dialogCoordinator, + public static Task ShowEditGroupDialog(Window parentWindow, IProfileManagerMinimal viewModel, GroupInfo group) { - CustomDialog customDialog = new() - { - Title = Strings.EditGroup, - Style = (Style)Application.Current.FindResource(DialogResourceKey) - }; - - GroupViewModel groupViewModel = new(async instance => + var childWindow = new GroupChildWindow(parentWindow); + + GroupViewModel childWindowViewModel = new(instance => { - await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog); + childWindow.IsOpen = false; + Settings.ConfigurationManager.Current.IsChildWindowOpen = false; + viewModel.OnProfileManagerDialogClose(); - - ProfileManager.ReplaceGroup(instance.Group, ParseGroupInfo(instance)); - }, async _ => + + ProfileManager.ReplaceGroup(group, ParseGroupInfo(instance)); + }, _ => { - await dialogCoordinator.HideMetroDialogAsync(viewModel, customDialog); + childWindow.IsOpen = false; + Settings.ConfigurationManager.Current.IsChildWindowOpen = false; + viewModel.OnProfileManagerDialogClose(); }, ProfileManager.GetGroupNames(), GroupEditMode.Edit, group); - - customDialog.Content = new GroupDialog - { - DataContext = groupViewModel - }; - + + childWindow.Title = Strings.EditGroup; + + childWindow.DataContext = childWindowViewModel; + viewModel.OnProfileManagerDialogOpen(); - - return dialogCoordinator.ShowMetroDialogAsync(viewModel, customDialog); + + Settings.ConfigurationManager.Current.IsChildWindowOpen = true; + + return parentWindow.ShowChildWindowAsync(childWindow); } public static Task ShowDeleteGroupDialog(Window parentWindow, IProfileManagerMinimal viewModel, @@ -688,13 +688,13 @@ public static Task ShowDeleteGroupDialog(Window parentWindow, IProfileManagerMin viewModel.OnProfileManagerDialogClose(); }, Strings.DeleteGroupMessage); - + childWindow.Title = Strings.DeleteGroup; childWindow.DataContext = childWindowViewModel; - + viewModel.OnProfileManagerDialogOpen(); - + Settings.ConfigurationManager.Current.IsChildWindowOpen = true; return parentWindow.ShowChildWindowAsync(childWindow); diff --git a/Source/NETworkManager/ViewModels/AWSSessionManagerHostViewModel.cs b/Source/NETworkManager/ViewModels/AWSSessionManagerHostViewModel.cs index f1ce710231..0a6188375a 100644 --- a/Source/NETworkManager/ViewModels/AWSSessionManagerHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/AWSSessionManagerHostViewModel.cs @@ -463,7 +463,7 @@ private void EditProfileAction() private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -479,7 +479,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -759,14 +759,14 @@ private async Task SyncInstanceIDsFromAWS(string profile, string region) if (groupInfo.Profiles.Count == 0) { if (ProfileManager.GroupExists(groupName)) - ProfileManager.RemoveGroup(ProfileManager.GetGroup(groupName)); + ProfileManager.RemoveGroup(ProfileManager.GetGroupByName(groupName)); Log.Info("No EC2 Instance(s) found!"); } else { if (ProfileManager.GroupExists(groupName)) - ProfileManager.ReplaceGroup(ProfileManager.GetGroup(groupName), groupInfo); + ProfileManager.ReplaceGroup(ProfileManager.GetGroupByName(groupName), groupInfo); else ProfileManager.AddGroup(groupInfo); @@ -795,7 +795,7 @@ private void RemoveDynamicGroup(string profile, string region) ProfileManager.ProfilesChanged = false; if (ProfileManager.GroupExists(groupName)) - ProfileManager.RemoveGroup(ProfileManager.GetGroup(groupName)); + ProfileManager.RemoveGroup(ProfileManager.GetGroupByName(groupName)); ProfileManager.ProfilesChanged = profilesChangedCurrentState; } diff --git a/Source/NETworkManager/ViewModels/DNSLookupHostViewModel.cs b/Source/NETworkManager/ViewModels/DNSLookupHostViewModel.cs index fe3106065c..ba6112e631 100644 --- a/Source/NETworkManager/ViewModels/DNSLookupHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/DNSLookupHostViewModel.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using System.Windows; -using System.Windows.Data; -using System.Windows.Input; -using System.Windows.Threading; -using Dragablz; +using Dragablz; using MahApps.Metro.Controls.Dialogs; using NETworkManager.Controls; using NETworkManager.Localization.Resources; @@ -16,6 +7,15 @@ using NETworkManager.Settings; using NETworkManager.Utilities; using NETworkManager.Views; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Windows; +using System.Windows.Data; +using System.Windows.Input; +using System.Windows.Threading; namespace NETworkManager.ViewModels; @@ -271,7 +271,7 @@ private void EditProfileAction() private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -287,7 +287,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -373,12 +373,12 @@ private void SetProfilesView(ProfileInfo profile = null) Profiles.Filter = o => { if (string.IsNullOrEmpty(Search)) - return true; - + return true; + if (o is not ProfileInfo info) return false; - + var search = Search.Trim(); diff --git a/Source/NETworkManager/ViewModels/IPGeolocationHostViewModel.cs b/Source/NETworkManager/ViewModels/IPGeolocationHostViewModel.cs index 3cc8ded9ec..3e06b2aebb 100644 --- a/Source/NETworkManager/ViewModels/IPGeolocationHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/IPGeolocationHostViewModel.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using System.Windows; -using System.Windows.Data; -using System.Windows.Input; -using System.Windows.Threading; -using Dragablz; +using Dragablz; using MahApps.Metro.Controls.Dialogs; using NETworkManager.Controls; using NETworkManager.Localization.Resources; @@ -16,6 +7,15 @@ using NETworkManager.Settings; using NETworkManager.Utilities; using NETworkManager.Views; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Windows; +using System.Windows.Data; +using System.Windows.Input; +using System.Windows.Threading; namespace NETworkManager.ViewModels; @@ -272,7 +272,7 @@ private void EditProfileAction() private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -288,7 +288,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -374,10 +374,10 @@ private void SetProfilesView(ProfileInfo profile = null) Profiles.Filter = o => { if (string.IsNullOrEmpty(Search)) - return true; - + return true; + if (o is not ProfileInfo info) - return false; + return false; var search = Search.Trim(); diff --git a/Source/NETworkManager/ViewModels/IPScannerHostViewModel.cs b/Source/NETworkManager/ViewModels/IPScannerHostViewModel.cs index 4eacaee941..21ab8ac6f8 100644 --- a/Source/NETworkManager/ViewModels/IPScannerHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/IPScannerHostViewModel.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using System.Windows; -using System.Windows.Data; -using System.Windows.Input; -using System.Windows.Threading; -using Dragablz; +using Dragablz; using MahApps.Metro.Controls.Dialogs; using NETworkManager.Controls; using NETworkManager.Localization.Resources; @@ -16,6 +7,15 @@ using NETworkManager.Settings; using NETworkManager.Utilities; using NETworkManager.Views; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Windows; +using System.Windows.Data; +using System.Windows.Input; +using System.Windows.Threading; namespace NETworkManager.ViewModels; @@ -271,7 +271,7 @@ private void EditProfileAction() private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -287,7 +287,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -378,8 +378,8 @@ private void SetProfilesView(ProfileInfo profile = null) Profiles.Filter = o => { if (string.IsNullOrEmpty(Search)) - return true; - + return true; + if (o is not ProfileInfo info) return false; diff --git a/Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs b/Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs index 8722bc23e9..7ae0e31d7b 100644 --- a/Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs +++ b/Source/NETworkManager/ViewModels/NetworkInterfaceViewModel.cs @@ -1,17 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Diagnostics; -using System.Linq; -using System.Net.NetworkInformation; -using System.Net.Sockets; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Data; -using System.Windows.Input; -using System.Windows.Threading; -using LiveCharts; +using LiveCharts; using LiveCharts.Configurations; using LiveCharts.Wpf; using log4net; @@ -26,6 +13,19 @@ using NETworkManager.Settings; using NETworkManager.Utilities; using NETworkManager.Views; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Net.NetworkInformation; +using System.Net.Sockets; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; +using System.Windows.Input; +using System.Windows.Threading; using NetworkInterface = NETworkManager.Models.Network.NetworkInterface; namespace NETworkManager.ViewModels; @@ -730,7 +730,7 @@ await _dialogCoordinator.ShowMessageAsync(this, Strings.Error, private bool ApplyConfiguration_CanExecute(object parameter) { return Application.Current.MainWindow != null && - !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen && + !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen && !ConfigurationManager.Current.IsChildWindowOpen; } @@ -771,7 +771,7 @@ private void EditProfileAction() private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -787,7 +787,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -939,9 +939,9 @@ private async Task RemoveIPv4AddressAction() private async void ReloadNetworkInterfaces() { // Avoid multiple reloads - if(IsNetworkInterfaceLoading) + if (IsNetworkInterfaceLoading) return; - + IsNetworkInterfaceLoading = true; // Make the user happy, let him see a reload animation (and he cannot spam the reload command) @@ -949,7 +949,7 @@ private async void ReloadNetworkInterfaces() // Store the last selected id var id = SelectedNetworkInterface?.Id ?? string.Empty; - + // Get all network interfaces... var networkInterfaces = await NetworkInterface.GetNetworkInterfacesAsync(); @@ -958,7 +958,7 @@ private async void ReloadNetworkInterfaces() { // Clear the list NetworkInterfaces.Clear(); - + // Add all network interfaces to the list networkInterfaces.ForEach(NetworkInterfaces.Add); }); @@ -967,7 +967,7 @@ private async void ReloadNetworkInterfaces() SelectedNetworkInterface = string.IsNullOrEmpty(id) ? NetworkInterfaces.FirstOrDefault() : NetworkInterfaces.FirstOrDefault(x => x.Id == id); - + IsNetworkInterfaceLoading = false; } @@ -1336,11 +1336,11 @@ private void SetProfilesView(ProfileInfo profile = null) Profiles.Filter = o => { if (string.IsNullOrEmpty(Search)) - return true; + return true; if (o is not ProfileInfo info) return false; - + var search = Search.Trim(); // Search by: Tag=xxx (exact match, ignore case) diff --git a/Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs b/Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs index db7dad3d4a..d058345722 100644 --- a/Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/PingMonitorHostViewModel.cs @@ -1,4 +1,13 @@ -using System; +using MahApps.Metro.Controls; +using MahApps.Metro.Controls.Dialogs; +using NETworkManager.Localization.Resources; +using NETworkManager.Models; +using NETworkManager.Models.Network; +using NETworkManager.Profiles; +using NETworkManager.Settings; +using NETworkManager.Utilities; +using NETworkManager.Views; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; @@ -10,15 +19,6 @@ using System.Windows.Data; using System.Windows.Input; using System.Windows.Threading; -using MahApps.Metro.Controls; -using MahApps.Metro.Controls.Dialogs; -using NETworkManager.Localization.Resources; -using NETworkManager.Models; -using NETworkManager.Models.Network; -using NETworkManager.Profiles; -using NETworkManager.Settings; -using NETworkManager.Utilities; -using NETworkManager.Views; namespace NETworkManager.ViewModels; @@ -312,8 +312,8 @@ private void LoadSettings() private bool Ping_CanExecute(object parameter) { - return Application.Current.MainWindow != null && - !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen && + return Application.Current.MainWindow != null && + !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen && !ConfigurationManager.Current.IsChildWindowOpen; } @@ -377,7 +377,7 @@ private void EditProfileAction() private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -393,7 +393,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -596,7 +596,7 @@ private void SetProfilesView(ProfileInfo profile = null) { if (string.IsNullOrEmpty(Search)) return true; - + if (o is not ProfileInfo info) return false; diff --git a/Source/NETworkManager/ViewModels/PortScannerHostViewModel.cs b/Source/NETworkManager/ViewModels/PortScannerHostViewModel.cs index 2fe8789688..74e750ebda 100644 --- a/Source/NETworkManager/ViewModels/PortScannerHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/PortScannerHostViewModel.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using System.Windows; -using System.Windows.Data; -using System.Windows.Input; -using System.Windows.Threading; -using Dragablz; +using Dragablz; using MahApps.Metro.Controls.Dialogs; using NETworkManager.Controls; using NETworkManager.Localization.Resources; @@ -16,6 +7,15 @@ using NETworkManager.Settings; using NETworkManager.Utilities; using NETworkManager.Views; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Windows; +using System.Windows.Data; +using System.Windows.Input; +using System.Windows.Threading; namespace NETworkManager.ViewModels; @@ -272,7 +272,7 @@ private void EditProfileAction() private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -288,7 +288,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -379,8 +379,8 @@ private void SetProfilesView(ProfileInfo profile = null) Profiles.Filter = o => { if (string.IsNullOrEmpty(Search)) - return true; - + return true; + if (o is not ProfileInfo info) return false; diff --git a/Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs b/Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs index 458f9384f0..9dac3563bb 100644 --- a/Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/PowerShellHostViewModel.cs @@ -1,16 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Data; -using System.Windows.Input; -using System.Windows.Threading; -using Dragablz; +using Dragablz; using log4net; using MahApps.Metro.Controls.Dialogs; using NETworkManager.Controls; @@ -22,6 +10,18 @@ using NETworkManager.Settings; using NETworkManager.Utilities; using NETworkManager.Views; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; +using System.Windows.Input; +using System.Windows.Threading; using PowerShellProfile = NETworkManager.Profiles.Application.PowerShell; namespace NETworkManager.ViewModels; @@ -30,7 +30,7 @@ public class PowerShellHostViewModel : ViewModelBase, IProfileManager { #region Variables private static readonly ILog Log = LogManager.GetLogger(typeof(PowerShellHostViewModel)); - + private readonly IDialogCoordinator _dialogCoordinator; private readonly DispatcherTimer _searchDispatcherTimer = new(); @@ -249,7 +249,7 @@ public PowerShellHostViewModel(IDialogCoordinator instance) CheckExecutable(); // Try to find PowerShell executable - if(!IsExecutableConfigured) + if (!IsExecutableConfigured) TryFindExecutable(); WriteDefaultProfileToRegistry(); @@ -379,7 +379,7 @@ private void EditProfileAction() private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -395,7 +395,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -434,13 +434,13 @@ private void CheckExecutable() { IsExecutableConfigured = !string.IsNullOrEmpty(SettingsManager.Current.PowerShell_ApplicationFilePath) && File.Exists(SettingsManager.Current.PowerShell_ApplicationFilePath); - - if(IsExecutableConfigured) + + if (IsExecutableConfigured) Log.Info($"PowerShell executable found: \"{SettingsManager.Current.PowerShell_ApplicationFilePath}\""); else Log.Warn("PowerShell executable not found!"); } - + /// /// Try to find executable. /// @@ -448,16 +448,16 @@ private void TryFindExecutable() { Log.Info("Try to find PowerShell executable..."); - var applicationFilePath = ApplicationHelper.Find(PowerShell.PwshFileName); - - if(string.IsNullOrEmpty(applicationFilePath)) + var applicationFilePath = ApplicationHelper.Find(PowerShell.PwshFileName); + + if (string.IsNullOrEmpty(applicationFilePath)) applicationFilePath = ApplicationHelper.Find(PowerShell.WindowsPowerShellFileName); - + SettingsManager.Current.PowerShell_ApplicationFilePath = applicationFilePath; - + CheckExecutable(); - - if(!IsExecutableConfigured) + + if (!IsExecutableConfigured) Log.Warn("Install PowerShell or configure the path in the settings."); } @@ -606,7 +606,7 @@ public void FocusEmbeddedWindow() // Focus embedded window in the selected tab (((DragablzTabItem)tabablzControl.SelectedItem)?.View as IEmbeddedWindow)?.FocusEmbeddedWindow(); - + break; } } @@ -639,7 +639,7 @@ private void SetProfilesView(ProfileInfo profile = null) { if (string.IsNullOrEmpty(Search)) return true; - + if (o is not ProfileInfo info) return false; @@ -683,15 +683,15 @@ public void OnProfileManagerDialogClose() { ConfigurationManager.OnDialogClose(); } - + private void WriteDefaultProfileToRegistry() { if (!SettingsManager.Current.Appearance_PowerShellModifyGlobalProfile) return; - - if(!IsExecutableConfigured) + + if (!IsExecutableConfigured) return; - + Log.Info("Write PowerShell profile to registry..."); PowerShell.WriteDefaultProfileToRegistry( diff --git a/Source/NETworkManager/ViewModels/ProfilesViewModel.cs b/Source/NETworkManager/ViewModels/ProfilesViewModel.cs index efb5deb5ba..952890754e 100644 --- a/Source/NETworkManager/ViewModels/ProfilesViewModel.cs +++ b/Source/NETworkManager/ViewModels/ProfilesViewModel.cs @@ -1,4 +1,8 @@ -using System; +using MahApps.Metro.Controls.Dialogs; +using NETworkManager.Profiles; +using NETworkManager.Settings; +using NETworkManager.Utilities; +using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; @@ -7,10 +11,6 @@ using System.Windows.Data; using System.Windows.Input; using System.Windows.Threading; -using MahApps.Metro.Controls.Dialogs; -using NETworkManager.Profiles; -using NETworkManager.Settings; -using NETworkManager.Utilities; namespace NETworkManager.ViewModels; @@ -191,7 +191,7 @@ private bool ModifyProfile_CanExecute(object obj) private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -207,14 +207,14 @@ private void DeleteProfileAction() private void AddGroupAction() { - ProfileDialogManager.ShowAddGroupDialog(this, _dialogCoordinator).ConfigureAwait(false); + ProfileDialogManager.ShowAddGroupDialog(Application.Current.MainWindow, this).ConfigureAwait(false); } public ICommand EditGroupCommand => new RelayCommand(_ => EditGroupAction()); private void EditGroupAction() { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, SelectedGroup).ConfigureAwait(false); + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, SelectedGroup).ConfigureAwait(false); } public ICommand DeleteGroupCommand => new RelayCommand(_ => DeleteGroupAction()); @@ -243,7 +243,7 @@ public void OnViewHide() private void SetGroupsView(GroupInfo group = null) { Groups = new CollectionViewSource - { Source = ProfileManager.Groups.Where(x => !x.IsDynamic).OrderBy(x => x.Name) }.View; + { Source = ProfileManager.Groups.Where(x => !x.IsDynamic).OrderBy(x => x.Name) }.View; // Set specific group or first if null SelectedGroup = null; @@ -267,7 +267,7 @@ private void SetProfilesView(GroupInfo group, ProfileInfo profile = null) { if (string.IsNullOrEmpty(Search)) return true; - + if (o is not ProfileInfo info) return false; diff --git a/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs b/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs index 948c06443c..1429f10918 100644 --- a/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/PuTTYHostViewModel.cs @@ -386,7 +386,7 @@ private void EditProfileAction() private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -402,7 +402,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -716,7 +716,7 @@ private void SetProfilesView(ProfileInfo profile = null) { if (string.IsNullOrEmpty(Search)) return true; - + if (o is not ProfileInfo info) return false; diff --git a/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs b/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs index 0235f55729..eb4faf0584 100644 --- a/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/RemoteDesktopHostViewModel.cs @@ -350,14 +350,14 @@ private bool ModifyProfile_CanExecute(object obj) private void EditProfileAction() { - ProfileDialogManager.ShowEditProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowEditProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand CopyAsProfileCommand => new RelayCommand(_ => CopyAsProfileAction(), ModifyProfile_CanExecute); private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -373,7 +373,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -588,7 +588,7 @@ private void SetProfilesView(ProfileInfo profile = null) { if (string.IsNullOrEmpty(Search)) return true; - + if (o is not ProfileInfo info) return false; diff --git a/Source/NETworkManager/ViewModels/SNMPHostViewModel.cs b/Source/NETworkManager/ViewModels/SNMPHostViewModel.cs index 6c6ae13d3a..9533dfba00 100644 --- a/Source/NETworkManager/ViewModels/SNMPHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/SNMPHostViewModel.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using System.Windows; -using System.Windows.Data; -using System.Windows.Input; -using System.Windows.Threading; -using Dragablz; +using Dragablz; using MahApps.Metro.Controls.Dialogs; using NETworkManager.Controls; using NETworkManager.Localization.Resources; @@ -18,6 +9,15 @@ using NETworkManager.Settings; using NETworkManager.Utilities; using NETworkManager.Views; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Windows; +using System.Windows.Data; +using System.Windows.Input; +using System.Windows.Threading; namespace NETworkManager.ViewModels; @@ -269,7 +269,7 @@ private void EditProfileAction() private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -285,7 +285,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -395,7 +395,7 @@ private void SetProfilesView(ProfileInfo profile = null) { if (string.IsNullOrEmpty(Search)) return true; - + if (o is not ProfileInfo info) return false; diff --git a/Source/NETworkManager/ViewModels/TigerVNCHostViewModel.cs b/Source/NETworkManager/ViewModels/TigerVNCHostViewModel.cs index 9d060acc3d..2af4aee5aa 100644 --- a/Source/NETworkManager/ViewModels/TigerVNCHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/TigerVNCHostViewModel.cs @@ -1,4 +1,15 @@ -using System; +using Dragablz; +using MahApps.Metro.Controls.Dialogs; +using NETworkManager.Controls; +using NETworkManager.Localization.Resources; +using NETworkManager.Models; +using NETworkManager.Models.EventSystem; +using NETworkManager.Models.TigerVNC; +using NETworkManager.Profiles; +using NETworkManager.Settings; +using NETworkManager.Utilities; +using NETworkManager.Views; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; @@ -10,17 +21,6 @@ using System.Windows.Data; using System.Windows.Input; using System.Windows.Threading; -using Dragablz; -using MahApps.Metro.Controls.Dialogs; -using NETworkManager.Controls; -using NETworkManager.Localization.Resources; -using NETworkManager.Models; -using NETworkManager.Models.EventSystem; -using NETworkManager.Models.TigerVNC; -using NETworkManager.Profiles; -using NETworkManager.Settings; -using NETworkManager.Utilities; -using NETworkManager.Views; using TigerVNC = NETworkManager.Profiles.Application.TigerVNC; namespace NETworkManager.ViewModels; @@ -321,7 +321,7 @@ private void EditProfileAction() private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -337,7 +337,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -512,9 +512,10 @@ private void SetProfilesView(ProfileInfo profile = null) Profiles.GroupDescriptions.Add(new PropertyGroupDescription(nameof(ProfileInfo.Group))); Profiles.Filter = o => - {if (string.IsNullOrEmpty(Search)) - return true; - + { + if (string.IsNullOrEmpty(Search)) + return true; + if (o is not ProfileInfo info) return false; diff --git a/Source/NETworkManager/ViewModels/TracerouteHostViewModel.cs b/Source/NETworkManager/ViewModels/TracerouteHostViewModel.cs index 7861a5985f..7ea450d9dc 100644 --- a/Source/NETworkManager/ViewModels/TracerouteHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/TracerouteHostViewModel.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using System.Windows; -using System.Windows.Data; -using System.Windows.Input; -using System.Windows.Threading; -using Dragablz; +using Dragablz; using MahApps.Metro.Controls.Dialogs; using NETworkManager.Controls; using NETworkManager.Localization.Resources; @@ -16,6 +7,15 @@ using NETworkManager.Settings; using NETworkManager.Utilities; using NETworkManager.Views; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Windows; +using System.Windows.Data; +using System.Windows.Input; +using System.Windows.Threading; namespace NETworkManager.ViewModels; @@ -272,7 +272,7 @@ private void EditProfileAction() private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -288,7 +288,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -380,7 +380,7 @@ private void SetProfilesView(ProfileInfo profile = null) { if (string.IsNullOrEmpty(Search)) return true; - + if (o is not ProfileInfo info) return false; diff --git a/Source/NETworkManager/ViewModels/WakeOnLANViewModel.cs b/Source/NETworkManager/ViewModels/WakeOnLANViewModel.cs index 0e5a53a375..283ff5dbfc 100644 --- a/Source/NETworkManager/ViewModels/WakeOnLANViewModel.cs +++ b/Source/NETworkManager/ViewModels/WakeOnLANViewModel.cs @@ -1,4 +1,12 @@ -using System; +using MahApps.Metro.Controls; +using MahApps.Metro.Controls.Dialogs; +using NETworkManager.Localization.Resources; +using NETworkManager.Models; +using NETworkManager.Models.Network; +using NETworkManager.Profiles; +using NETworkManager.Settings; +using NETworkManager.Utilities; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; @@ -8,14 +16,6 @@ using System.Windows.Data; using System.Windows.Input; using System.Windows.Threading; -using MahApps.Metro.Controls; -using MahApps.Metro.Controls.Dialogs; -using NETworkManager.Localization.Resources; -using NETworkManager.Models; -using NETworkManager.Models.Network; -using NETworkManager.Profiles; -using NETworkManager.Settings; -using NETworkManager.Utilities; namespace NETworkManager.ViewModels; @@ -328,7 +328,7 @@ private void EditProfileAction() private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -344,7 +344,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -466,7 +466,7 @@ private void SetProfilesView(ProfileInfo profile = null) { if (string.IsNullOrEmpty(Search)) return true; - + if (o is not ProfileInfo info) return false; diff --git a/Source/NETworkManager/ViewModels/WebConsoleHostViewModel.cs b/Source/NETworkManager/ViewModels/WebConsoleHostViewModel.cs index a5071a1cbb..65412c07d3 100644 --- a/Source/NETworkManager/ViewModels/WebConsoleHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/WebConsoleHostViewModel.cs @@ -1,14 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Data; -using System.Windows.Input; -using System.Windows.Threading; -using Dragablz; +using Dragablz; using MahApps.Metro.Controls.Dialogs; using Microsoft.Web.WebView2.Core; using NETworkManager.Controls; @@ -21,6 +11,16 @@ using NETworkManager.Settings; using NETworkManager.Utilities; using NETworkManager.Views; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; +using System.Windows.Input; +using System.Windows.Threading; namespace NETworkManager.ViewModels; @@ -312,14 +312,14 @@ private bool ModifyProfile_CanExecute(object obj) private void EditProfileAction() { - ProfileDialogManager.ShowEditProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowEditProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand CopyAsProfileCommand => new RelayCommand(_ => CopyAsProfileAction(), ModifyProfile_CanExecute); private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -335,7 +335,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -484,7 +484,7 @@ private void SetProfilesView(ProfileInfo profile = null) { if (string.IsNullOrEmpty(Search)) return true; - + if (o is not ProfileInfo info) return false; diff --git a/Source/NETworkManager/ViewModels/WhoisHostViewModel.cs b/Source/NETworkManager/ViewModels/WhoisHostViewModel.cs index 40aef3e150..38c6812290 100644 --- a/Source/NETworkManager/ViewModels/WhoisHostViewModel.cs +++ b/Source/NETworkManager/ViewModels/WhoisHostViewModel.cs @@ -1,13 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using System.Windows; -using System.Windows.Data; -using System.Windows.Input; -using System.Windows.Threading; -using Dragablz; +using Dragablz; using MahApps.Metro.Controls.Dialogs; using NETworkManager.Controls; using NETworkManager.Localization.Resources; @@ -16,6 +7,15 @@ using NETworkManager.Settings; using NETworkManager.Utilities; using NETworkManager.Views; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Linq; +using System.Windows; +using System.Windows.Data; +using System.Windows.Input; +using System.Windows.Threading; namespace NETworkManager.ViewModels; @@ -251,7 +251,7 @@ private void QueryProfileAction() private void AddProfileAction() { - ProfileDialogManager.ShowAddProfileDialog(Application.Current.MainWindow, this, null, null, ApplicationName.Whois) + ProfileDialogManager.ShowAddProfileDialog(Application.Current.MainWindow, this, null, null, ApplicationName.Whois) .ConfigureAwait(false); } @@ -271,7 +271,7 @@ private void EditProfileAction() private void CopyAsProfileAction() { - ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow,this, SelectedProfile).ConfigureAwait(false); + ProfileDialogManager.ShowCopyAsProfileDialog(Application.Current.MainWindow, this, SelectedProfile).ConfigureAwait(false); } public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute); @@ -287,7 +287,7 @@ private void DeleteProfileAction() private void EditGroupAction(object group) { - ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())) + ProfileDialogManager.ShowEditGroupDialog(Application.Current.MainWindow, this, ProfileManager.GetGroupByName($"{group}")) .ConfigureAwait(false); } @@ -374,9 +374,9 @@ private void SetProfilesView(ProfileInfo profile = null) { if (string.IsNullOrEmpty(Search)) return true; - + if (o is not ProfileInfo info) - return false; + return false; var search = Search.Trim(); diff --git a/Source/NETworkManager/Views/GroupDialog.xaml b/Source/NETworkManager/Views/GroupChildWindow.xaml similarity index 99% rename from Source/NETworkManager/Views/GroupDialog.xaml rename to Source/NETworkManager/Views/GroupChildWindow.xaml index 517021c395..4328ceb7dd 100644 --- a/Source/NETworkManager/Views/GroupDialog.xaml +++ b/Source/NETworkManager/Views/GroupChildWindow.xaml @@ -3,36 +3,44 @@ to enable/disable it AND in the list view (rectangle) to indicate that a page has an error. --> - - + xmlns:profiles="clr-namespace:NETworkManager.Profiles;assembly=NETworkManager.Profiles" + xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks" + xmlns:simpleChildWindow="clr-namespace:MahApps.Metro.SimpleChildWindow;assembly=MahApps.Metro.SimpleChildWindow" + ShowTitleBar="True" + TitleBarBackground="Transparent" + TitleBarNonActiveBackground="Transparent" + ShowCloseButton="True" + CloseButtonCommand="{Binding CancelCommand}" + AllowMove="True" + TitleForeground="{DynamicResource MahApps.Brushes.Gray3}" + CloseByEscape="False" + OverlayBrush="{DynamicResource ResourceKey=MahApps.Brushes.Gray.SemiTransparent}" + Loaded="UserControl_Loaded" + mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:GroupViewModel}"> + - - - - - + + + + + - - + + @@ -2484,4 +2492,4 @@ Style="{StaticResource DefaultButton}" /> - \ No newline at end of file + \ No newline at end of file diff --git a/Source/NETworkManager/Views/GroupChildWindow.xaml.cs b/Source/NETworkManager/Views/GroupChildWindow.xaml.cs new file mode 100644 index 0000000000..af6ecd6e24 --- /dev/null +++ b/Source/NETworkManager/Views/GroupChildWindow.xaml.cs @@ -0,0 +1,35 @@ +using System.Windows; +using System.Windows.Input; + +namespace NETworkManager.Views; + +public partial class GroupChildWindow +{ + public GroupChildWindow(Window parentWindow) + { + InitializeComponent(); + + // Set the width and height of the child window based on the parent window size + ChildWindowMaxWidth = 1050; + ChildWindowMaxHeight = 650; + ChildWindowWidth = parentWindow.ActualWidth * 0.85; + ChildWindowHeight = parentWindow.ActualHeight * 0.85; + + // Update the size of the child window when the parent window is resized + parentWindow.SizeChanged += (_, _) => + { + ChildWindowWidth = parentWindow.ActualWidth * 0.85; + ChildWindowHeight = parentWindow.ActualHeight * 0.85; + }; + } + + private void UserControl_Loaded(object sender, RoutedEventArgs e) + { + TextBoxName.Focus(); + } + + private void ScrollViewer_ManipulationBoundaryFeedback(object sender, ManipulationBoundaryFeedbackEventArgs e) + { + e.Handled = true; + } +} \ No newline at end of file diff --git a/Source/NETworkManager/Views/GroupDialog.xaml.cs b/Source/NETworkManager/Views/GroupDialog.xaml.cs deleted file mode 100644 index a5ee24cef0..0000000000 --- a/Source/NETworkManager/Views/GroupDialog.xaml.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Windows; -using System.Windows.Input; - -namespace NETworkManager.Views; - -public partial class GroupDialog -{ - public GroupDialog() - { - InitializeComponent(); - } - - private void UserControl_Loaded(object sender, RoutedEventArgs e) - { - TextBoxName.Focus(); - } - - private void ScrollViewer_ManipulationBoundaryFeedback(object sender, - ManipulationBoundaryFeedbackEventArgs e) - { - e.Handled = true; - } -} \ No newline at end of file diff --git a/Source/NETworkManager/Views/ProfileChildWindow.xaml b/Source/NETworkManager/Views/ProfileChildWindow.xaml index 3a5bfbad97..6cffd4ac6b 100644 --- a/Source/NETworkManager/Views/ProfileChildWindow.xaml +++ b/Source/NETworkManager/Views/ProfileChildWindow.xaml @@ -34,20 +34,14 @@ - - - - - + + + + + - + diff --git a/Website/docs/changelog/next-release.md b/Website/docs/changelog/next-release.md index 0c4f69757f..3cbc742488 100644 --- a/Website/docs/changelog/next-release.md +++ b/Website/docs/changelog/next-release.md @@ -41,6 +41,7 @@ Release date: **xx.xx.2025** - Redesign welcome dialog. [#3077](https://github.com/BornToBeRoot/NETworkManager/pull/3077) - Redesign profile dialog. [#3087](https://github.com/BornToBeRoot/NETworkManager/pull/3087) +- Redesign group dialog. [#3089](https://github.com/BornToBeRoot/NETworkManager/pull/3089) - Redesign confirm delete dialog. [#3087](https://github.com/BornToBeRoot/NETworkManager/pull/3087) - Add upgrade dialog when updating from a previous version. [#3077](https://github.com/BornToBeRoot/NETworkManager/pull/3077)