Skip to content

Commit 1a485af

Browse files
committed
Settings/Dialog is working
1 parent 1120c95 commit 1a485af

File tree

10 files changed

+191
-29
lines changed

10 files changed

+191
-29
lines changed

Source/NETworkManager/Models/Settings/SettingsInfo.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,21 @@ public int IPScanner_ICMPTimeout
752752
}
753753
}
754754

755+
private ObservableCollection<CustomCommandInfo> _ipScanner_CustomCommands = new ObservableCollection<CustomCommandInfo>();
756+
public ObservableCollection<CustomCommandInfo> IPScanner_CustomCommands
757+
{
758+
get => _ipScanner_CustomCommands;
759+
set
760+
{
761+
if (value == _ipScanner_CustomCommands)
762+
return;
763+
764+
_ipScanner_CustomCommands = value;
765+
OnPropertyChanged();
766+
SettingsChanged = true;
767+
}
768+
}
769+
755770
private bool _ipScanner_ExpandStatistics = true;
756771
public bool IPScanner_ExpandStatistics
757772
{
@@ -3654,6 +3669,7 @@ public SettingsInfo()
36543669

36553670
// IP Scanner
36563671
IPScanner_HostHistory.CollectionChanged += CollectionChanged;
3672+
IPScanner_CustomCommands.CollectionChanged += CollectionChanged;
36573673

36583674
// Port Scanner
36593675
PortScanner_HostHistory.CollectionChanged += CollectionChanged;

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

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

Source/NETworkManager/Resources/Localization/StaticStrings.resx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,10 @@
279279
<data name="IExploreExe" xml:space="preserve">
280280
<value>iexplore.exe</value>
281281
</data>
282-
<data name="VariableCustomCommandHostname" xml:space="preserve">
283-
<value>%Hostname%</value>
282+
<data name="ExampleCustomCommandVariableHostname" xml:space="preserve">
283+
<value>https://$$HOSTNAME$$/</value>
284+
</data>
285+
<data name="InternetExplorer" xml:space="preserve">
286+
<value>Internet Explorer</value>
284287
</data>
285288
</root>

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

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

Source/NETworkManager/Resources/Localization/Strings.resx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,10 +2277,22 @@ is disabled!</value>
22772277
<data name="CustomCommands" xml:space="preserve">
22782278
<value>Custom commands</value>
22792279
</data>
2280+
<data name="AddCustomCommand" xml:space="preserve">
2281+
<value>Add custom command</value>
2282+
</data>
22802283
<data name="Arguments" xml:space="preserve">
22812284
<value>Arguments</value>
22822285
</data>
2286+
<data name="DeleteCustomCommand" xml:space="preserve">
2287+
<value>Delete custom command</value>
2288+
</data>
2289+
<data name="EditCustomCommand" xml:space="preserve">
2290+
<value>Edit custom command</value>
2291+
</data>
22832292
<data name="Program" xml:space="preserve">
22842293
<value>Program</value>
22852294
</data>
2295+
<data name="DeleteCustomCommandMessage" xml:space="preserve">
2296+
<value>The selected custom command will be deleted permanently.</value>
2297+
</data>
22862298
</root>

Source/NETworkManager/ViewModels/DNSLookupSettingsViewModel.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using Heijden.DNS;
22
using NETworkManager.Models.Settings;
33
using NETworkManager.Utilities;
4-
using System;
54
using System.Collections.Generic;
65
using System.ComponentModel;
76
using System.Linq;
@@ -385,13 +384,7 @@ public async void DeleteDNSServer()
385384
};
386385

387386
await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
388-
}
389-
390-
public void Refresh()
391-
{
392-
// Refresh
393-
DNSServers.Refresh();
394-
}
387+
}
395388
#endregion
396389
}
397390
}

Source/NETworkManager/ViewModels/IPScannerSettingsViewModel.cs

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
using Heijden.DNS;
2+
using MahApps.Metro.Controls.Dialogs;
23
using NETworkManager.Models.Settings;
34
using NETworkManager.Utilities;
4-
using System;
5+
using NETworkManager.Views;
56
using System.Collections.Generic;
7+
using System.ComponentModel;
68
using System.Linq;
9+
using System.Windows.Data;
710
using System.Windows.Input;
811

912
namespace NETworkManager.ViewModels
@@ -13,6 +16,8 @@ public class IPScannerSettingsViewModel : ViewModelBase
1316
#region Variables
1417
private readonly bool _isLoading;
1518

19+
private readonly IDialogCoordinator _dialogCoordinator;
20+
1621
private bool _showScanResultForAllIPAddresses;
1722
public bool ShowScanResultForAllIPAddresses
1823
{
@@ -270,6 +275,22 @@ public bool ResolveMACAddress
270275
}
271276
}
272277

278+
public ICollectionView CustomCommands { get; }
279+
280+
private CustomCommandInfo _selectedCustomCommand = new CustomCommandInfo();
281+
public CustomCommandInfo SelectedCustomCommand
282+
{
283+
get => _selectedCustomCommand;
284+
set
285+
{
286+
if (value == _selectedCustomCommand)
287+
return;
288+
289+
_selectedCustomCommand = value;
290+
OnPropertyChanged();
291+
}
292+
}
293+
273294
private bool _showStatistics;
274295
public bool ShowStatistics
275296
{
@@ -289,10 +310,15 @@ public bool ShowStatistics
289310
#endregion
290311

291312
#region Constructor, load settings
292-
public IPScannerSettingsViewModel()
293-
{
313+
public IPScannerSettingsViewModel(IDialogCoordinator instance)
314+
{
294315
_isLoading = true;
295316

317+
_dialogCoordinator = instance;
318+
319+
CustomCommands = CollectionViewSource.GetDefaultView(SettingsManager.Current.IPScanner_CustomCommands);
320+
CustomCommands.SortDescriptions.Add(new SortDescription(nameof(CustomCommandInfo.Name), ListSortDirection.Ascending));
321+
296322
LoadSettings();
297323

298324
_isLoading = false;
@@ -345,20 +371,83 @@ private void DeleteCustomCommandAction()
345371
DeleteCustomCommand();
346372
}
347373

348-
349374
#endregion
350375

351376
#region Methods
352377
public async void AddCustomCommand()
353378
{
379+
var customDialog = new CustomDialog
380+
{
381+
Title = Resources.Localization.Strings.AddCustomCommand
382+
};
383+
384+
var customCommandViewModel = new CustomCommandViewModel(instance =>
385+
{
386+
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
387+
388+
SettingsManager.Current.IPScanner_CustomCommands.Add(new CustomCommandInfo(instance.Name, instance.FilePath, instance.Arguments));
389+
}, instance =>
390+
{
391+
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
392+
});
393+
394+
customDialog.Content = new CustomCommandDialog
395+
{
396+
DataContext = customCommandViewModel
397+
};
398+
399+
await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
354400
}
355401

356402
public async void EditCustomCommand()
357403
{
404+
var customDialog = new CustomDialog
405+
{
406+
Title = Resources.Localization.Strings.EditCustomCommand
407+
};
408+
409+
var customCommandViewModel = new CustomCommandViewModel(instance =>
410+
{
411+
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
412+
413+
SettingsManager.Current.IPScanner_CustomCommands.Remove(SelectedCustomCommand);
414+
SettingsManager.Current.IPScanner_CustomCommands.Add(new CustomCommandInfo(instance.Name, instance.FilePath, instance.Arguments));
415+
}, instance =>
416+
{
417+
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
418+
}, true, SelectedCustomCommand);
419+
420+
customDialog.Content = new CustomCommandDialog
421+
{
422+
DataContext = customCommandViewModel
423+
};
424+
425+
await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
358426
}
359427

360428
public async void DeleteCustomCommand()
361429
{
430+
var customDialog = new CustomDialog
431+
{
432+
Title = Resources.Localization.Strings.DeleteCustomCommand
433+
};
434+
435+
var confirmRemoveViewModel = new ConfirmRemoveViewModel(instance =>
436+
{
437+
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
438+
439+
SettingsManager.Current.IPScanner_CustomCommands.Remove(SelectedCustomCommand);
440+
}, instance =>
441+
{
442+
_dialogCoordinator.HideMetroDialogAsync(this, customDialog);
443+
}, Resources.Localization.Strings.DeleteCustomCommandMessage);
444+
445+
customDialog.Content = new ConfirmRemoveDialog
446+
{
447+
DataContext = confirmRemoveViewModel
448+
};
449+
450+
await _dialogCoordinator.ShowMetroDialogAsync(this, customDialog);
362451
}
363452
#endregion
364453
}

Source/NETworkManager/Views/CustomCommandDialog.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<RowDefinition Height="Auto" />
3333
</Grid.RowDefinitions>
3434
<TextBlock Grid.Column="0" Grid.Row="0" Text="{x:Static localization:Strings.Name}" />
35-
<TextBox x:Name="TextBoxName" Grid.Column="2" Grid.Row="0" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleCredentialName}">
35+
<TextBox x:Name="TextBoxName" Grid.Column="2" Grid.Row="0" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.InternetExplorer}">
3636
<TextBox.Style>
3737
<Style TargetType="{x:Type TextBox}" BasedOn="{StaticResource DefaultTextBox}">
3838
<Style.Triggers>
@@ -75,7 +75,7 @@
7575
</TextBox.Text>
7676
</TextBox>
7777
<TextBlock Grid.Column="0" Grid.Row="4" Text="{x:Static localization:Strings.Arguments}" />
78-
<TextBox x:Name="TextBoxArguments" Grid.Column="2" Grid.Row="4" Text="{Binding Arguments, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.VariableCustomCommandHostname}" />
78+
<TextBox x:Name="TextBoxArguments" Grid.Column="2" Grid.Row="4" Text="{Binding Arguments, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" mah:TextBoxHelper.Watermark="{x:Static localization:StaticStrings.ExampleCustomCommandVariableHostname}" />
7979
</Grid>
8080
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
8181
<Button Content="{x:Static localization:Strings.Cancel}" Command="{Binding CancelCommand}" IsCancel="True" Style="{StaticResource DefaultButton}" />

Source/NETworkManager/Views/IPScannerSettingsView.xaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
xmlns:validators="clr-namespace:NETworkManager.Validators"
88
xmlns:viewModels="clr-namespace:NETworkManager.ViewModels"
99
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
10+
xmlns:utilities="clr-namespace:NETworkManager.Utilities"
1011
xmlns:localization="clr-namespace:NETworkManager.Resources.Localization"
12+
xmlns:dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
13+
dialogs:DialogParticipation.Register="{Binding}"
1114
mc:Ignorable="d" d:DataContext="{d:DesignInstance viewModels:IPScannerSettingsViewModel}">
1215
<StackPanel>
1316
<TextBlock Text="{x:Static localization:Strings.IPScanner}" Style="{StaticResource HeaderTextBlock}" />
@@ -110,7 +113,7 @@
110113
<Style.Triggers>
111114
<MultiDataTrigger>
112115
<MultiDataTrigger.Conditions>
113-
<Condition Binding="{Binding ElementName=DataGridDNSServers, Path=SelectedItems.Count}" Value="1" />
116+
<Condition Binding="{Binding ElementName=DataGridCustomCommands, Path=SelectedItems.Count}" Value="1" />
114117
</MultiDataTrigger.Conditions>
115118
<MultiDataTrigger.Setters>
116119
<Setter Property="IsEnabled" Value="True"/>
@@ -141,7 +144,7 @@
141144
<Style.Triggers>
142145
<MultiDataTrigger>
143146
<MultiDataTrigger.Conditions>
144-
<Condition Binding="{Binding ElementName=DataGridDNSServers, Path=SelectedItems.Count}" Value="1" />
147+
<Condition Binding="{Binding ElementName=DataGridCustomCommands, Path=SelectedItems.Count}" Value="1" />
145148
</MultiDataTrigger.Conditions>
146149
<MultiDataTrigger.Setters>
147150
<Setter Property="IsEnabled" Value="True"/>

0 commit comments

Comments
 (0)