19
19
using Rubberduck . VBEditor . SafeComWrappers ;
20
20
using System . Windows ;
21
21
using Rubberduck . Parsing . UIContext ;
22
+ using Rubberduck . UI . UnitTesting . Commands ;
22
23
using Rubberduck . VBEditor . SafeComWrappers . Abstract ;
23
24
24
25
// ReSharper disable CanBeReplacedWithTryCastAndCheckForNull
@@ -39,9 +40,9 @@ public sealed class CodeExplorerViewModel : ViewModelBase, IDisposable
39
40
private static readonly Logger Logger = LogManager . GetCurrentClassLogger ( ) ;
40
41
41
42
public CodeExplorerViewModel (
42
- FolderHelper folderHelper ,
43
- RubberduckParserState state ,
44
- List < CommandBase > commands ,
43
+ FolderHelper folderHelper ,
44
+ RubberduckParserState state ,
45
+ RemoveCommand removeCommand ,
45
46
IConfigProvider < GeneralSettings > generalSettingsProvider ,
46
47
IConfigProvider < WindowSettings > windowSettingsProvider ,
47
48
IUiDispatcher uiDispatcher ,
@@ -64,53 +65,15 @@ public CodeExplorerViewModel(
64
65
{
65
66
_windowSettings = windowSettingsProvider . Create ( ) ;
66
67
}
67
-
68
- var reparseCommand = commands . OfType < ReparseCommand > ( ) . SingleOrDefault ( ) ;
69
-
70
- RefreshCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) ,
71
- reparseCommand == null ? ( Action < object > ) ( o => { } ) :
72
- o => reparseCommand . Execute ( o ) ,
73
- o => ! IsBusy && reparseCommand != null && reparseCommand . CanExecute ( o ) ) ;
74
-
75
- OpenCommand = commands . OfType < OpenCommand > ( ) . SingleOrDefault ( ) ;
76
- OpenDesignerCommand = commands . OfType < OpenDesignerCommand > ( ) . SingleOrDefault ( ) ;
77
-
78
- AddVBFormCommand = commands . OfType < AddVBFormCommand > ( ) . SingleOrDefault ( ) ;
79
- AddMDIFormCommand = commands . OfType < AddMDIFormCommand > ( ) . SingleOrDefault ( ) ;
80
- AddUserFormCommand = commands . OfType < AddUserFormCommand > ( ) . SingleOrDefault ( ) ;
81
- AddStdModuleCommand = commands . OfType < AddStdModuleCommand > ( ) . SingleOrDefault ( ) ;
82
- AddClassModuleCommand = commands . OfType < AddClassModuleCommand > ( ) . SingleOrDefault ( ) ;
83
- AddUserControlCommand = commands . OfType < AddUserControlCommand > ( ) . SingleOrDefault ( ) ;
84
- AddPropertyPageCommand = commands . OfType < AddPropertyPageCommand > ( ) . SingleOrDefault ( ) ;
85
- AddUserDocumentCommand = commands . OfType < AddUserDocumentCommand > ( ) . SingleOrDefault ( ) ;
86
- AddTestModuleCommand = commands . OfType < UI . CodeExplorer . Commands . AddTestModuleCommand > ( ) . SingleOrDefault ( ) ;
87
- AddTestModuleWithStubsCommand = commands . OfType < AddTestModuleWithStubsCommand > ( ) . SingleOrDefault ( ) ;
88
-
89
- SetAsStartupProjectCommand = commands . OfType < SetAsStartupProjectCommand > ( ) . SingleOrDefault ( ) ;
90
- OpenProjectPropertiesCommand = commands . OfType < OpenProjectPropertiesCommand > ( ) . SingleOrDefault ( ) ;
91
- RenameCommand = commands . OfType < RenameCommand > ( ) . SingleOrDefault ( ) ;
92
- IndenterCommand = commands . OfType < IndentCommand > ( ) . SingleOrDefault ( ) ;
93
-
94
- FindAllReferencesCommand = commands . OfType < UI . CodeExplorer . Commands . FindAllReferencesCommand > ( ) . SingleOrDefault ( ) ;
95
- FindAllImplementationsCommand = commands . OfType < UI . CodeExplorer . Commands . FindAllImplementationsCommand > ( ) . SingleOrDefault ( ) ;
96
-
97
68
CollapseAllSubnodesCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteCollapseNodes ) ;
98
69
ExpandAllSubnodesCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteExpandNodes ) ;
99
70
100
- ImportCommand = commands . OfType < ImportCommand > ( ) . SingleOrDefault ( ) ;
101
- ExportCommand = commands . OfType < ExportCommand > ( ) . SingleOrDefault ( ) ;
102
- ExportAllCommand = commands . OfType < ExportAllCommand > ( ) . SingleOrDefault ( ) ;
103
-
104
- _externalRemoveCommand = commands . OfType < RemoveCommand > ( ) . SingleOrDefault ( ) ;
71
+ _externalRemoveCommand = removeCommand ;
105
72
if ( _externalRemoveCommand != null )
106
73
{
107
74
RemoveCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteRemoveComand , _externalRemoveCommand . CanExecute ) ;
108
75
}
109
76
110
- PrintCommand = commands . OfType < PrintCommand > ( ) . SingleOrDefault ( ) ;
111
-
112
- CopyResultsCommand = commands . OfType < CopyResultsCommand > ( ) . SingleOrDefault ( ) ;
113
-
114
77
SetNameSortCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , param =>
115
78
{
116
79
if ( ( bool ) param )
@@ -189,7 +152,7 @@ public bool SortByCodeOrder
189
152
}
190
153
}
191
154
192
- public CommandBase CopyResultsCommand { get ; }
155
+ public CopyResultsCommand CopyResultsCommand { get ; }
193
156
194
157
public CommandBase SetNameSortCommand { get ; }
195
158
@@ -287,9 +250,9 @@ public string Description
287
250
}
288
251
}
289
252
290
- public bool CanExecuteIndenterCommand => IndenterCommand . CanExecute ( SelectedItem ) ;
291
- public bool CanExecuteRenameCommand => RenameCommand . CanExecute ( SelectedItem ) ;
292
- public bool CanExecuteFindAllReferencesCommand => FindAllReferencesCommand . CanExecute ( SelectedItem ) ;
253
+ public bool CanExecuteIndenterCommand => IndenterCommand ? . CanExecute ( SelectedItem ) ?? false ;
254
+ public bool CanExecuteRenameCommand => RenameCommand ? . CanExecute ( SelectedItem ) ?? false ;
255
+ public bool CanExecuteFindAllReferencesCommand => FindAllReferencesCommand ? . CanExecute ( SelectedItem ) ?? false ;
293
256
294
257
private ObservableCollection < CodeExplorerItemViewModel > _projects ;
295
258
public ObservableCollection < CodeExplorerItemViewModel > Projects
@@ -516,46 +479,46 @@ private void SwitchNodeState(CodeExplorerItemViewModel node, bool expandedState)
516
479
SwitchNodeState ( item , expandedState ) ;
517
480
}
518
481
}
482
+
519
483
520
- public CommandBase RefreshCommand { get ; }
521
-
522
- public CommandBase OpenCommand { get ; }
523
-
484
+ public ReparseCommand RefreshCommand { get ; set ; }
524
485
525
- public CommandBase AddVBFormCommand { get ; }
526
- public CommandBase AddMDIFormCommand { get ; }
527
- public CommandBase AddUserFormCommand { get ; }
528
- public CommandBase AddStdModuleCommand { get ; }
529
- public CommandBase AddClassModuleCommand { get ; }
530
- public CommandBase AddUserControlCommand { get ; }
531
- public CommandBase AddPropertyPageCommand { get ; }
532
- public CommandBase AddUserDocumentCommand { get ; }
533
- public CommandBase AddTestModuleCommand { get ; }
534
- public CommandBase AddTestModuleWithStubsCommand { get ; }
486
+ public OpenCommand OpenCommand { get ; set ; }
535
487
536
- public CommandBase OpenDesignerCommand { get ; }
537
- public CommandBase SetAsStartupProjectCommand { get ; }
538
- public CommandBase OpenProjectPropertiesCommand { get ; }
488
+ public AddVBFormCommand AddVBFormCommand { get ; set ; }
489
+ public AddMDIFormCommand AddMDIFormCommand { get ; set ; }
490
+ public AddUserFormCommand AddUserFormCommand { get ; set ; }
491
+ public AddStdModuleCommand AddStdModuleCommand { get ; set ; }
492
+ public AddClassModuleCommand AddClassModuleCommand { get ; set ; }
493
+ public AddUserControlCommand AddUserControlCommand { get ; set ; }
494
+ public AddPropertyPageCommand AddPropertyPageCommand { get ; set ; }
495
+ public AddUserDocumentCommand AddUserDocumentCommand { get ; set ; }
496
+ public AddTestModuleCommand AddTestModuleCommand { get ; set ; }
497
+ public AddTestModuleWithStubsCommand AddTestModuleWithStubsCommand { get ; set ; }
539
498
540
- public CommandBase RenameCommand { get ; }
499
+ public OpenDesignerCommand OpenDesignerCommand { get ; set ; }
500
+ public SetAsStartupProjectCommand SetAsStartupProjectCommand { get ; set ; }
501
+ public OpenProjectPropertiesCommand OpenProjectPropertiesCommand { get ; set ; }
541
502
542
- public CommandBase IndenterCommand { get ; }
503
+ public RenameCommand RenameCommand { get ; set ; }
504
+
505
+ public IndentCommand IndenterCommand { get ; set ; }
543
506
544
- public CommandBase FindAllReferencesCommand { get ; }
545
- public CommandBase FindAllImplementationsCommand { get ; }
507
+ public FindAllReferencesCommand FindAllReferencesCommand { get ; set ; }
508
+ public FindAllImplementationsCommand FindAllImplementationsCommand { get ; set ; }
546
509
547
510
public CommandBase CollapseAllSubnodesCommand { get ; }
548
511
public CommandBase ExpandAllSubnodesCommand { get ; }
549
512
550
- public CommandBase ImportCommand { get ; }
551
- public CommandBase ExportCommand { get ; }
552
- public CommandBase ExportAllCommand { get ; }
513
+ public ImportCommand ImportCommand { get ; set ; }
514
+ public ExportCommand ExportCommand { get ; set ; }
515
+ public ExportAllCommand ExportAllCommand { get ; set ; }
553
516
554
517
public CommandBase RemoveCommand { get ; }
555
518
556
- public CommandBase PrintCommand { get ; }
519
+ public PrintCommand PrintCommand { get ; set ; }
557
520
558
- private readonly CommandBase _externalRemoveCommand ;
521
+ private readonly RemoveCommand _externalRemoveCommand ;
559
522
560
523
// this is a special case--we have to reset SelectedItem to prevent a crash
561
524
private void ExecuteRemoveComand ( object param )
@@ -567,7 +530,7 @@ private void ExecuteRemoveComand(object param)
567
530
_externalRemoveCommand . Execute ( param ) ;
568
531
}
569
532
570
- private bool CanExecuteExportAllCommand => ExportAllCommand . CanExecute ( SelectedItem ) ;
533
+ private bool CanExecuteExportAllCommand => ExportAllCommand ? . CanExecute ( SelectedItem ) ?? false ;
571
534
572
535
public Visibility ExportVisibility => _vbe . Kind == VBEKind . Standalone || CanExecuteExportAllCommand ? Visibility . Collapsed : Visibility . Visible ;
573
536
0 commit comments