diff --git a/.gitignore b/.gitignore index 267c67d..2e785c9 100644 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ _dotTrace* /**/.idea */**/Packages /**/.intellijPlatform + +# NuGet tools +.nuget/ diff --git a/CHANGELOG.md b/CHANGELOG.md index f958457..2198ecb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Changelog All notable changes to this project will be documented in this file. +## 26.04.XXXX +- Fix issue: register `GoToHandlerAction` as a VS/ReSharper keyboard-assignable action with a default shortcut of `Alt+H`. Users can now find it in Tools > Options > Environment > Keyboard as `GoToHandlerAction`. + ## 26.03.07XX - Fix issue #93: rename `GoToHandlrAction` kotlin file to `GoToHandlerAction` since this is what is referenced in the plugin.xml file. diff --git a/src/dotnet/MediatorPlugin/Actions/GoToHandlerNavigationAction.cs b/src/dotnet/MediatorPlugin/Actions/GoToHandlerNavigationAction.cs new file mode 100644 index 0000000..f39e2dc --- /dev/null +++ b/src/dotnet/MediatorPlugin/Actions/GoToHandlerNavigationAction.cs @@ -0,0 +1,52 @@ +using JetBrains.Application.DataContext; +using JetBrains.Application.Shortcuts.ShortcutManager; +using JetBrains.Application.UI.Actions; +using JetBrains.Application.UI.ActionsRevised.Menu; +using JetBrains.Diagnostics; +using JetBrains.ProjectModel; +using JetBrains.ReSharper.Feature.Services.Navigation.ContextNavigation; +using JetBrains.ReSharper.Psi.Tree; +using ReSharper.MediatorPlugin.Diagnostics; +using ReSharper.MediatorPlugin.Services.Find; +using ReSharper.MediatorPlugin.Services.Navigation; + +namespace ReSharper.MediatorPlugin.Actions; + +#pragma warning disable CS0612 +[Action("GoToHandlerAction", "Go to Handler", ShortcutScope = ShortcutScope.TextEditor, DefaultShortcutText = "Alt+H")] +#pragma warning restore CS0612 +public class GoToHandlerNavigationAction : IExecutableAction +{ + private readonly IHandlerSelector _handlerSelector = new HandlerSelector(); + + public bool Update(IDataContext context, ActionPresentation presentation, DelegateUpdate nextUpdate) + { + var selectedTreeNode = context.GetSelectedTreeNode(); + + if (selectedTreeNode is not IIdentifier identifier) + return nextUpdate.Invoke(); + + return _handlerSelector.IsMediatorRequestSupported(identifier); + } + + public void Execute(IDataContext context, DelegateExecute nextExecute) + { + Logger.Instance.Log(LoggingLevel.INFO, "GoToHandlerNavigationAction.Execute called"); + + var solution = context.GetComponent(); + var selectedTreeNode = context.GetSelectedTreeNode(); + + if (selectedTreeNode is not IIdentifier) + { + Logger.Instance.Log(LoggingLevel.VERBOSE, "Selected element is not an identifier"); + return; + } + + _handlerSelector.NavigateToHandler + ( + solution, + selectedTreeNode, + new DataContextNavigationOptionsFactory(context) + ); + } +}