From 9657ef77845c4c573cc615af4404dd83b3525643 Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 19 Apr 2011 17:56:26 +0400 Subject: [PATCH] mnemonics for add/remove buttons in Project Structure dialog are replaced by insert/delete shortcuts (IDEA-43339) --- .../FacetAutodetectionConfigurable.java | 8 +++++++ .../classpath/ClasspathPanelImpl.java | 23 ++++--------------- .../openapi/projectRoots/ui/PathEditor.java | 4 ++++ .../openapi/actionSystem/CommonShortcuts.java | 8 +++++-- .../intellij/ui/SimpleColoredComponent.java | 3 ++- .../src/messages/ProjectBundle.properties | 4 ++-- .../util/src/com/intellij/util/ui/UIUtil.java | 15 ++++++++++++ 7 files changed, 42 insertions(+), 23 deletions(-) diff --git a/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetAutodetectionConfigurable.java b/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetAutodetectionConfigurable.java index 1bd0d909b6ab..6e9dac3c833e 100644 --- a/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetAutodetectionConfigurable.java +++ b/java/idea-ui/src/com/intellij/facet/impl/ui/facetType/FacetAutodetectionConfigurable.java @@ -20,6 +20,7 @@ import com.intellij.facet.impl.autodetecting.DisabledAutodetectionByTypeElement; import com.intellij.facet.impl.autodetecting.DisabledAutodetectionInModuleElement; import com.intellij.facet.impl.autodetecting.FacetAutodetectingManager; import com.intellij.facet.impl.autodetecting.FacetAutodetectingManagerImpl; +import com.intellij.openapi.actionSystem.CommonShortcuts; import com.intellij.openapi.module.Module; import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ConfigurationException; @@ -45,6 +46,7 @@ import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; import java.util.*; /** @@ -105,9 +107,11 @@ public class FacetAutodetectionConfigurable implements Configurable { } } }); + UIUtil.addKeyboardShortcut(myModulesList, myAddModuleButton, CommonShortcuts.getInsertKeystroke()); myRemoveModuleButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { + //noinspection unchecked List removed = ListUtil.removeSelectedItems(myModulesList); for (String moduleName : removed) { if (!myAddedModules.remove(moduleName)) { @@ -117,14 +121,18 @@ public class FacetAutodetectionConfigurable implements Configurable { updateButtons(); } }); + KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0); + UIUtil.addKeyboardShortcut(myModulesList, myRemoveModuleButton, delete); myRemoveFileButton.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { + //noinspection unchecked List removed = ListUtil.removeSelectedItems(myFilesList); myRemovedFiles.addAll(removed); updateButtons(); } }); + UIUtil.addKeyboardShortcut(myFilesList, myRemoveFileButton, delete); myEnableAutoDetectionCheckBox.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java index a7a23e18f039..644223beb720 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/classpath/ClasspathPanelImpl.java @@ -50,6 +50,7 @@ import com.intellij.ui.*; import com.intellij.ui.awt.RelativePoint; import com.intellij.util.EventDispatcher; import com.intellij.util.ui.Table; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -306,10 +307,10 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel { }); } - addKeyboardShortcut(myEntryTable, removeButton, KeyEvent.VK_DELETE, 0); - addKeyboardShortcut(myEntryTable, addButton, KeyEvent.VK_INSERT, 0); - addKeyboardShortcut(myEntryTable, upButton, KeyEvent.VK_UP, KeyEvent.CTRL_DOWN_MASK); - addKeyboardShortcut(myEntryTable, downButton, KeyEvent.VK_DOWN, KeyEvent.CTRL_DOWN_MASK); + UIUtil.addKeyboardShortcut(myEntryTable, removeButton, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); + UIUtil.addKeyboardShortcut(myEntryTable, addButton, CommonShortcuts.getInsertKeystroke()); + UIUtil.addKeyboardShortcut(myEntryTable, upButton, KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.CTRL_DOWN_MASK)); + UIUtil.addKeyboardShortcut(myEntryTable, downButton, KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.CTRL_DOWN_MASK)); addButton.addActionListener(new ActionListener() { @Override @@ -407,20 +408,6 @@ public class ClasspathPanelImpl extends JPanel implements ClasspathPanel { return panel; } - private static void addKeyboardShortcut(final JComponent target, final JButton button, final int keyEvent, final int modifiers) { - target.registerKeyboardAction( - new ActionListener() { - public void actionPerformed(ActionEvent e) { - if (button.isEnabled()) { - button.doClick(); - } - } - }, - KeyStroke.getKeyStroke(keyEvent, modifiers), - WHEN_FOCUSED - ); - } - @Override public void runClasspathPanelAction(Runnable action) { try { diff --git a/platform/lang-api/src/com/intellij/openapi/projectRoots/ui/PathEditor.java b/platform/lang-api/src/com/intellij/openapi/projectRoots/ui/PathEditor.java index 04335e580838..824191a85269 100644 --- a/platform/lang-api/src/com/intellij/openapi/projectRoots/ui/PathEditor.java +++ b/platform/lang-api/src/com/intellij/openapi/projectRoots/ui/PathEditor.java @@ -17,6 +17,7 @@ package com.intellij.openapi.projectRoots.ui; import com.google.common.collect.Lists; import com.intellij.ide.DataManager; +import com.intellij.openapi.actionSystem.CommonShortcuts; import com.intellij.openapi.actionSystem.PlatformDataKeys; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; @@ -52,6 +53,7 @@ import javax.swing.event.ListSelectionListener; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -188,12 +190,14 @@ public class PathEditor { setSelectedRoots(added); } }); + UIUtil.addKeyboardShortcut(myList, myAddButton, CommonShortcuts.getInsertKeystroke()); myRemoveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int[] idxs = myList.getSelectedIndices(); doRemoveItems(idxs, myList); } }); + UIUtil.addKeyboardShortcut(myList, myRemoveButton, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); mySpecifyUrlButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { onSpecifyUrlButtonClicked(); 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 a01c28d4d235..b177076fbf94 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/CommonShortcuts.java @@ -32,13 +32,17 @@ public class CommonShortcuts { SystemInfo.isMac ? KeyEvent.META_DOWN_MASK : KeyEvent.CTRL_DOWN_MASK)); - public static final ShortcutSet INSERT = new CustomShortcutSet(SystemInfo.isMac ? KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK) - : KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0)); + public static final ShortcutSet INSERT = new CustomShortcutSet(getInsertKeystroke()); public static final ShortcutSet DELETE = new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0)); public static final ShortcutSet ESCAPE = new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)); public static final ShortcutSet DOUBLE_CLICK_1 = new CustomShortcutSet(new Shortcut[]{new MouseShortcut(MouseEvent.BUTTON1, 0, 2)}); + public static KeyStroke getInsertKeystroke() { + return SystemInfo.isMac ? KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK) + : KeyStroke.getKeyStroke(KeyEvent.VK_INSERT, 0); + } + public static ShortcutSet getCopy() { return new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_COPY)); } diff --git a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java index 2976bb2cf59a..b902ca5b6711 100644 --- a/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java +++ b/platform/platform-api/src/com/intellij/ui/SimpleColoredComponent.java @@ -22,6 +22,7 @@ import com.intellij.openapi.util.SystemInfo; import com.intellij.util.containers.HashMap; import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import javax.accessibility.Accessible; import javax.accessibility.AccessibleContext; @@ -180,7 +181,7 @@ public class SimpleColoredComponent extends JComponent implements Accessible { /** * Sets a new component icon */ - public final void setIcon(final Icon icon) { + public final void setIcon(final @Nullable Icon icon) { myIcon = icon; revalidateAndRepaint(); } diff --git a/platform/platform-resources-en/src/messages/ProjectBundle.properties b/platform/platform-resources-en/src/messages/ProjectBundle.properties index f091a77df3ce..caf8510f511a 100644 --- a/platform/platform-resources-en/src/messages/ProjectBundle.properties +++ b/platform/platform-resources-en/src/messages/ProjectBundle.properties @@ -79,8 +79,8 @@ sdk.table.settings=SDK Table sdk.unknown.name=Unknown SDK sdk.list.name.required.error=Please specify SDK name sdk.list.unique.name.required.error=Please specify a different SDK name -button.add=&Add... -button.remove=&Remove +button.add=Add... +button.remove=Remove sdk.paths.specify.url.button=&Specify URL... sdk.configure.title=Configure SDK sdk.configure.save.settings.error=Cannot Save Settings diff --git a/platform/util/src/com/intellij/util/ui/UIUtil.java b/platform/util/src/com/intellij/util/ui/UIUtil.java index 81aa592c7ddd..870606807654 100644 --- a/platform/util/src/com/intellij/util/ui/UIUtil.java +++ b/platform/util/src/com/intellij/util/ui/UIUtil.java @@ -1463,6 +1463,21 @@ public class UIUtil { } } + public static void addKeyboardShortcut(final JComponent target, + final AbstractButton button, final KeyStroke keyStroke) { + target.registerKeyboardAction( + new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (button.isEnabled()) { + button.doClick(); + } + } + }, + keyStroke, + JComponent.WHEN_FOCUSED + ); + } + public static class MacTreeUI extends BasicTreeUI { public static final String SOURCE_LIST_CLIENT_PROPERTY = "mac.ui.source.list";