Skip to content

Commit fadf3e7

Browse files
committed
Navigate command.
1 parent 17d4cc3 commit fadf3e7

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,17 @@
7676
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Rename}"
7777
Command="{Binding RenameCommand}" />
7878
<Separator />
79+
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=Navigate}"
80+
Command="{Binding ContextMenuNavigateCommand}" />
81+
<Separator />
7982
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_ContextMenu_AddTestModuleText}"
8083
Command="{Binding AddTestModuleCommand}" />
81-
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_ContextMenu_AddStdModuleText}" Command="{Binding AddStdModuleCommand}" />
82-
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_ContextMenu_AddClassModuleText}" Command="{Binding AddClsModuleCommand}" />
83-
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_ContextMenu_AddFormText}" Command="{Binding AddFormCommand}" />
84+
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_ContextMenu_AddStdModuleText}"
85+
Command="{Binding AddStdModuleCommand}" />
86+
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_ContextMenu_AddClassModuleText}"
87+
Command="{Binding AddClsModuleCommand}" />
88+
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_ContextMenu_AddFormText}"
89+
Command="{Binding AddFormCommand}" />
8490
</ContextMenu>
8591
</Setter.Value>
8692
</Setter>

0 commit comments

Comments
 (0)