1919using Rubberduck . VBEditor . SafeComWrappers ;
2020using System . Windows ;
2121using Rubberduck . Parsing . UIContext ;
22+ using Rubberduck . UI . UnitTesting . Commands ;
2223using Rubberduck . VBEditor . SafeComWrappers . Abstract ;
2324
2425// ReSharper disable CanBeReplacedWithTryCastAndCheckForNull
@@ -39,9 +40,9 @@ public sealed class CodeExplorerViewModel : ViewModelBase, IDisposable
3940 private static readonly Logger Logger = LogManager . GetCurrentClassLogger ( ) ;
4041
4142 public CodeExplorerViewModel (
42- FolderHelper folderHelper ,
43- RubberduckParserState state ,
44- List < CommandBase > commands ,
43+ FolderHelper folderHelper ,
44+ RubberduckParserState state ,
45+ RemoveCommand removeCommand ,
4546 IConfigProvider < GeneralSettings > generalSettingsProvider ,
4647 IConfigProvider < WindowSettings > windowSettingsProvider ,
4748 IUiDispatcher uiDispatcher ,
@@ -64,53 +65,15 @@ public CodeExplorerViewModel(
6465 {
6566 _windowSettings = windowSettingsProvider . Create ( ) ;
6667 }
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-
9768 CollapseAllSubnodesCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteCollapseNodes ) ;
9869 ExpandAllSubnodesCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteExpandNodes ) ;
9970
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 ;
10572 if ( _externalRemoveCommand != null )
10673 {
10774 RemoveCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , ExecuteRemoveComand , _externalRemoveCommand . CanExecute ) ;
10875 }
10976
110- PrintCommand = commands . OfType < PrintCommand > ( ) . SingleOrDefault ( ) ;
111-
112- CopyResultsCommand = commands . OfType < CopyResultsCommand > ( ) . SingleOrDefault ( ) ;
113-
11477 SetNameSortCommand = new DelegateCommand ( LogManager . GetCurrentClassLogger ( ) , param =>
11578 {
11679 if ( ( bool ) param )
@@ -189,7 +152,7 @@ public bool SortByCodeOrder
189152 }
190153 }
191154
192- public CommandBase CopyResultsCommand { get ; }
155+ public CopyResultsCommand CopyResultsCommand { get ; }
193156
194157 public CommandBase SetNameSortCommand { get ; }
195158
@@ -287,9 +250,9 @@ public string Description
287250 }
288251 }
289252
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 ;
293256
294257 private ObservableCollection < CodeExplorerItemViewModel > _projects ;
295258 public ObservableCollection < CodeExplorerItemViewModel > Projects
@@ -516,46 +479,46 @@ private void SwitchNodeState(CodeExplorerItemViewModel node, bool expandedState)
516479 SwitchNodeState ( item , expandedState ) ;
517480 }
518481 }
482+
519483
520- public CommandBase RefreshCommand { get ; }
521-
522- public CommandBase OpenCommand { get ; }
523-
484+ public ReparseCommand RefreshCommand { get ; set ; }
524485
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 ; }
535487
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 ; }
539498
540- public CommandBase RenameCommand { get ; }
499+ public OpenDesignerCommand OpenDesignerCommand { get ; set ; }
500+ public SetAsStartupProjectCommand SetAsStartupProjectCommand { get ; set ; }
501+ public OpenProjectPropertiesCommand OpenProjectPropertiesCommand { get ; set ; }
541502
542- public CommandBase IndenterCommand { get ; }
503+ public RenameCommand RenameCommand { get ; set ; }
504+
505+ public IndentCommand IndenterCommand { get ; set ; }
543506
544- public CommandBase FindAllReferencesCommand { get ; }
545- public CommandBase FindAllImplementationsCommand { get ; }
507+ public FindAllReferencesCommand FindAllReferencesCommand { get ; set ; }
508+ public FindAllImplementationsCommand FindAllImplementationsCommand { get ; set ; }
546509
547510 public CommandBase CollapseAllSubnodesCommand { get ; }
548511 public CommandBase ExpandAllSubnodesCommand { get ; }
549512
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 ; }
553516
554517 public CommandBase RemoveCommand { get ; }
555518
556- public CommandBase PrintCommand { get ; }
519+ public PrintCommand PrintCommand { get ; set ; }
557520
558- private readonly CommandBase _externalRemoveCommand ;
521+ private readonly RemoveCommand _externalRemoveCommand ;
559522
560523 // this is a special case--we have to reset SelectedItem to prevent a crash
561524 private void ExecuteRemoveComand ( object param )
@@ -567,7 +530,7 @@ private void ExecuteRemoveComand(object param)
567530 _externalRemoveCommand . Execute ( param ) ;
568531 }
569532
570- private bool CanExecuteExportAllCommand => ExportAllCommand . CanExecute ( SelectedItem ) ;
533+ private bool CanExecuteExportAllCommand => ExportAllCommand ? . CanExecute ( SelectedItem ) ?? false ;
571534
572535 public Visibility ExportVisibility => _vbe . Kind == VBEKind . Standalone || CanExecuteExportAllCommand ? Visibility . Collapsed : Visibility . Visible ;
573536
0 commit comments