@@ -21,6 +21,8 @@ public class CodeExplorerViewModel : ViewModelBase
2121    { 
2222        private  readonly  VBE  _vbe ; 
2323        private  readonly  RubberduckParserState  _state ; 
24+         private  readonly  NewUnitTestModuleCommand  _newUnitTestModuleCommand ; 
25+         private  readonly  Indenter  _indenter ; 
2426        private  readonly  ICodePaneWrapperFactory  _wrapperFactory ; 
2527        private  readonly  FindAllReferencesCommand  _findAllReferences ; 
2628
@@ -34,21 +36,22 @@ public CodeExplorerViewModel(VBE vbe,
3436        { 
3537            _vbe  =  vbe ; 
3638            _state  =  state ; 
37-             _navigateCommand  =  navigateCommand ; 
3839            _newUnitTestModuleCommand  =  newUnitTestModuleCommand ; 
3940            _indenter  =  indenter ; 
4041            _wrapperFactory  =  wrapperFactory ; 
4142            _findAllReferences  =  findAllReferences ; 
4243            _state . StateChanged  +=  ParserState_StateChanged ; 
4344            _state . ModuleStateChanged  +=  ParserState_ModuleStateChanged ; 
4445
46+             _navigateCommand  =  navigateCommand ; 
47+             _contextMenuNavigateCommand  =  new  DelegateCommand ( ExecuteContextMenuNavigateCommand ,  CanExecuteContextMenuNavigateCommand ) ; 
4548            _refreshCommand  =  new  DelegateCommand ( ExecuteRefreshCommand ,  _ =>  CanRefresh ) ; 
4649            _addTestModuleCommand  =  new  DelegateCommand ( ExecuteAddTestModuleCommand ) ; 
4750            _addStdModuleCommand  =  new  DelegateCommand ( ExecuteAddStdModuleCommand ,  CanAddModule ) ; 
4851            _addClsModuleCommand  =  new  DelegateCommand ( ExecuteAddClsModuleCommand ,  CanAddModule ) ; 
4952            _addFormCommand  =  new  DelegateCommand ( ExecuteAddFormCommand ,  CanAddModule ) ; 
50-             _indenterCommand  =  new  DelegateCommand ( ExecuteIndenterCommand ) ; 
51-             _renameCommand  =  new  DelegateCommand ( ExecuteRenameCommand ) ; 
53+             _indenterCommand  =  new  DelegateCommand ( ExecuteIndenterCommand ,  _  =>   CanExecuteIndenterCommand ) ; 
54+             _renameCommand  =  new  DelegateCommand ( ExecuteRenameCommand ,  _  =>   CanExecuteRenameCommand ) ; 
5255            _findAllReferencesCommand  =  new  DelegateCommand ( ExecuteFindAllReferencesCommand ) ; 
5356        } 
5457
@@ -77,10 +80,11 @@ public CodeExplorerViewModel(VBE vbe,
7780        public  ICommand  FindAllReferencesCommand  {  get  {  return  _findAllReferencesCommand ;  }  } 
7881
7982        private  readonly  INavigateCommand  _navigateCommand ; 
80-         private  readonly  NewUnitTestModuleCommand  _newUnitTestModuleCommand ; 
81-         private  readonly  Indenter  _indenter ; 
8283        public  ICommand  NavigateCommand  {  get  {  return  _navigateCommand ;  }  } 
8384
85+         private  readonly  ICommand  _contextMenuNavigateCommand ; 
86+         public  ICommand  ContextMenuNavigateCommand  {  get  {  return  _contextMenuNavigateCommand ;  }  } 
87+ 
8488        public  string  Description 
8589        { 
8690            get 
@@ -153,6 +157,11 @@ private bool CanAddModule(object param)
153157            return  _vbe . ActiveVBProject  !=  null ; 
154158        } 
155159
160+         private  bool  CanExecuteContextMenuNavigateCommand ( object  param ) 
161+         { 
162+             return  SelectedItem  !=  null  &&  SelectedItem . QualifiedSelection . HasValue ; 
163+         } 
164+ 
156165        public  bool  CanExecuteIndenterCommand 
157166        { 
158167            get 
@@ -329,6 +338,15 @@ private void ExecuteFindAllReferencesCommand(object obj)
329338            _findAllReferences . Execute ( GetSelectedDeclaration ( ) ) ; 
330339        } 
331340
341+         private  void  ExecuteContextMenuNavigateCommand ( object  obj ) 
342+         { 
343+             // ReSharper disable once PossibleInvalidOperationException 
344+             // CanExecute protects against this 
345+             var  arg  =  new  NavigateCodeEventArgs ( SelectedItem . QualifiedSelection . Value ) ; 
346+ 
347+             NavigateCommand . Execute ( arg ) ; 
348+         } 
349+ 
332350        private  Declaration  GetSelectedDeclaration ( ) 
333351        { 
334352            if  ( SelectedItem  is  CodeExplorerProjectViewModel ) 
0 commit comments