diff --git a/RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerCustomFolderViewModel.cs b/RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerCustomFolderViewModel.cs index 2b59367af7..ebcac8b37c 100644 --- a/RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerCustomFolderViewModel.cs +++ b/RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerCustomFolderViewModel.cs @@ -11,6 +11,7 @@ namespace Rubberduck.Navigation.CodeExplorer public class CodeExplorerCustomFolderViewModel : CodeExplorerItemViewModel { private readonly string _name; + private readonly string _folderAttribute; private static readonly DeclarationType[] ComponentTypes = { DeclarationType.ClassModule, @@ -19,9 +20,10 @@ public class CodeExplorerCustomFolderViewModel : CodeExplorerItemViewModel DeclarationType.UserForm, }; - public CodeExplorerCustomFolderViewModel(string name, IEnumerable declarations) + public CodeExplorerCustomFolderViewModel(string name, string fullPath, IEnumerable declarations) { - _name = name; + _name = name.Replace("\"", string.Empty); + _folderAttribute = string.Format("@Folder(\"{0}\")", fullPath.Replace("\"", string.Empty)); _collapsedIcon = GetImageSource(resx.folder_horizontal); _expandedIcon = GetImageSource(resx.folder_horizontal_open); @@ -48,6 +50,8 @@ public CodeExplorerCustomFolderViewModel(string name, IEnumerable d } } + public string FolderAttribute { get { return _folderAttribute; } } + public override string Name { get { return _name; } } public override string NameWithSignature { get { return Name; } } diff --git a/RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerProjectViewModel.cs b/RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerProjectViewModel.cs index 722570cfbb..26e83f29e8 100644 --- a/RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerProjectViewModel.cs +++ b/RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerProjectViewModel.cs @@ -43,7 +43,7 @@ public CodeExplorerProjectViewModel(Declaration declaration, IEnumerable FindFolders(IEnumerable declarations, char delimiter) { - var root = new CodeExplorerCustomFolderViewModel(string.Empty, new List()); + var root = new CodeExplorerCustomFolderViewModel(string.Empty, string.Empty, new List()); var items = declarations.ToList(); var folders = items.Where(item => ComponentTypes.Contains(item.DeclarationType)) @@ -68,7 +68,7 @@ private static IEnumerable FindFolders(IEnumerable ComponentTypes.Contains(item.DeclarationType) && item.CustomFolder == currentPath).ToList(); - next = new CodeExplorerCustomFolderViewModel(part, items.Where(item => + next = new CodeExplorerCustomFolderViewModel(part, currentPath, items.Where(item => parents.Contains(item) || parents.Any(parent => (item.ParentDeclaration != null && item.ParentDeclaration.Equals(parent)) || item.ComponentName == parent.ComponentName))); node.AddChild(next); diff --git a/RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs b/RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs index 5dba572a25..07de4e4508 100644 --- a/RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs +++ b/RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs @@ -21,6 +21,8 @@ public class CodeExplorerViewModel : ViewModelBase { private readonly VBE _vbe; private readonly RubberduckParserState _state; + private readonly NewUnitTestModuleCommand _newUnitTestModuleCommand; + private readonly Indenter _indenter; private readonly ICodePaneWrapperFactory _wrapperFactory; private readonly FindAllReferencesCommand _findAllReferences; @@ -34,7 +36,6 @@ public CodeExplorerViewModel(VBE vbe, { _vbe = vbe; _state = state; - _navigateCommand = navigateCommand; _newUnitTestModuleCommand = newUnitTestModuleCommand; _indenter = indenter; _wrapperFactory = wrapperFactory; @@ -42,13 +43,15 @@ public CodeExplorerViewModel(VBE vbe, _state.StateChanged += ParserState_StateChanged; _state.ModuleStateChanged += ParserState_ModuleStateChanged; - _refreshCommand = new DelegateCommand(ExecuteRefreshCommand); + _navigateCommand = navigateCommand; + _contextMenuNavigateCommand = new DelegateCommand(ExecuteContextMenuNavigateCommand, CanExecuteContextMenuNavigateCommand); + _refreshCommand = new DelegateCommand(ExecuteRefreshCommand, _ => CanRefresh); _addTestModuleCommand = new DelegateCommand(ExecuteAddTestModuleCommand); _addStdModuleCommand = new DelegateCommand(ExecuteAddStdModuleCommand, CanAddModule); _addClsModuleCommand = new DelegateCommand(ExecuteAddClsModuleCommand, CanAddModule); _addFormCommand = new DelegateCommand(ExecuteAddFormCommand, CanAddModule); - _indenterCommand = new DelegateCommand(ExecuteIndenterCommand); - _renameCommand = new DelegateCommand(ExecuteRenameCommand); + _indenterCommand = new DelegateCommand(ExecuteIndenterCommand, _ => CanExecuteIndenterCommand); + _renameCommand = new DelegateCommand(ExecuteRenameCommand, _ => CanExecuteRenameCommand); _findAllReferencesCommand = new DelegateCommand(ExecuteFindAllReferencesCommand); } @@ -77,10 +80,39 @@ public CodeExplorerViewModel(VBE vbe, public ICommand FindAllReferencesCommand { get { return _findAllReferencesCommand; } } private readonly INavigateCommand _navigateCommand; - private readonly NewUnitTestModuleCommand _newUnitTestModuleCommand; - private readonly Indenter _indenter; public ICommand NavigateCommand { get { return _navigateCommand; } } + private readonly ICommand _contextMenuNavigateCommand; + public ICommand ContextMenuNavigateCommand { get { return _contextMenuNavigateCommand; } } + + public string Description + { + get + { + if (SelectedItem is CodeExplorerProjectViewModel) + { + return ((CodeExplorerProjectViewModel)SelectedItem).Declaration.DescriptionString; + } + + if (SelectedItem is CodeExplorerComponentViewModel) + { + return ((CodeExplorerComponentViewModel)SelectedItem).Declaration.DescriptionString; + } + + if (SelectedItem is CodeExplorerMemberViewModel) + { + return ((CodeExplorerMemberViewModel)SelectedItem).Declaration.DescriptionString; + } + + if (SelectedItem is CodeExplorerCustomFolderViewModel) + { + return ((CodeExplorerCustomFolderViewModel)SelectedItem).FolderAttribute; + } + + return string.Empty; + } + } + private CodeExplorerItemViewModel _selectedItem; public CodeExplorerItemViewModel SelectedItem { @@ -92,6 +124,7 @@ public CodeExplorerItemViewModel SelectedItem OnPropertyChanged("CanExecuteIndenterCommand"); OnPropertyChanged("CanExecuteRenameCommand"); OnPropertyChanged("CanExecuteFindAllReferencesCommand"); + OnPropertyChanged("Description"); } } @@ -124,6 +157,11 @@ private bool CanAddModule(object param) return _vbe.ActiveVBProject != null; } + private bool CanExecuteContextMenuNavigateCommand(object param) + { + return SelectedItem != null && SelectedItem.QualifiedSelection.HasValue; + } + public bool CanExecuteIndenterCommand { get @@ -267,21 +305,20 @@ private void ExecuteAddFormCommand(object param) private void ExecuteIndenterCommand(object param) { + if (!SelectedItem.QualifiedSelection.HasValue) + { + return; + } + Debug.WriteLine("CodeExplorerViewModel.IndenterCommand"); if (SelectedItem is CodeExplorerProjectViewModel) { - if (SelectedItem.QualifiedSelection.HasValue) - { - _indenter.Indent(SelectedItem.QualifiedSelection.Value.QualifiedName.Project); - } + _indenter.Indent(SelectedItem.QualifiedSelection.Value.QualifiedName.Project); } if (SelectedItem is CodeExplorerComponentViewModel) { - if (SelectedItem.QualifiedSelection.HasValue) - { - _indenter.Indent(SelectedItem.QualifiedSelection.Value.QualifiedName.Component); - } + _indenter.Indent(SelectedItem.QualifiedSelection.Value.QualifiedName.Component); } } @@ -301,6 +338,15 @@ private void ExecuteFindAllReferencesCommand(object obj) _findAllReferences.Execute(GetSelectedDeclaration()); } + private void ExecuteContextMenuNavigateCommand(object obj) + { + // ReSharper disable once PossibleInvalidOperationException + // CanExecute protects against this + var arg = new NavigateCodeEventArgs(SelectedItem.QualifiedSelection.Value); + + NavigateCommand.Execute(arg); + } + private Declaration GetSelectedDeclaration() { if (SelectedItem is CodeExplorerProjectViewModel) diff --git a/RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml b/RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml index 5abd2b04a2..b302248e6a 100644 --- a/RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml +++ b/RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml @@ -10,14 +10,14 @@ xmlns:themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" ResxExtension.DefaultResxName="Rubberduck.UI.RubberduckUI" Language="{UICulture}" + Name="CodeExplorer" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" d:DataContext="{d:DesignInstance codeExplorer:CodeExplorerViewModel}"> - - -