From 6095a02ede0852e8168aa141217605b7835bfaf6 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Tue, 21 Apr 2015 17:43:51 +0300 Subject: [PATCH] vcs: avoid rewriting ShortcutSet for global actions while registering local shortcuts this fixes issues like IDEA-119375 --- .../com/intellij/dvcs/push/ui/PushLog.java | 2 +- .../openapi/actionSystem/EmptyAction.java | 5 ++++ .../vcs/changes/ChangesViewManager.java | 28 +++++++------------ .../committed/CommittedChangesBrowser.java | 2 +- .../committed/CommittedChangesPanel.java | 5 ++-- .../CommittedChangesTreeBrowser.java | 9 +++--- .../shelf/ShelvedChangesViewManager.java | 4 +-- .../intellij/vcs/log/ui/frame/MainFrame.java | 2 +- .../src/git4idea/ui/GitCommitListPanel.java | 2 +- .../idea/svn/integrate/ToBeMergedDialog.java | 2 +- 10 files changed, 29 insertions(+), 32 deletions(-) diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/PushLog.java b/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/PushLog.java index 5de0142324d8..3495cbb7cbe2 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/PushLog.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/PushLog.java @@ -212,7 +212,7 @@ public class PushLog extends JPanel implements DataProvider { myChangesBrowser = new ChangesBrowser(project, null, Collections.emptyList(), null, false, true, null, ChangesBrowser.MyUseCase.LOCAL_CHANGES, null); - myChangesBrowser.getDiffAction().registerCustomShortcutSet(CommonShortcuts.getDiff(), myTree); + myChangesBrowser.getDiffAction().registerCustomShortcutSet(myChangesBrowser.getDiffAction().getShortcutSet(), myTree); final EditSourceForDialogAction editSourceAction = new EditSourceForDialogAction(myChangesBrowser); editSourceAction.registerCustomShortcutSet(CommonShortcuts.getEditSource(), myChangesBrowser); myChangesBrowser.addToolbarAction(editSourceAction); diff --git a/platform/platform-api/src/com/intellij/openapi/actionSystem/EmptyAction.java b/platform/platform-api/src/com/intellij/openapi/actionSystem/EmptyAction.java index 9e53c35f7cac..38499eb25394 100644 --- a/platform/platform-api/src/com/intellij/openapi/actionSystem/EmptyAction.java +++ b/platform/platform-api/src/com/intellij/openapi/actionSystem/EmptyAction.java @@ -79,6 +79,11 @@ public final class EmptyAction extends AnAction { } } + public static void registerWithShortcutSet(@NotNull String id, @NotNull ShortcutSet shortcutSet, @NotNull JComponent component) { + AnAction newAction = wrap(ActionManager.getInstance().getAction(id)); + newAction.registerCustomShortcutSet(shortcutSet, component); + } + public static AnAction wrap(final AnAction action) { return action instanceof ActionGroup ? new ActionGroup() { { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java index 411e17461912..a19ebeaf68e0 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangesViewManager.java @@ -22,7 +22,8 @@ */ package com.intellij.openapi.vcs.changes; -import com.intellij.diff.util.DiffUserDataKeysEx; +import com.intellij.diff.util.DiffPlaces; +import com.intellij.diff.util.DiffUtil; import com.intellij.icons.AllIcons; import com.intellij.ide.CommonActionsManager; import com.intellij.ide.TreeExpander; @@ -40,9 +41,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.SimpleToolWindowPanel; import com.intellij.openapi.ui.Splitter; import com.intellij.openapi.util.*; -import com.intellij.diff.util.DiffPlaces; -import com.intellij.diff.util.DiffUserDataKeys; -import com.intellij.diff.util.DiffUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.VcsBundle; @@ -202,17 +200,13 @@ public class ChangesViewManager implements ChangesViewI, JDOMExternalizable, Pro DefaultActionGroup group = (DefaultActionGroup) ActionManager.getInstance().getAction("ChangesViewToolbar"); - ActionManager.getInstance().getAction("ChangesView.Refresh").registerCustomShortcutSet(CommonShortcuts.getRerun(), panel); - ActionManager.getInstance().getAction("ChangesView.NewChangeList").registerCustomShortcutSet(CommonShortcuts.getNew(), panel); - ActionManager.getInstance().getAction("ChangesView.RemoveChangeList").registerCustomShortcutSet(CommonShortcuts.getDelete(), panel); - AnAction moveToChangeList = ActionManager.getInstance().getAction(IdeActions.MOVE_TO_ANOTHER_CHANGE_LIST); - moveToChangeList.registerCustomShortcutSet(new CompositeShortcutSet(moveToChangeList.getShortcutSet(), - CommonShortcuts.getMove()), panel); - ActionManager.getInstance().getAction("ChangesView.Rename").registerCustomShortcutSet(CommonShortcuts.getRename(), panel); - ActionManager.getInstance().getAction("ChangesView.SetDefault").registerCustomShortcutSet( - new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_U, KeyEvent.ALT_DOWN_MASK | ctrlMask())), panel); - - ActionManager.getInstance().getAction("ChangesView.Diff").registerCustomShortcutSet(CommonShortcuts.getDiff(), panel); + EmptyAction.registerWithShortcutSet("ChangesView.Refresh", CommonShortcuts.getRerun(), panel); + EmptyAction.registerWithShortcutSet("ChangesView.NewChangeList", CommonShortcuts.getNew(), panel); + EmptyAction.registerWithShortcutSet("ChangesView.RemoveChangeList", CommonShortcuts.getDelete(), panel); + EmptyAction.registerWithShortcutSet(IdeActions.MOVE_TO_ANOTHER_CHANGE_LIST, CommonShortcuts.getMove(), panel); + EmptyAction.registerWithShortcutSet("ChangesView.Rename",CommonShortcuts.getRename() , panel); + EmptyAction.registerWithShortcutSet("ChangesView.SetDefault", new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_U, KeyEvent.ALT_DOWN_MASK | ctrlMask())), panel); + EmptyAction.registerWithShortcutSet("ChangesView.Diff", CommonShortcuts.getDiff(), panel); JPanel toolbarPanel = new JPanel(new BorderLayout()); ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.CHANGES_VIEW_TOOLBAR, group, false); @@ -226,9 +220,7 @@ public class ChangesViewManager implements ChangesViewI, JDOMExternalizable, Pro visualActionsGroup.add(CommonActionsManager.getInstance().createCollapseAllAction(expander, panel)); ToggleShowFlattenAction showFlattenAction = new ToggleShowFlattenAction(); - showFlattenAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_P, - ctrlMask())), - panel); + showFlattenAction.registerCustomShortcutSet(new CustomShortcutSet(KeyStroke.getKeyStroke(KeyEvent.VK_P, ctrlMask())), panel); visualActionsGroup.add(showFlattenAction); visualActionsGroup.add(ActionManager.getInstance().getAction(IdeActions.ACTION_COPY)); visualActionsGroup.add(new ToggleShowIgnoredAction()); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesBrowser.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesBrowser.java index 7359f09f8811..705e96585a75 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesBrowser.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesBrowser.java @@ -172,7 +172,7 @@ public class CommittedChangesBrowser extends JPanel { selectFirstIfAny(); - myChangesView.getDiffAction().registerCustomShortcutSet(CommonShortcuts.getDiff(), myChangeListsView); + myChangesView.getDiffAction().registerCustomShortcutSet(myChangesView.getDiffAction().getShortcutSet(), myChangeListsView); } public void selectFirstIfAny() { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesPanel.java index 25766ad99d5d..959f9bdd874d 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesPanel.java @@ -121,9 +121,8 @@ public class CommittedChangesPanel extends JPanel implements TypeSafeDataProvide } else { myBrowser.setTableContextMenu(group, Collections.emptyList()); } - - final AnAction anAction = ActionManager.getInstance().getAction("CommittedChanges.Refresh"); - anAction.registerCustomShortcutSet(CommonShortcuts.getRerun(), this); + + EmptyAction.registerWithShortcutSet("CommittedChanges.Refresh", CommonShortcuts.getRerun(), this); myBrowser.addFilter(myFilterComponent); myIfNotCachedReloader = myLocation == null ? null : new Consumer() { @Override diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesTreeBrowser.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesTreeBrowser.java index e6f5027f0b4f..76c353ef0541 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesTreeBrowser.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/CommittedChangesTreeBrowser.java @@ -10,6 +10,7 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; +import com.intellij.openapi.keymap.Keymap; import com.intellij.openapi.keymap.KeymapManager; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Splitter; @@ -110,9 +111,9 @@ public class CommittedChangesTreeBrowser extends JPanel implements TypeSafeDataP updateBySelectionChange(); - ActionManager.getInstance().getAction("CommittedChanges.Details").registerCustomShortcutSet( - new CustomShortcutSet(KeymapManager.getInstance().getActiveKeymap().getShortcuts(IdeActions.ACTION_QUICK_JAVADOC)), - this); + Keymap keymap = KeymapManager.getInstance().getActiveKeymap(); + CustomShortcutSet quickdocShortcuts = new CustomShortcutSet(keymap.getShortcuts(IdeActions.ACTION_QUICK_JAVADOC)); + EmptyAction.registerWithShortcutSet("CommittedChanges.Details", quickdocShortcuts, this); myCopyProvider = new TreeCopyProvider(myChangesTree); myTreeExpander = new DefaultTreeExpander(myChangesTree); @@ -120,7 +121,7 @@ public class CommittedChangesTreeBrowser extends JPanel implements TypeSafeDataP myHelpId = ourHelpId; - myDetailsView.getDiffAction().registerCustomShortcutSet(CommonShortcuts.getDiff(), myChangesTree); + myDetailsView.getDiffAction().registerCustomShortcutSet(myDetailsView.getDiffAction().getShortcutSet(), myChangesTree); myConnection = myProject.getMessageBus().connect(); myConnection.subscribe(ITEMS_RELOADED, new CommittedChangesReloadListener() { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java index 8cad5f820d96..5427340f06b9 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/shelf/ShelvedChangesViewManager.java @@ -125,9 +125,9 @@ public class ShelvedChangesViewManager implements ProjectComponent { new TreeLinkMouseListener(new ShelfTreeCellRenderer(project, myMoveRenameInfo)).installOn(myTree); final AnAction showDiffAction = ActionManager.getInstance().getAction("ShelvedChanges.Diff"); - showDiffAction.registerCustomShortcutSet(CommonShortcuts.getDiff(), myTree); + showDiffAction.registerCustomShortcutSet(showDiffAction.getShortcutSet(), myTree); final EditSourceAction editSourceAction = new EditSourceAction(); - editSourceAction.registerCustomShortcutSet(CommonShortcuts.getEditSource(), myTree); + editSourceAction.registerCustomShortcutSet(editSourceAction.getShortcutSet(), myTree); PopupHandler.installPopupHandler(myTree, "ShelvedChangesPopupMenu", ActionPlaces.UNKNOWN); diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/MainFrame.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/MainFrame.java index b924ade5cfe4..36a7ab4494bc 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/MainFrame.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/MainFrame.java @@ -83,7 +83,7 @@ public class MainFrame extends JPanel implements TypeSafeDataProvider { myDetailsPanel = new DetailsPanel(logDataHolder, myGraphTable, vcsLogUI.getColorManager(), initialDataPack); myChangesBrowser = new RepositoryChangesBrowser(project, null, Collections.emptyList(), null); - myChangesBrowser.getDiffAction().registerCustomShortcutSet(CommonShortcuts.getDiff(), getGraphTable()); + myChangesBrowser.getDiffAction().registerCustomShortcutSet(myChangesBrowser.getDiffAction().getShortcutSet(), getGraphTable()); myChangesBrowser.getEditSourceAction().registerCustomShortcutSet(CommonShortcuts.getEditSource(), getGraphTable()); setDefaultEmptyText(myChangesBrowser); myChangesLoadingPane = new JBLoadingPanel(new BorderLayout(), project); diff --git a/plugins/git4idea/src/git4idea/ui/GitCommitListPanel.java b/plugins/git4idea/src/git4idea/ui/GitCommitListPanel.java index 5d66960e4fe1..4351572dc090 100644 --- a/plugins/git4idea/src/git4idea/ui/GitCommitListPanel.java +++ b/plugins/git4idea/src/git4idea/ui/GitCommitListPanel.java @@ -102,7 +102,7 @@ public class GitCommitListPanel extends JPanel implements TypeSafeDataProvider { * Registers the diff action which will be called when the diff shortcut is pressed in the table. */ public void registerDiffAction(@NotNull AnAction diffAction) { - diffAction.registerCustomShortcutSet(CommonShortcuts.getDiff(), myTable); + diffAction.registerCustomShortcutSet(diffAction.getShortcutSet(), myTable); } // Make changes available for diff action diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/ToBeMergedDialog.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/ToBeMergedDialog.java index d1ec9715ae45..aa2293161973 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/ToBeMergedDialog.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/integrate/ToBeMergedDialog.java @@ -350,7 +350,7 @@ public class ToBeMergedDialog extends DialogWrapper implements MergeDialogI { flatModel.fireTableDataChanged(); myRepositoryChangesBrowser = new RepositoryChangesBrowser(myProject, Collections.emptyList(), Collections.emptyList(), null); - myRepositoryChangesBrowser.getDiffAction().registerCustomShortcutSet(CommonShortcuts.getDiff(), myRevisionsList); + myRepositoryChangesBrowser.getDiffAction().registerCustomShortcutSet(myRepositoryChangesBrowser.getDiffAction().getShortcutSet(), myRevisionsList); setChangesDecorator(); mySplitter.setSecondComponent(myRepositoryChangesBrowser); mySplitter.setDividerWidth(2);