Skip to content

Commit 10dfca3

Browse files
committed
Feature: Expand / Collapse row via button
1 parent 33a7d68 commit 10dfca3

File tree

6 files changed

+126
-88
lines changed

6 files changed

+126
-88
lines changed

Source/NETworkManager/ViewModels/DNSLookupHostViewModel.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public int SelectedTabIndex
4747
}
4848

4949
#region Profiles
50-
public ICollectionView _profiles;
50+
51+
private ICollectionView _profiles;
5152
public ICollectionView Profiles
5253
{
5354
get => _profiles;

Source/NETworkManager/ViewModels/IPScannerHostViewModel.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public IPScannerHostViewModel(IDialogCoordinator instance)
164164

165165
TabItems = new ObservableCollection<DragablzTabItem>
166166
{
167-
new DragablzTabItem(Localization.Resources.Strings.NewTab, new IPScannerView(_tabId), _tabId)
167+
new(Localization.Resources.Strings.NewTab, new IPScannerView(_tabId), _tabId)
168168
};
169169

170170
// Profiles
@@ -191,14 +191,14 @@ private void LoadSettings()
191191
#endregion
192192

193193
#region ICommand & Actions
194-
public ICommand AddTabCommand => new RelayCommand(p => AddTabAction());
194+
public ICommand AddTabCommand => new RelayCommand(_ => AddTabAction());
195195

196196
private void AddTabAction()
197197
{
198198
AddTab();
199199
}
200200

201-
public ICommand ScanProfileCommand => new RelayCommand(p => ScanProfileAction(), ScanProfile_CanExecute);
201+
public ICommand ScanProfileCommand => new RelayCommand(_ => ScanProfileAction(), ScanProfile_CanExecute);
202202

203203
private bool ScanProfile_CanExecute(object obj)
204204
{
@@ -210,44 +210,44 @@ private void ScanProfileAction()
210210
AddTab(SelectedProfile);
211211
}
212212

213-
public ICommand AddProfileCommand => new RelayCommand(p => AddProfileAction());
213+
public ICommand AddProfileCommand => new RelayCommand(_ => AddProfileAction());
214214

215215
private void AddProfileAction()
216216
{
217-
ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.IPScanner);
217+
ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, null, null, ApplicationName.IPScanner).ConfigureAwait(true);
218218
}
219219

220-
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile != null && !SelectedProfile.IsDynamic;
220+
private bool ModifyProfile_CanExecute(object obj) => SelectedProfile is { IsDynamic: false };
221221

222-
public ICommand EditProfileCommand => new RelayCommand(p => EditProfileAction(), ModifyProfile_CanExecute);
222+
public ICommand EditProfileCommand => new RelayCommand(_ => EditProfileAction(), ModifyProfile_CanExecute);
223223

224224
private void EditProfileAction()
225225
{
226-
ProfileDialogManager.ShowEditProfileDialog(this, _dialogCoordinator, SelectedProfile);
226+
ProfileDialogManager.ShowEditProfileDialog(this, _dialogCoordinator, SelectedProfile).ConfigureAwait(true);
227227
}
228228

229-
public ICommand CopyAsProfileCommand => new RelayCommand(p => CopyAsProfileAction(), ModifyProfile_CanExecute);
229+
public ICommand CopyAsProfileCommand => new RelayCommand(_ => CopyAsProfileAction(), ModifyProfile_CanExecute);
230230

231231
private void CopyAsProfileAction()
232232
{
233-
ProfileDialogManager.ShowCopyAsProfileDialog(this, _dialogCoordinator, SelectedProfile);
233+
ProfileDialogManager.ShowCopyAsProfileDialog(this, _dialogCoordinator, SelectedProfile).ConfigureAwait(true);
234234
}
235235

236-
public ICommand DeleteProfileCommand => new RelayCommand(p => DeleteProfileAction(), ModifyProfile_CanExecute);
236+
public ICommand DeleteProfileCommand => new RelayCommand(_ => DeleteProfileAction(), ModifyProfile_CanExecute);
237237

238238
private void DeleteProfileAction()
239239
{
240-
ProfileDialogManager.ShowDeleteProfileDialog(this, _dialogCoordinator, new List<ProfileInfo> { SelectedProfile });
240+
ProfileDialogManager.ShowDeleteProfileDialog(this, _dialogCoordinator, new List<ProfileInfo> { SelectedProfile }).ConfigureAwait(true);
241241
}
242242

243243
public ICommand EditGroupCommand => new RelayCommand(EditGroupAction);
244244

245245
private void EditGroupAction(object group)
246246
{
247-
ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString()));
247+
ProfileDialogManager.ShowEditGroupDialog(this, _dialogCoordinator, ProfileManager.GetGroup(group.ToString())).ConfigureAwait(true);
248248
}
249249

250-
public ICommand ClearSearchCommand => new RelayCommand(p => ClearSearchAction());
250+
public ICommand ClearSearchCommand => new RelayCommand(_ => ClearSearchAction());
251251

252252
private void ClearSearchAction()
253253
{
@@ -348,8 +348,8 @@ private void SetProfilesView(ProfileInfo profile = null)
348348
else
349349
SelectedProfile = Profiles.Cast<ProfileInfo>().FirstOrDefault();
350350
}
351-
352-
public void RefreshProfiles()
351+
352+
private void RefreshProfiles()
353353
{
354354
if (!_isViewActive)
355355
return;

Source/NETworkManager/ViewModels/IPScannerViewModel.cs

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,9 @@ private void LoadSettings()
266266

267267
#region ICommands & Actions
268268

269-
public ICommand ScanCommand => new RelayCommand(p => ScanAction(), Scan_CanExecute);
269+
public ICommand ScanCommand => new RelayCommand(_ => ScanAction(), Scan_CanExecute);
270270

271-
private bool Scan_CanExecute(object paramter)
271+
private bool Scan_CanExecute(object parameter)
272272
{
273273
return Application.Current.MainWindow != null && !((MetroWindow)Application.Current.MainWindow).IsAnyDialogOpen;
274274
}
@@ -278,7 +278,7 @@ private void ScanAction()
278278
Scan();
279279
}
280280

281-
public ICommand DetectSubnetCommand => new RelayCommand(p => DetectSubnetAction());
281+
public ICommand DetectSubnetCommand => new RelayCommand(_ => DetectSubnetAction());
282282

283283
private void DetectSubnetAction()
284284
{
@@ -299,14 +299,14 @@ private void RedirectDataToApplicationAction(object name)
299299
EventSystem.RedirectToApplication(applicationName, host);
300300
}
301301

302-
public ICommand PerformDNSLookupIPAddressCommand => new RelayCommand(p => PerformDNSLookupIPAddressAction());
302+
public ICommand PerformDNSLookupIPAddressCommand => new RelayCommand(_ => PerformDNSLookupIPAddressAction());
303303

304304
private void PerformDNSLookupIPAddressAction()
305305
{
306306
EventSystem.RedirectToApplication(ApplicationName.DNSLookup, SelectedResult.PingInfo.IPAddress.ToString());
307307
}
308308

309-
public ICommand PerformDNSLookupHostnameCommand => new RelayCommand(p => PerformDNSLookupHostnameAction());
309+
public ICommand PerformDNSLookupHostnameCommand => new RelayCommand(_ => PerformDNSLookupHostnameAction());
310310

311311
private void PerformDNSLookupHostnameAction()
312312
{
@@ -320,7 +320,7 @@ private void CustomCommandAction(object guid)
320320
CustomCommand(guid);
321321
}
322322

323-
public ICommand AddProfileSelectedHostCommand => new RelayCommand(p => AddProfileSelectedHostAction());
323+
public ICommand AddProfileSelectedHostCommand => new RelayCommand(_ => AddProfileSelectedHostAction());
324324

325325
private async void AddProfileSelectedHostAction()
326326
{
@@ -336,56 +336,56 @@ private async void AddProfileSelectedHostAction()
336336
await ProfileDialogManager.ShowAddProfileDialog(this, _dialogCoordinator, profileInfo);
337337
}
338338

339-
public ICommand CopySelectedStatusCommand => new RelayCommand(p => CopySelectedStatusAction());
339+
public ICommand CopySelectedStatusCommand => new RelayCommand(_ => CopySelectedStatusAction());
340340

341341
private void CopySelectedStatusAction()
342342
{
343343
ClipboardHelper.SetClipboard(SelectedResult.IsReachable.ToString());
344344
}
345345

346-
public ICommand CopySelectedIPAddressCommand => new RelayCommand(p => CopySelectedIPAddressAction());
346+
public ICommand CopySelectedIPAddressCommand => new RelayCommand(_ => CopySelectedIPAddressAction());
347347

348348
private void CopySelectedIPAddressAction()
349349
{
350350
ClipboardHelper.SetClipboard(SelectedResult.PingInfo.IPAddress.ToString());
351351
}
352352

353-
public ICommand CopySelectedHostnameCommand => new RelayCommand(p => CopySelectedHostnameAction());
353+
public ICommand CopySelectedHostnameCommand => new RelayCommand(_ => CopySelectedHostnameAction());
354354

355355
private void CopySelectedHostnameAction()
356356
{
357357
ClipboardHelper.SetClipboard(SelectedResult.Hostname);
358358
}
359359

360-
public ICommand CopySelectedPortStatusCommand => new RelayCommand(p => CopySelectedPortStatusAction());
360+
public ICommand CopySelectedPortStatusCommand => new RelayCommand(_ => CopySelectedPortStatusAction());
361361

362362
private void CopySelectedPortStatusAction()
363363
{
364364
ClipboardHelper.SetClipboard(ResourceTranslator.Translate(ResourceIdentifier.PortState, SelectedResult.IsAnyPortOpen ? PortState.Open : PortState.Closed));
365365
}
366366

367-
public ICommand CopySelectedPingStatusCommand => new RelayCommand(p => CopySelectedPingStatusAction());
367+
public ICommand CopySelectedPingStatusCommand => new RelayCommand(_ => CopySelectedPingStatusAction());
368368

369369
private void CopySelectedPingStatusAction()
370370
{
371371
ClipboardHelper.SetClipboard(ResourceTranslator.Translate(ResourceIdentifier.PortState, SelectedResult.PingInfo.Status));
372372
}
373373

374-
public ICommand CopySelectedMACAddressCommand => new RelayCommand(p => CopySelectedMACAddressAction());
374+
public ICommand CopySelectedMACAddressCommand => new RelayCommand(_ => CopySelectedMACAddressAction());
375375

376376
private void CopySelectedMACAddressAction()
377377
{
378378
ClipboardHelper.SetClipboard(MACAddressHelper.GetDefaultFormat(SelectedResult.MACAddress.ToString()));
379379
}
380380

381-
public ICommand CopySelectedVendorCommand => new RelayCommand(p => CopySelectedVendorAction());
381+
public ICommand CopySelectedVendorCommand => new RelayCommand(_ => CopySelectedVendorAction());
382382

383383
private void CopySelectedVendorAction()
384384
{
385385
ClipboardHelper.SetClipboard(SelectedResult.Vendor);
386386
}
387387

388-
public ICommand CopySelectedPortsCommand => new RelayCommand(p => CopySelectedPortsAction());
388+
public ICommand CopySelectedPortsCommand => new RelayCommand(_ => CopySelectedPortsAction());
389389

390390
private void CopySelectedPortsAction()
391391
{
@@ -399,28 +399,28 @@ private void CopySelectedPortsAction()
399399
ClipboardHelper.SetClipboard(stringBuilder.ToString());
400400
}
401401

402-
public ICommand CopySelectedBytesCommand => new RelayCommand(p => CopySelectedBytesAction());
402+
public ICommand CopySelectedBytesCommand => new RelayCommand(_ => CopySelectedBytesAction());
403403

404404
private void CopySelectedBytesAction()
405405
{
406406
ClipboardHelper.SetClipboard(SelectedResult.PingInfo.Bytes.ToString());
407407
}
408408

409-
public ICommand CopySelectedTimeCommand => new RelayCommand(p => CopySelectedTimeAction());
409+
public ICommand CopySelectedTimeCommand => new RelayCommand(_ => CopySelectedTimeAction());
410410

411411
private void CopySelectedTimeAction()
412412
{
413413
ClipboardHelper.SetClipboard(SelectedResult.PingInfo.Time.ToString());
414414
}
415415

416-
public ICommand CopySelectedTTLCommand => new RelayCommand(p => CopySelectedTTLAction());
416+
public ICommand CopySelectedTTLCommand => new RelayCommand(_ => CopySelectedTTLAction());
417417

418418
private void CopySelectedTTLAction()
419419
{
420420
ClipboardHelper.SetClipboard(SelectedResult.PingInfo.TTL.ToString());
421421
}
422422

423-
public ICommand ExportCommand => new RelayCommand(p => ExportAction());
423+
public ICommand ExportCommand => new RelayCommand(_ => ExportAction());
424424

425425
private void ExportAction()
426426
{
@@ -539,19 +539,16 @@ private async Task DetectIPRange()
539539
var subnetmaskDetected = false;
540540

541541
// Get subnetmask, based on ip address
542-
foreach (var networkInterface in await NetworkInterface.GetNetworkInterfacesAsync())
542+
foreach (var networkInterface in (await NetworkInterface.GetNetworkInterfacesAsync()).Where(networkInterface => networkInterface.IPv4Address.Any(x => x.Item1.Equals(localIP))))
543543
{
544-
if (networkInterface.IPv4Address.Any(x => x.Item1.Equals(localIP)))
545-
{
546-
subnetmaskDetected = true;
544+
subnetmaskDetected = true;
547545

548-
Hosts = $"{localIP}/{Subnetmask.ConvertSubnetmaskToCidr(networkInterface.IPv4Address.First().Item2)}";
546+
Hosts = $"{localIP}/{Subnetmask.ConvertSubnetmaskToCidr(networkInterface.IPv4Address.First().Item2)}";
549547

550-
// Fix: If the user clears the textbox and then clicks again on the button, the textbox remains empty...
551-
OnPropertyChanged(nameof(Hosts));
548+
// Fix: If the user clears the textbox and then clicks again on the button, the textbox remains empty...
549+
OnPropertyChanged(nameof(Hosts));
552550

553-
break;
554-
}
551+
break;
555552
}
556553

557554
if (!subnetmaskDetected)
@@ -569,14 +566,14 @@ private async Task CustomCommand(object guid)
569566
{
570567
if (guid is Guid id)
571568
{
572-
CustomCommandInfo info = (CustomCommandInfo)CustomCommands.FirstOrDefault(x => x.ID == id).Clone();
569+
var info = (CustomCommandInfo)CustomCommands.FirstOrDefault(x => x.ID == id)?.Clone();
573570

574571
if (info == null)
575572
return; // ToDo: Log and error message
576573

577574
// Replace vars
578-
string hostname = !string.IsNullOrEmpty(SelectedResult.Hostname) ? SelectedResult.Hostname.TrimEnd('.') : "";
579-
string ipAddress = SelectedResult.PingInfo.IPAddress.ToString();
575+
var hostname = !string.IsNullOrEmpty(SelectedResult.Hostname) ? SelectedResult.Hostname.TrimEnd('.') : "";
576+
var ipAddress = SelectedResult.PingInfo.IPAddress.ToString();
580577

581578
info.FilePath = Regex.Replace(info.FilePath, "\\$\\$hostname\\$\\$", hostname, RegexOptions.IgnoreCase);
582579
info.FilePath = Regex.Replace(info.FilePath, "\\$\\$ipaddress\\$\\$", ipAddress, RegexOptions.IgnoreCase);
@@ -636,7 +633,7 @@ private async Task Export()
636633

637634
SettingsManager.Current.IPScanner_ExportFileType = instance.FileType;
638635
SettingsManager.Current.IPScanner_ExportFilePath = instance.FilePath;
639-
}, instance => { _dialogCoordinator.HideMetroDialogAsync(this, customDialog); }, new ExportFileType[] { ExportFileType.Csv, ExportFileType.Xml, ExportFileType.Json }, true, SettingsManager.Current.IPScanner_ExportFileType, SettingsManager.Current.IPScanner_ExportFilePath);
636+
}, instance => { _dialogCoordinator.HideMetroDialogAsync(this, customDialog); }, new[] { ExportFileType.Csv, ExportFileType.Xml, ExportFileType.Json }, true, SettingsManager.Current.IPScanner_ExportFileType, SettingsManager.Current.IPScanner_ExportFilePath);
640637

641638
customDialog.Content = new ExportDialog
642639
{

0 commit comments

Comments
 (0)