Skip to content

Commit 34bfbfc

Browse files
committed
Chore: Migrate to new dialog helper
1 parent 9257e1d commit 34bfbfc

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

Source/NETworkManager.Utilities/SecureStringHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static class SecureStringHelper
99
public static string ConvertToString(SecureString secureString)
1010
{
1111
var valuePtr = IntPtr.Zero;
12+
1213
try
1314
{
1415
valuePtr = Marshal.SecureStringToGlobalAllocUnicode(secureString);

Source/NETworkManager/ViewModels/PortScannerSettingsViewModel.cs

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using NETworkManager.Utilities;
77
using NETworkManager.Views;
88
using System.ComponentModel;
9+
using System.Linq;
910
using System.Threading.Tasks;
1011
using System.Windows;
1112
using System.Windows.Data;
@@ -142,6 +143,8 @@ public PortScannerSettingsViewModel(IDialogCoordinator instance)
142143
PortProfiles.SortDescriptions.Add(
143144
new SortDescription(nameof(PortProfileInfo.Name), ListSortDirection.Ascending));
144145

146+
SelectedPortProfile = PortProfiles.Cast<PortProfileInfo>().FirstOrDefault();
147+
145148
LoadSettings();
146149

147150
_isLoading = false;
@@ -232,30 +235,21 @@ public async Task EditPortProfile()
232235
await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
233236
}
234237

235-
private Task DeletePortProfile()
238+
private async Task DeletePortProfile()
236239
{
237-
var childWindow = new OKCancelMessageChildWindow();
238-
239-
var childWindowViewModel = new OKCancelMessageViewModel(_ =>
240-
{
241-
childWindow.IsOpen = false;
242-
ConfigurationManager.Current.IsChildWindowOpen = false;
243-
244-
SettingsManager.Current.PortScanner_PortProfiles.Remove(SelectedPortProfile);
245-
}, _ =>
246-
{
247-
childWindow.IsOpen = false;
248-
ConfigurationManager.Current.IsChildWindowOpen = false;
249-
},
250-
Strings.DeletePortProfileMessage, ChildWindowIcon.Info, Strings.Delete);
251-
252-
childWindow.Title = Strings.DeletePortProfile;
240+
var result = await DialogHelper.ShowOKCancelMessageAsync(Application.Current.MainWindow,
241+
Strings.DeletePortProfile,
242+
Strings.DeletePortProfileMessage,
243+
ChildWindowIcon.Info,
244+
Strings.Delete);
253245

254-
childWindow.DataContext = childWindowViewModel;
246+
if (!result)
247+
return;
255248

256-
ConfigurationManager.Current.IsChildWindowOpen = true;
249+
SettingsManager.Current.PortScanner_PortProfiles.Remove(SelectedPortProfile);
257250

258-
return (Application.Current.MainWindow as MainWindow).ShowChildWindowAsync(childWindow);
251+
// Select first item after deletion
252+
SelectedPortProfile = PortProfiles.Cast<PortProfileInfo>().FirstOrDefault();
259253
}
260254

261255
#endregion

0 commit comments

Comments
 (0)