Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add references command to context menus.
- Loading branch information
Showing
11 changed files
with
176 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 0 additions & 67 deletions
67
Rubberduck.Core/UI/CodeExplorer/Commands/AddRemoveReferencesCommand.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using System.Runtime.InteropServices; | ||
using NLog; | ||
using Rubberduck.AddRemoveReferences; | ||
using Rubberduck.Navigation.CodeExplorer; | ||
using Rubberduck.Parsing.Symbols; | ||
using Rubberduck.Parsing.VBA; | ||
using Rubberduck.UI.AddRemoveReferences; | ||
using Rubberduck.VBEditor.SafeComWrappers.Abstract; | ||
|
||
namespace Rubberduck.UI.Command | ||
{ | ||
[ComVisible(false)] | ||
public class AddRemoveReferencesCommand : CommandBase | ||
{ | ||
private readonly IVBE _vbe; | ||
private readonly RubberduckParserState _state; | ||
private readonly IAddRemoveReferencesPresenterFactory _factory; | ||
private readonly IReferenceReconciler _reconciler; | ||
|
||
public AddRemoveReferencesCommand(IVBE vbe, | ||
RubberduckParserState state, | ||
IAddRemoveReferencesPresenterFactory factory, | ||
IReferenceReconciler reconciler) | ||
: base(LogManager.GetCurrentClassLogger()) | ||
{ | ||
_vbe = vbe; | ||
_state = state; | ||
_factory = factory; | ||
_reconciler = reconciler; | ||
} | ||
|
||
protected override void OnExecute(object parameter) | ||
{ | ||
if (_state.Status != ParserState.Ready) | ||
{ | ||
return; | ||
} | ||
|
||
var declaration = parameter is CodeExplorerItemViewModel explorerItem | ||
? GetDeclaration(explorerItem) | ||
: GetDeclaration(); | ||
|
||
if (!(Declaration.GetProjectParent(declaration) is ProjectDeclaration project)) | ||
{ | ||
return; | ||
} | ||
|
||
var dialog = _factory.Create(project); | ||
var model = dialog.Show(); | ||
if (model is null) | ||
{ | ||
return; | ||
} | ||
|
||
_reconciler.ReconcileReferences(model); | ||
_state.OnParseRequested(this); | ||
} | ||
|
||
protected override bool EvaluateCanExecute(object parameter) | ||
{ | ||
if (_state.Status != ParserState.Ready) | ||
{ | ||
return false; | ||
} | ||
|
||
if (parameter is CodeExplorerItemViewModel explorerNode) | ||
{ | ||
return GetDeclaration(explorerNode) is ProjectDeclaration; | ||
} | ||
|
||
using (var project = _vbe.ActiveVBProject) | ||
{ | ||
return !(project is null); | ||
} | ||
} | ||
|
||
private Declaration GetDeclaration(CodeExplorerItemViewModel node) | ||
{ | ||
while (node != null && !(node is ICodeExplorerDeclarationViewModel)) | ||
{ | ||
node = node.Parent; | ||
} | ||
|
||
return (node as ICodeExplorerDeclarationViewModel)?.Declaration; | ||
} | ||
|
||
private Declaration GetDeclaration() | ||
{ | ||
using (var project = _vbe.ActiveVBProject) | ||
{ | ||
if (project is null || project.IsWrappingNullReference) | ||
{ | ||
return null; | ||
} | ||
return _state.DeclarationFinder.FindProject(project.Name); | ||
} | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
Rubberduck.Core/UI/Command/MenuItems/AddRemoveReferencesCommandMenuItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using Rubberduck.Parsing.VBA; | ||
using Rubberduck.UI.Command.MenuItems.ParentMenus; | ||
|
||
namespace Rubberduck.UI.Command.MenuItems | ||
{ | ||
public abstract class AddRemoveReferencesCommandMenuItemBase : CommandMenuItemBase | ||
{ | ||
protected AddRemoveReferencesCommandMenuItemBase(AddRemoveReferencesCommand command) : base(command) { } | ||
|
||
public override string Key => "AddRemoveReferences"; | ||
public override bool BeginGroup => true; | ||
|
||
public override bool EvaluateCanExecute(RubberduckParserState state) | ||
{ | ||
return state != null && Command.CanExecute(null); | ||
} | ||
} | ||
|
||
public class ToolMenuAddRemoveReferencesCommandMenuItem : AddRemoveReferencesCommandMenuItemBase | ||
{ | ||
public override int DisplayOrder => (int)ToolsMenuItemDisplayOrder.AddRemoveReferences; | ||
|
||
public ToolMenuAddRemoveReferencesCommandMenuItem(AddRemoveReferencesCommand command) : base(command) { } | ||
} | ||
|
||
public class ProjectExplorerAddRemoveReferencesCommandMenuItem : AddRemoveReferencesCommandMenuItemBase | ||
{ | ||
public override int DisplayOrder => (int)RefactoringsMenuItemDisplayOrder.AddRemoveReferences; | ||
|
||
public ProjectExplorerAddRemoveReferencesCommandMenuItem(AddRemoveReferencesCommand command) : base(command) { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,5 +18,6 @@ public enum ToolsMenuItemDisplayOrder | |
ToDoExplorer, | ||
RegexAssistant, | ||
ExportAll, | ||
AddRemoveReferences | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters