1+ using NETworkManager . Localization . Resources ;
2+ using NETworkManager . Models ;
13using NETworkManager . Models . Firewall ;
24using NETworkManager . Utilities ;
35using System ;
@@ -12,21 +14,23 @@ namespace NETworkManager.ViewModels;
1214public class FirewallRuleViewModel : ViewModelBase
1315{
1416 /// <summary>
15- /// Creates a new instance of <see cref="FirewallRuleViewModel"/> for adding or
16- /// editing a firewall rule.
17+ /// Creates a new instance of <see cref="FirewallRuleViewModel"/> for adding, editing or
18+ /// copying a firewall rule.
1719 /// </summary>
1820 /// <param name="okCommand">OK command to save the rule.</param>
1921 /// <param name="cancelHandler">Cancel command to discard changes.</param>
20- /// <param name="entry">Existing rule to edit; <see langword="null"/> to add a new rule.</param>
22+ /// <param name="entry">Existing rule to edit or copy. Ignored when adding a new rule.</param>
23+ /// <param name="mode">Mode of the dialog (add, edit or copy).</param>
2124 public FirewallRuleViewModel ( Action < FirewallRuleViewModel > okCommand ,
22- Action < FirewallRuleViewModel > cancelHandler , FirewallRule entry = null )
25+ Action < FirewallRuleViewModel > cancelHandler , FirewallRule entry = null , EditMode mode = EditMode . Add )
2326 {
2427 OKCommand = new RelayCommand ( _ => okCommand ( this ) ) ;
2528 CancelCommand = new RelayCommand ( _ => cancelHandler ( this ) ) ;
2629
27- Entry = entry ;
30+ Mode = mode ;
31+ Entry = mode == EditMode . Add ? null : entry ;
2832
29- if ( entry == null )
33+ if ( Entry == null )
3034 {
3135 IsEnabled = true ;
3236 Direction = FirewallRuleDirection . Inbound ;
@@ -40,6 +44,10 @@ public FirewallRuleViewModel(Action<FirewallRuleViewModel> okCommand,
4044 else
4145 {
4246 Name = entry . Name ;
47+
48+ if ( mode == EditMode . Copy )
49+ Name += " - " + Strings . CopyNoun ;
50+
4351 IsEnabled = entry . IsEnabled ;
4452 Description = entry . Description ?? string . Empty ;
4553 Direction = entry . Direction ;
@@ -68,7 +76,13 @@ public FirewallRuleViewModel(Action<FirewallRuleViewModel> okCommand,
6876 public ICommand CancelCommand { get ; }
6977
7078 /// <summary>
71- /// The original firewall rule being edited, or <see langword="null"/> when adding a new rule.
79+ /// Mode of the dialog (add, edit or copy).
80+ /// </summary>
81+ public EditMode Mode { get ; }
82+
83+ /// <summary>
84+ /// The original firewall rule being edited (or the source rule when copying),
85+ /// or <see langword="null"/> when adding a new rule.
7286 /// </summary>
7387 public FirewallRule Entry { get ; }
7488
0 commit comments