|
6 | 6 | using NETworkManager.Utilities; |
7 | 7 | using NETworkManager.Views; |
8 | 8 | using System.ComponentModel; |
| 9 | +using System.Linq; |
9 | 10 | using System.Threading.Tasks; |
10 | 11 | using System.Windows; |
11 | 12 | using System.Windows.Data; |
@@ -142,6 +143,8 @@ public PortScannerSettingsViewModel(IDialogCoordinator instance) |
142 | 143 | PortProfiles.SortDescriptions.Add( |
143 | 144 | new SortDescription(nameof(PortProfileInfo.Name), ListSortDirection.Ascending)); |
144 | 145 |
|
| 146 | + SelectedPortProfile = PortProfiles.Cast<PortProfileInfo>().FirstOrDefault(); |
| 147 | + |
145 | 148 | LoadSettings(); |
146 | 149 |
|
147 | 150 | _isLoading = false; |
@@ -232,30 +235,21 @@ public async Task EditPortProfile() |
232 | 235 | await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog); |
233 | 236 | } |
234 | 237 |
|
235 | | - private Task DeletePortProfile() |
| 238 | + private async Task DeletePortProfile() |
236 | 239 | { |
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); |
253 | 245 |
|
254 | | - childWindow.DataContext = childWindowViewModel; |
| 246 | + if (!result) |
| 247 | + return; |
255 | 248 |
|
256 | | - ConfigurationManager.Current.IsChildWindowOpen = true; |
| 249 | + SettingsManager.Current.PortScanner_PortProfiles.Remove(SelectedPortProfile); |
257 | 250 |
|
258 | | - return (Application.Current.MainWindow as MainWindow).ShowChildWindowAsync(childWindow); |
| 251 | + // Select first item after deletion |
| 252 | + SelectedPortProfile = PortProfiles.Cast<PortProfileInfo>().FirstOrDefault(); |
259 | 253 | } |
260 | 254 |
|
261 | 255 | #endregion |
|
0 commit comments