예제 #1
0
        // This is the current key binding for the command being overridden by an action
        // By definition, this is the VS key binding (because we're overriding an existing
        // VS command and using its key bindings)
        public override ActionShortcut GetOverriddenVsShortcut(IActionDefWithId def)
        {
            if (dte == null)
            {
                return(null);
            }

            // Not sure if we're ever called on a non-UI thread, but better safe than sorry
            if (!threading.Dispatcher.CheckAccess())
            {
                return(null);
            }

            // def.CommandId is the command ID of the ReSharper action. We want the command ID
            // of the VS command it's overriding
            var commandId = vsActionDefs.TryGetOverriddenCommandIds(def).FirstOrDefault();

            if (commandId == null)
            {
                return(null);
            }

            var command = VsCommandHelpers.TryGetVsCommandAutomationObject(commandId, dte);

            if (command == null)
            {
                return(null);
            }

            return(GetVsShortcut(command));
        }
        private void SetShortcuts(Shortcut shortcut, IActionDefWithId def)
        {
            const bool showSecondarySchemeIfSame = false;

            SetGivenShortcuts(shortcut, def, showSecondarySchemeIfSame);
            SetVsOverriddenShortcuts(shortcut, def, showSecondarySchemeIfSame);
            SetWellKnownShortcuts(shortcut, def, showSecondarySchemeIfSame);
        }
        private void SetGivenShortcuts(Shortcut shortcut, IActionDefWithId def, bool showSecondarySchemeIfSame)
        {
            shortcut.VsShortcut       = GetFirstShortcutSequence(def.VsShortcuts);
            shortcut.IntellijShortcut = GetFirstShortcutSequence(def.IdeaShortcuts);

            if (HasSameShortcuts(shortcut) && !showSecondarySchemeIfSame)
            {
                shortcut.IntellijShortcut = null;
            }
        }
        private void SetVsOverriddenShortcuts(Shortcut shortcut, IActionDefWithId def, bool showSecondarySchemeIfSame)
        {
            // If we don't have any VS shortcuts, look to see if the action is an override of a
            // VS command, and get the current key binding for that command
            if (!shortcut.HasVsShortcuts)
            {
                shortcut.VsShortcut = GetShortcutSequence(overriddenShortcutFinder.GetOverriddenVsShortcut(def));
            }

            if (HasSameShortcuts(shortcut) && !showSecondarySchemeIfSame)
            {
                shortcut.IntellijShortcut = null;
            }
        }
        private void SetWellKnownShortcuts(Shortcut shortcut, IActionDefWithId def,
                                           bool showSecondarySchemeIfSame)
        {
            switch (def.ActionId)
            {
            // The Escape action doesn't have a bound shortcut, or a VS override
            case "Escape":
                shortcut.VsShortcut = GetShortcutSequence("Escape");
                break;

            // Only happens when we're tabbing around hotspots in Live Templates. Useful to show
            case "TextControl.Tab":
                shortcut.VsShortcut = GetShortcutSequence("Tab");
                break;

            case "TextControl.Enter":
                shortcut.VsShortcut = GetShortcutSequence("Enter");
                break;

            // The shortcuts for the overridden VS "go to" commands come from the current
            // binding, but if we're in the IntelliJ binding, they get removed, so we have
            // to hard code them.
            case "GotoDeclaration":
                if (shortcut.VsShortcut == null)
                {
                    shortcut.VsShortcut = GetShortcutSequence("F12");
                }
                break;

            case "GotoImplementation":
                if (shortcut.VsShortcut == null)
                {
                    shortcut.VsShortcut = GetShortcutSequence("Control+F12");
                }
                break;
            }

            if (!shortcut.HasIntellijShortcuts && showSecondarySchemeIfSame)
            {
                shortcut.IntellijShortcut = shortcut.VsShortcut;
            }
        }
        private string GetPath(IActionDefWithId def)
        {
            var path = actionPresentationHelper.GetPathPresentationToRoot(def);

            return(!string.IsNullOrEmpty(path) ? MnemonicStore.RemoveMnemonicMark(path) + " \u2192 " : string.Empty);
        }
 // This is the current key binding for the command being overridden by an action
 // By definition, this is the VS key binding (because we're overriding an existing
 // VS command and using its key bindings)
 public virtual ActionShortcut GetOverriddenVsShortcut(IActionDefWithId def)
 {
     return(null);
 }
 private static string GetCaption(IActionDefWithId action, IDataContext dataContext, IActionManager actionManager)
 {
     return(actionManager.Handlers.Evaluate(action, dataContext).Text);
 }