Skip to content

Commit ac8dc84

Browse files
committed
Feature: Profile file unlock child window
1 parent 6b943c8 commit ac8dc84

31 files changed

+192
-145
lines changed

Source/NETworkManager.Localization/Resources/Strings.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Source/NETworkManager.Localization/Resources/Strings.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3876,4 +3876,7 @@ Right-click for more options.</value>
38763876
<data name="Donate" xml:space="preserve">
38773877
<value>Donate</value>
38783878
</data>
3879+
<data name="ProfileFile" xml:space="preserve">
3880+
<value>Profile file</value>
3881+
</data>
38793882
</root>

Source/NETworkManager.Settings/ConfigurationInfo.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,27 @@ public string ProfileManagerErrorMessage
430430
}
431431
}
432432

433+
/// <summary>
434+
/// Private variable for <see cref="IsChildWindowOpen" />.
435+
/// </summary>
436+
private bool _isChildWindowOpen;
437+
438+
/// <summary>
439+
/// Indicates if a child window is open.
440+
/// </summary>
441+
public bool IsChildWindowOpen
442+
{
443+
get => _isChildWindowOpen;
444+
set
445+
{
446+
if (value == _isChildWindowOpen)
447+
return;
448+
449+
_isChildWindowOpen = value;
450+
OnPropertyChanged();
451+
}
452+
}
453+
433454
/// <summary>
434455
/// Private variable for <see cref="FixAirspace" />.
435456
/// </summary>

Source/NETworkManager/MainWindow.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
</mah:WindowCommands>
8989
</mah:MetroWindow.LeftWindowCommands>
9090
<mah:MetroWindow.RightWindowCommands>
91-
<mah:WindowCommands ShowSeparators="False" Visibility="{Binding IsWelcomeWindowOpen, Converter={StaticResource BooleanReverseToVisibilityCollapsedConverter}}">
91+
<mah:WindowCommands ShowSeparators="False" Visibility="{Binding Source={x:Static settings:ConfigurationManager.Current}, Path=IsChildWindowOpen, Converter={StaticResource BooleanReverseToVisibilityCollapsedConverter}}">
9292
<Button Command="{Binding OpenRunCommand}"
9393
Visibility="{Binding Path=FlyoutRunCommandIsOpen, Converter={StaticResource ResourceKey=BooleanReverseToVisibilityCollapsedConverter}}"
9494
ToolTip="{x:Static localization:Strings.ToolTip_RunCommandWithHotKey}"

Source/NETworkManager/MainWindow.xaml.cs

Lines changed: 38 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using log4net;
1+
using Dragablz;
2+
using log4net;
23
using MahApps.Metro.Controls.Dialogs;
34
using MahApps.Metro.SimpleChildWindow;
45
using NETworkManager.Controls;
@@ -9,8 +10,6 @@
910
using NETworkManager.Models.AWS;
1011
using NETworkManager.Models.EventSystem;
1112
using NETworkManager.Models.Network;
12-
using NETworkManager.Models.PowerShell;
13-
using NETworkManager.Models.PuTTY;
1413
using NETworkManager.Profiles;
1514
using NETworkManager.Settings;
1615
using NETworkManager.Update;
@@ -19,11 +18,9 @@
1918
using NETworkManager.Views;
2019
using System;
2120
using System.Collections.Generic;
22-
using System.Collections.ObjectModel;
2321
using System.ComponentModel;
2422
using System.Diagnostics;
2523
using System.Drawing;
26-
using System.IO;
2724
using System.Linq;
2825
using System.Net.NetworkInformation;
2926
using System.Runtime.CompilerServices;
@@ -38,7 +35,6 @@
3835
using System.Windows.Interop;
3936
using System.Windows.Markup;
4037
using System.Windows.Threading;
41-
using Dragablz;
4238
using Application = System.Windows.Application;
4339
using ContextMenu = System.Windows.Controls.ContextMenu;
4440
using MouseEventArgs = System.Windows.Forms.MouseEventArgs;
@@ -116,21 +112,6 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null)
116112
private bool _isInTray;
117113
private bool _isClosing;
118114

119-
private bool _isWelcomeWindowOpen;
120-
121-
public bool IsWelcomeWindowOpen
122-
{
123-
get => _isWelcomeWindowOpen;
124-
set
125-
{
126-
if (value == _isWelcomeWindowOpen)
127-
return;
128-
129-
_isWelcomeWindowOpen = value;
130-
OnPropertyChanged();
131-
}
132-
}
133-
134115
private bool _applicationViewIsExpanded;
135116

136117
public bool ApplicationViewIsExpanded
@@ -412,7 +393,7 @@ public ProfileFileInfo SelectedProfileFile
412393
{
413394
if (!_isProfileFileUpdating)
414395
LoadProfile(value);
415-
396+
416397
ConfigurationManager.Current.ProfileManagerShowUnlock = value.IsEncrypted && !value.IsPasswordValid;
417398
SettingsManager.Current.Profiles_LastSelected = value.Name;
418399
}
@@ -492,13 +473,13 @@ await this.ShowMessageAsync(Strings.SettingsHaveBeenReset,
492473
if (SettingsManager.Current.WelcomeDialog_Show)
493474
{
494475

495-
var welcomeChildWindow = new WelcomeChildWindow();
476+
var childWindow = new WelcomeChildWindow();
496477

497-
var welcomeViewModel = new WelcomeViewModel(async instance =>
478+
var viewModel = new WelcomeViewModel(instance =>
498479
{
499-
IsWelcomeWindowOpen = false;
480+
childWindow.IsOpen = false;
500481

501-
welcomeChildWindow.IsOpen = false;
482+
ConfigurationManager.Current.IsChildWindowOpen = false;
502483

503484
// Set settings based on user choice
504485
SettingsManager.Current.Update_CheckForUpdatesAtStartup = instance.CheckForUpdatesAtStartup;
@@ -511,21 +492,13 @@ await this.ShowMessageAsync(Strings.SettingsHaveBeenReset,
511492
instance.PowerShellModifyGlobalProfile;
512493

513494
// Generate lists at runtime
514-
SettingsManager.Current.General_ApplicationList =
515-
new ObservableSetCollection<ApplicationInfo>(ApplicationManager.GetDefaultList());
516-
SettingsManager.Current.IPScanner_CustomCommands =
517-
new ObservableCollection<CustomCommandInfo>(IPScannerCustomCommand.GetDefaultList());
518-
SettingsManager.Current.PortScanner_PortProfiles =
519-
new ObservableCollection<PortProfileInfo>(PortProfile.GetDefaultList());
520-
SettingsManager.Current.DNSLookup_DNSServers =
521-
new ObservableCollection<DNSServerConnectionInfoProfile>(DNSServer.GetDefaultList());
522-
SettingsManager.Current.AWSSessionManager_AWSProfiles =
523-
new ObservableCollection<AWSProfileInfo>(AWSProfile.GetDefaultList());
524-
SettingsManager.Current.SNMP_OidProfiles =
525-
new ObservableCollection<SNMPOIDProfileInfo>(SNMPOIDProfile.GetDefaultList());
526-
SettingsManager.Current.SNTPLookup_SNTPServers =
527-
new ObservableCollection<ServerConnectionInfoProfile>(SNTPServer.GetDefaultList());
528-
495+
SettingsManager.Current.General_ApplicationList = [.. ApplicationManager.GetDefaultList()];
496+
SettingsManager.Current.IPScanner_CustomCommands = [.. IPScannerCustomCommand.GetDefaultList()];
497+
SettingsManager.Current.PortScanner_PortProfiles = [.. PortProfile.GetDefaultList()];
498+
SettingsManager.Current.DNSLookup_DNSServers = [.. DNSServer.GetDefaultList()];
499+
SettingsManager.Current.AWSSessionManager_AWSProfiles = [.. AWSProfile.GetDefaultList()];
500+
SettingsManager.Current.SNMP_OidProfiles = [.. SNMPOIDProfile.GetDefaultList()];
501+
SettingsManager.Current.SNTPLookup_SNTPServers = [.. SNTPServer.GetDefaultList()];
529502
SettingsManager.Current.WelcomeDialog_Show = false;
530503

531504
// Save it to create a settings file
@@ -534,11 +507,11 @@ await this.ShowMessageAsync(Strings.SettingsHaveBeenReset,
534507
Load();
535508
});
536509

537-
welcomeChildWindow.DataContext = welcomeViewModel;
510+
childWindow.DataContext = viewModel;
538511

539-
IsWelcomeWindowOpen = true;
512+
ConfigurationManager.Current.IsChildWindowOpen = true;
540513

541-
await this.ShowChildWindowAsync(welcomeChildWindow);
514+
await this.ShowChildWindowAsync(childWindow);
542515
}
543516
else
544517
{
@@ -1395,7 +1368,7 @@ private void LoadProfiles()
13951368
.FirstOrDefault(x => x.Name == SettingsManager.Current.Profiles_LastSelected);
13961369
SelectedProfileFile ??= ProfileFiles.SourceCollection.Cast<ProfileFileInfo>().FirstOrDefault();
13971370
}
1398-
1371+
13991372
private async void LoadProfile(ProfileFileInfo info, bool showWrongPassword = false)
14001373
{
14011374
// Disable profile management while switching profiles
@@ -1404,34 +1377,37 @@ private async void LoadProfile(ProfileFileInfo info, bool showWrongPassword = fa
14041377

14051378
if (info.IsEncrypted && !info.IsPasswordValid)
14061379
{
1407-
var customDialog = new CustomDialog
1408-
{
1409-
Title = Strings.UnlockProfileFile
1410-
};
1380+
var childWindow = new CredentialsPasswordProfileFileChildWindow();
14111381

1412-
var viewModel = new CredentialsPasswordProfileFileViewModel(async instance =>
1382+
var viewModel = new CredentialsPasswordProfileFileViewModel(instance =>
14131383
{
1414-
await this.HideMetroDialogAsync(customDialog);
1384+
childWindow.IsOpen = false;
1385+
1386+
ConfigurationManager.Current.IsChildWindowOpen = false;
1387+
14151388
ConfigurationManager.OnDialogClose();
14161389

14171390
info.Password = instance.Password;
14181391

14191392
SwitchProfile(info);
1420-
}, async _ =>
1393+
}, _ =>
14211394
{
1422-
await this.HideMetroDialogAsync(customDialog);
1395+
childWindow.IsOpen = false;
1396+
1397+
ConfigurationManager.Current.IsChildWindowOpen = false;
1398+
14231399
ConfigurationManager.OnDialogClose();
14241400

14251401
ProfileManager.Unload();
14261402
}, info.Name, showWrongPassword);
14271403

1428-
customDialog.Content = new CredentialsPasswordProfileFileDialog
1429-
{
1430-
DataContext = viewModel
1431-
};
1404+
childWindow.DataContext = viewModel;
14321405

14331406
ConfigurationManager.OnDialogOpen();
1434-
await this.ShowMetroDialogAsync(customDialog);
1407+
1408+
ConfigurationManager.Current.IsChildWindowOpen = true;
1409+
1410+
await this.ShowChildWindowAsync(childWindow);
14351411
}
14361412
else
14371413
{
@@ -1566,7 +1542,7 @@ private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref
15661542

15671543
// Handle system commands (like maximize and restore)
15681544
case WmSysCommand:
1569-
1545+
15701546
switch (wParam.ToInt32())
15711547
{
15721548
// Window is maximized
@@ -1584,7 +1560,7 @@ private IntPtr HwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref
15841560

15851561
return IntPtr.Zero;
15861562
}
1587-
1563+
15881564
private void UpdateOnWindowResize()
15891565
{
15901566
foreach (var tabablzControl in VisualTreeHelper.FindVisualChildren<TabablzControl>(this))
@@ -1609,6 +1585,7 @@ private void UpdateOnWindowResize()
16091585
private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
16101586

16111587
[DllImport("user32.dll")]
1588+
16121589
private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
16131590

16141591
// WM_HOTKEY
@@ -1920,7 +1897,7 @@ private void ConfigureDNSServer()
19201897

19211898
DNSClient.GetInstance().Configure(dnsSettings);
19221899
}
1923-
1900+
19241901
#endregion
19251902

19261903
#region Status window

Source/NETworkManager/Resources/Styles/PasswordBoxStyles.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<Setter Property="FontSize" Value="14" />
1212
<Setter Property="BorderBrush" Value="{DynamicResource MahApps.Brushes.Gray8}" />
1313
<Setter Property="VerticalContentAlignment" Value="Center" />
14+
<Setter Property="mah:ControlsHelper.FocusBorderBrush" Value="{DynamicResource MahApps.Brushes.Gray8}" />
1415
<Setter Property="mah:PasswordBoxHelper.CapsLockWarningToolTip"
1516
Value="{x:Static localization:Strings.CapsLockIsEnabled}" />
1617
<Setter Property="mah:PasswordBoxHelper.CapsLockIcon">

Source/NETworkManager/ViewModels/ARPTableViewModel.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ private set
252252

253253
private bool Refresh_CanExecute(object parameter)
254254
{
255-
return Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen;
255+
return Application.Current.MainWindow != null &&
256+
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen &&
257+
!ConfigurationManager.Current.IsChildWindowOpen;
256258
}
257259

258260
private async Task RefreshAction()
@@ -267,7 +269,9 @@ private async Task RefreshAction()
267269

268270
private bool DeleteTable_CanExecute(object parameter)
269271
{
270-
return Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen;
272+
return Application.Current.MainWindow != null &&
273+
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen &&
274+
!ConfigurationManager.Current.IsChildWindowOpen;
271275
}
272276

273277
private async Task DeleteTableAction()
@@ -297,8 +301,8 @@ private async Task DeleteTableAction()
297301
private bool DeleteEntry_CanExecute(object parameter)
298302
{
299303
return Application.Current.MainWindow != null &&
300-
!((MetroWindow)Application.Current.MainWindow)
301-
.IsAnyDialogOpen;
304+
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen &&
305+
!ConfigurationManager.Current.IsChildWindowOpen;;
302306
}
303307

304308
private async Task DeleteEntryAction()
@@ -328,8 +332,8 @@ private async Task DeleteEntryAction()
328332
private bool AddEntry_CanExecute(object parameter)
329333
{
330334
return Application.Current.MainWindow != null &&
331-
!((MetroWindow)Application.Current.MainWindow)
332-
.IsAnyDialogOpen;
335+
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen &&
336+
!ConfigurationManager.Current.IsChildWindowOpen;
333337
}
334338

335339
private async Task AddEntryAction()

Source/NETworkManager/ViewModels/BitCalculatorViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ private void LoadSettings()
155155
private bool Calculate_CanExecute(object parameter)
156156
{
157157
return Application.Current.MainWindow != null &&
158-
!((MetroWindow)Application.Current.MainWindow)
159-
.IsAnyDialogOpen;
158+
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen &&
159+
!ConfigurationManager.Current.IsChildWindowOpen;
160160
}
161161

162162
private void CalculateAction()

Source/NETworkManager/ViewModels/ConnectionsViewModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,9 @@ public string StatusMessage
276276

277277
private bool Refresh_CanExecute(object parameter)
278278
{
279-
return Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen;
279+
return Application.Current.MainWindow != null &&
280+
!((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen &&
281+
!ConfigurationManager.Current.IsChildWindowOpen;
280282
}
281283

282284
private async Task RefreshAction()

Source/NETworkManager/ViewModels/CredentialsPasswordProfileFileViewModel.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
using System;
1+
using NETworkManager.Utilities;
2+
using System;
23
using System.Security;
34
using System.Windows.Input;
4-
using NETworkManager.Utilities;
55

66
namespace NETworkManager.ViewModels;
77

@@ -27,7 +27,6 @@ public class CredentialsPasswordProfileFileViewModel : ViewModelBase
2727
/// </summary>
2828
private bool _showWrongPassword;
2929

30-
3130
/// <summary>
3231
/// Initialize a new class <see cref="CredentialsPasswordProfileFileViewModel" /> with <see cref="OKCommand" /> and
3332
/// <see cref="CancelCommand" />.

0 commit comments

Comments
 (0)