Example usage for com.intellij.openapi.keymap KeymapUtil getShortcutText

List of usage examples for com.intellij.openapi.keymap KeymapUtil getShortcutText

Introduction

In this page you can find the example usage for com.intellij.openapi.keymap KeymapUtil getShortcutText.

Prototype

@NotNull
    public static String getShortcutText(@NotNull Shortcut shortcut) 

Source Link

Usage

From source file:be.janickreynders.shortcuttranslator.ShortcutTranslatorDialog.java

License:Open Source License

private Set<ShortcutDescription> translateShortcut(KeyStroke stroke, Keymap sourceKeymap, Keymap targetKeymap) {
    Set<ShortcutDescription> descriptions = new LinkedHashSet<ShortcutDescription>();
    String[] actionIds = sourceKeymap.getActionIds(stroke);

    for (String actionId : actionIds) {
        Shortcut[] shortcuts = targetKeymap.getShortcuts(actionId);
        for (Shortcut shortcut : shortcuts) {
            descriptions.add(new ShortcutDescription(KeymapUtil.getShortcutText(shortcut), actionId,
                    getAction(actionId)));
        }/*from  w  ww. j a  v  a2  s  .  co  m*/
    }
    return descriptions;
}

From source file:com.android.tools.idea.fd.actions.HotswapAction.java

License:Apache License

@Nullable
private static String getShortcutText() {
    Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap();
    Shortcut[] shortcuts = activeKeymap.getShortcuts("Android.HotswapChanges");
    return shortcuts.length > 0 ? " (" + KeymapUtil.getShortcutText(shortcuts[0]) + ") " : "";
}

From source file:com.android.tools.idea.fd.InstantRunNotificationProvider.java

License:Apache License

@NotNull
private static String getRestartActivityShortcutText() {
    if (ApplicationManager.getApplication() == null || ApplicationManager.getApplication().isUnitTestMode()) {
        return "";
    }//from   w ww.ja  va2s  .  c om

    Shortcut[] shortcuts = ActionManager.getInstance().getAction("Android.RestartActivity").getShortcutSet()
            .getShortcuts();
    return shortcuts.length > 0 ? " (" + KeymapUtil.getShortcutText(shortcuts[0]) + ") " : "";
}

From source file:com.antoine.ideaplugin.greenrobot.ShowUsagesAction.java

License:Apache License

@NotNull
private InplaceButton createSettingsButton(@NotNull final FindUsagesHandler handler,
        @NotNull final RelativePoint popupPosition, final Editor editor, final int maxUsages,
        @NotNull final Runnable cancelAction) {
    String shortcutText = "";
    KeyboardShortcut shortcut = UsageViewImpl.getShowUsagesWithSettingsShortcut();
    if (shortcut != null) {
        shortcutText = "(" + KeymapUtil.getShortcutText(shortcut) + ")";
    }//from   w  ww  .  jav  a  2s . c om
    return new InplaceButton("Settings..." + shortcutText, AllIcons.General.Settings, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    showDialogAndFindUsages(handler, popupPosition, editor, maxUsages);
                }
            });
            cancelAction.run();
        }
    });
}

From source file:com.antoine.ideaplugin.greenrobot.ShowUsagesAction.java

License:Apache License

@Nullable
private static String getSecondInvocationTitle(@NotNull FindUsagesOptions options,
        @NotNull FindUsagesHandler handler) {
    if (getShowUsagesShortcut() != null) {
        GlobalSearchScope maximalScope = FindUsagesManager.getMaximalScope(handler);
        if (!notNullizeScope(options, handler.getProject()).equals(maximalScope)) {
            return "Press " + KeymapUtil.getShortcutText(getShowUsagesShortcut()) + " again to search in "
                    + maximalScope.getDisplayName();
        }/*from  w  w  w .j a va2s  . c om*/
    }
    return null;
}

From source file:com.codeflections.typengo.CommandInputForm.java

License:Open Source License

private void updatePopup(@NotNull JPopupMenu popupMenu, @NotNull String typedStr) {
    popupMenu.removeAll();/*ww w  .j av  a2s. com*/
    Collection<ActionInfo> foundActions = ActionFinder.findActions(typedStr);
    EditorColorsScheme currScheme = EditorColorsManager.getInstance().getGlobalScheme();
    Color backgroundColor = currScheme.getColor(EditorColors.NOTIFICATION_BACKGROUND);
    Color foregroundColor = currScheme.getDefaultForeground();
    if (backgroundColor == null)
        backgroundColor = currScheme.getDefaultBackground();
    Color shortcutColor = getShortcutColor(backgroundColor, foregroundColor);
    String shortcutStyle = "color:#" + GuiUtils.colorToHex(shortcutColor);
    String abbrStyle = "font-family:" + currScheme.getConsoleFontName() + ";font-style:oblique;";
    for (ActionInfo actionInfo : foundActions) {
        AnAction action = actionInfo.getAction();
        if (action != null) {
            Presentation presentation = actionInfo.getAction().getTemplatePresentation();
            StringBuilder sb = new StringBuilder();
            sb.append("<html><span style='").append(abbrStyle).append("'>")
                    .append(fillString(actionInfo.getAbbreviation(), ABBR_FIELD_SIZE)).append("</span>");
            String desc = presentation.getDescription();
            if (desc != null && !desc.isEmpty()) {
                sb.append(desc);
            } else {
                String text = presentation.getText();
                if (text != null && !text.isEmpty()) {
                    sb.append(text);
                }
            }
            Shortcut[] shortcuts = action.getShortcutSet().getShortcuts();
            if (shortcuts.length > 0) {
                sb.append("&nbsp;&nbsp;<i style='").append(shortcutStyle).append("'>");
                for (Shortcut shortcut : action.getShortcutSet().getShortcuts()) {
                    if (shortcut != shortcuts[0]) {
                        sb.append(", ");
                    }
                    sb.append(KeymapUtil.getShortcutText(shortcut));
                }
                sb.append("</i>");
            }
            sb.append("</html>");
            JMenuItem menuItem = new JMenuItem(sb.toString());
            menuItem.setForeground(foregroundColor);
            menuItem.setBackground(backgroundColor);
            popupMenu.add(menuItem);
        }
    }
}

From source file:com.headwire.aem.tooling.intellij.explorer.AbstractSlingServerNodeDescriptor.java

License:Apache License

public static boolean addShortcutText(String actionId, CompositeAppearance appearance) {
    Keymap activeKeymap = KeymapManager.getInstance().getActiveKeymap();
    Shortcut[] shortcuts = activeKeymap.getShortcuts(actionId);
    if (shortcuts != null && shortcuts.length > 0) {
        appearance.getEnding().addText(" (" + KeymapUtil.getShortcutText(shortcuts[0]) + ")",
                SimpleTextAttributes.GRAY_ATTRIBUTES);
        return true;
    } else// w  w w  .  j a  v a 2s.com
        return false;
}

From source file:com.intellij.android.designer.designSurface.AndroidDesignerActionPanel.java

License:Apache License

private ActionGroup getRhsActions() {
    DefaultActionGroup group = new DefaultActionGroup();

    group.add(new ToggleAction(null, "Zoom to Fit (0)", AndroidIcons.ZoomFit) {
        @Override//  ww w  . j  a  va  2  s. c om
        public boolean isSelected(AnActionEvent e) {
            return ((AndroidDesignerEditorPanel) myDesigner).isZoomToFit();
        }

        @Override
        public void setSelected(AnActionEvent e, boolean state) {
            myDesigner.zoom(ZoomType.FIT);
        }
    });
    group.add(new AnAction(null, "Reset Zoom to 100% (1)", AndroidIcons.ZoomActual) {
        @Override
        public void actionPerformed(AnActionEvent e) {
            myDesigner.zoom(ZoomType.ACTUAL);
        }
    });
    group.addSeparator();
    group.add(new AnAction(null, "Zoom In (+)", AndroidIcons.ZoomIn) {
        @Override
        public void actionPerformed(AnActionEvent e) {
            myDesigner.zoom(ZoomType.IN);
        }
    });
    group.add(new AnAction(null, "Zoom Out (-)", AndroidIcons.ZoomOut) {
        @Override
        public void actionPerformed(AnActionEvent e) {
            myDesigner.zoom(ZoomType.OUT);
        }
    });

    String description = "Jump to Source";
    KeyboardShortcut shortcut = ActionManager.getInstance()
            .getKeyboardShortcut(IdeActions.ACTION_GOTO_DECLARATION);
    if (shortcut != null) {
        description += " (" + KeymapUtil.getShortcutText(shortcut) + ")";
    }
    // Use FilesTypes.Text rather than FileTypes.Xml here to avoid having the icon from
    // the tab bar replicated right below it
    group.add(new AnAction(null, description, AllIcons.FileTypes.Text) {
        @Override
        public void actionPerformed(AnActionEvent e) {
            List<RadComponent> selection = myDesigner.getSurfaceArea().getSelection();
            if (!selection.isEmpty()) {
                RadViewComponent component = (RadViewComponent) selection.get(0);
                PsiNavigateUtil.navigate(component.getTag());
            }
        }

        @Override
        public void update(AnActionEvent e) {
            List<RadComponent> selection = myDesigner.getSurfaceArea().getSelection();
            e.getPresentation().setEnabled(!selection.isEmpty());
        }
    });

    return group;
}

From source file:com.intellij.codeInsight.highlighting.HighlightUsagesHandler.java

License:Apache License

public static String getShortcutText() {
    final Shortcut[] shortcuts = ActionManager.getInstance()
            .getAction(IdeActions.ACTION_HIGHLIGHT_USAGES_IN_FILE).getShortcutSet().getShortcuts();
    if (shortcuts.length == 0) {
        return "<no key assigned>";
    }//from w w w. j  a  v a2s  . c o  m
    return KeymapUtil.getShortcutText(shortcuts[0]);
}

From source file:com.intellij.find.actions.ShowUsagesAction.java

License:Apache License

@Nullable
private static String getSecondInvocationTitle(@NotNull FindUsagesOptions options,
        @NotNull FindUsagesHandler handler) {
    if (getShowUsagesShortcut() != null) {
        GlobalSearchScope maximalScope = FindUsagesManager.getMaximalScope(handler);
        if (!options.searchScope.equals(maximalScope)) {
            return "Press " + KeymapUtil.getShortcutText(getShowUsagesShortcut()) + " again to search in "
                    + maximalScope.getDisplayName();
        }//from ww w.  j ava2s. c  om
    }
    return null;
}