From 456eae64db32da636f5ea53b15771cf54fbb63b6 Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Tue, 3 Apr 2012 14:57:28 +0400 Subject: [PATCH] OC-3524 + get context help shortcut from current keymap --- .../openapi/actionSystem/CommonShortcuts.java | 4 +++ .../intellij/openapi/ui/DialogWrapper.java | 35 ++++++++++++------- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java index 1a565dc95af4..415bd600254e 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java @@ -101,4 +101,8 @@ public class CommonShortcuts { public static ShortcutSet getFind() { return new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_FIND)); } + + public static ShortcutSet getContextHelp() { + return new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_CONTEXT_HELP)); + } } diff --git a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java index 63d81832f492..5a1379b16642 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/DialogWrapper.java @@ -20,10 +20,7 @@ import com.intellij.ide.ui.UISettings; import com.intellij.idea.ActionsBundle; import com.intellij.openapi.Disposable; import com.intellij.openapi.MnemonicHelper; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.CustomShortcutSet; -import com.intellij.openapi.actionSystem.MacOtherAction; +import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationInfo; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; @@ -1416,17 +1413,29 @@ public abstract class DialogWrapper { } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); - getRootPane().registerKeyboardAction(new ActionListener() { - public void actionPerformed(ActionEvent e) { - doHelpAction(); + if (ApplicationInfo.contextHelpAvailable()) { + ShortcutSet help = CommonShortcuts.getContextHelp(); + for (Shortcut shortcut : help.getShortcuts()) { + if (shortcut instanceof KeyboardShortcut) { + KeyboardShortcut ks = (KeyboardShortcut)shortcut; + KeyStroke first = ks.getFirstKeyStroke(); + KeyStroke second = ks.getSecondKeyStroke(); + if (second == null) { + getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + doHelpAction(); + } + }, first, JComponent.WHEN_IN_FOCUSED_WINDOW); + } + } } - }, KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); - getRootPane().registerKeyboardAction(new ActionListener() { - public void actionPerformed(ActionEvent e) { - doHelpAction(); - } - }, KeyStroke.getKeyStroke(KeyEvent.VK_HELP, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); + getRootPane().registerKeyboardAction(new ActionListener() { + public void actionPerformed(ActionEvent e) { + doHelpAction(); + } + }, KeyStroke.getKeyStroke(KeyEvent.VK_HELP, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); + } if (myButtons != null) { getRootPane().registerKeyboardAction(new AbstractAction() {