From 3e56beceb329504d212efaf3bd9b2b3fff60ee69 Mon Sep 17 00:00:00 2001 From: "Gregory.Shrago" Date: Mon, 29 Feb 2016 23:14:16 +0300 Subject: [PATCH] unify pin-active-tab actions: TW, EW & content-tabs: part 2 --- .../ide/actions/PinActiveTabAction.java | 58 +++++++++++-------- .../content/tabs/PinToolwindowTabAction.java | 2 + .../src/messages/ActionsBundle.properties | 4 +- .../src/idea/PlatformActions.xml | 8 ++- .../intellij/usages/impl/UsageViewImpl.java | 2 +- 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/actions/PinActiveTabAction.java b/platform/platform-impl/src/com/intellij/ide/actions/PinActiveTabAction.java index 20f7e9f2ec65..c78c0b57201a 100644 --- a/platform/platform-impl/src/com/intellij/ide/actions/PinActiveTabAction.java +++ b/platform/platform-impl/src/com/intellij/ide/actions/PinActiveTabAction.java @@ -21,7 +21,7 @@ import com.intellij.ide.IdeBundle; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.fileEditor.ex.FileEditorManagerEx; import com.intellij.openapi.fileEditor.impl.EditorWindow; -import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.project.DumbAwareAction; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.ToolWindow; @@ -34,9 +34,9 @@ import org.jetbrains.annotations.Nullable; /** * Pins any kind of tab in context: editor tab, toolwindow tab or other tabs. * - * todo drop TW and EW, pro: one action-one shortcut; contra: menu|Window changes + * todo drop TW and EW, both are only for menu|Window tab/editor sub-menus. */ -public class PinActiveTabAction extends ToggleAction implements DumbAware { +public class PinActiveTabAction extends DumbAwareAction implements Toggleable { public static abstract class Handler { public final boolean isPinned; @@ -51,15 +51,12 @@ public class PinActiveTabAction extends ToggleAction implements DumbAware { } @Override - public boolean isSelected(AnActionEvent e) { + public void actionPerformed(AnActionEvent e) { Handler handler = getHandler(e); - return handler != null && handler.isPinned; - } - - @Override - public void setSelected(AnActionEvent e, boolean state) { - Handler handler = getHandler(e); - if (handler != null) handler.setPinned(state); + if (handler == null) return; + boolean selected = !handler.isPinned; + handler.setPinned(selected); + e.getPresentation().putClientProperty(SELECTED_PROPERTY, selected); } @Override @@ -89,24 +86,14 @@ public class PinActiveTabAction extends ToggleAction implements DumbAware { Content content = currentWindow != null ? null : getContentFromEvent(e); if (content != null && content.isPinnable()) { - return new Handler(content.isPinned(), content.getManager().getSelectedContent() == content) { - @Override - void setPinned(boolean value) { - content.setPinned(value); - } - }; + return createHandler(content); } final EditorWindow window = currentWindow != null ? currentWindow : project != null ? FileEditorManagerEx.getInstanceEx(project).getCurrentWindow() : null; VirtualFile selectedFile = window == null ? null : getFileFromEvent(e, window); if (selectedFile != null) { - return new Handler(window.isFilePinned(selectedFile), selectedFile.equals(e.getData(CommonDataKeys.VIRTUAL_FILE))) { - @Override - void setPinned(boolean value) { - window.setFilePinned(selectedFile, value); - } - }; + return createHandler(window, selectedFile); } return null; } @@ -122,6 +109,26 @@ public class PinActiveTabAction extends ToggleAction implements DumbAware { return content != null ? content : getToolWindowContent(e); } + @NotNull + private static Handler createHandler(final Content content) { + return new Handler(content.isPinned(), content.getManager().getSelectedContent() == content) { + @Override + void setPinned(boolean value) { + content.setPinned(value); + } + }; + } + + @NotNull + private static Handler createHandler(final EditorWindow window, final VirtualFile selectedFile) { + return new Handler(window.isFilePinned(selectedFile), selectedFile.equals(window.getSelectedFile())) { + @Override + void setPinned(boolean value) { + window.setFilePinned(selectedFile, value); + } + }; + } + @Nullable private static Content getNonToolWindowContent(@NotNull AnActionEvent e) { Content result = null; @@ -165,6 +172,11 @@ public class PinActiveTabAction extends ToggleAction implements DumbAware { } public static class EW extends PinActiveTabAction { + @Nullable + @Override + protected VirtualFile getFileFromEvent(@NotNull AnActionEvent e, @NotNull EditorWindow window) { + return window.getSelectedFile(); + } @Override protected Content getContentFromEvent(@NotNull AnActionEvent e) { diff --git a/platform/platform-impl/src/com/intellij/ui/content/tabs/PinToolwindowTabAction.java b/platform/platform-impl/src/com/intellij/ui/content/tabs/PinToolwindowTabAction.java index b8f3053a7a47..12d67dd76fea 100644 --- a/platform/platform-impl/src/com/intellij/ui/content/tabs/PinToolwindowTabAction.java +++ b/platform/platform-impl/src/com/intellij/ui/content/tabs/PinToolwindowTabAction.java @@ -21,6 +21,8 @@ import com.intellij.openapi.actionSystem.AnAction; /** * @author spleaner + * + * @deprecated use {@link PinActiveTabAction} */ public class PinToolwindowTabAction extends PinActiveTabAction.TW { public static final String ACTION_NAME = "PinToolwindowTab"; diff --git a/platform/platform-resources-en/src/messages/ActionsBundle.properties b/platform/platform-resources-en/src/messages/ActionsBundle.properties index 8c2d1b504fd2..a0ec59332719 100644 --- a/platform/platform-resources-en/src/messages/ActionsBundle.properties +++ b/platform/platform-resources-en/src/messages/ActionsBundle.properties @@ -904,7 +904,9 @@ action.PreviousEditorTab.text=Select Previous Tab in multi-editor file action.CloseActiveTab.text=Cl_ose Active Tab action.CloseActiveTab.description=Close active tool window tab action.PinActiveTab.text=P_in Active Tab -action.PinActiveTab.description=Pin active tool window or editor tab +action.PinActiveTab.description=Pin active editor or tool window tab +action.PinActiveEditorTab.text=P_in Active Tab +action.PinActiveEditorTab.description=Pin active editor tab action.CloseEditor.text=_Close Active Editor action.CloseEditor.description=Close active editor action.CloseAllEditors.text=Close _All diff --git a/platform/platform-resources/src/idea/PlatformActions.xml b/platform/platform-resources/src/idea/PlatformActions.xml index b0e5595b2748..275831506eed 100644 --- a/platform/platform-resources/src/idea/PlatformActions.xml +++ b/platform/platform-resources/src/idea/PlatformActions.xml @@ -377,6 +377,8 @@ + + @@ -387,7 +389,7 @@ - + @@ -410,7 +412,7 @@ - + @@ -547,7 +549,7 @@ - + diff --git a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java index 5a19b4734596..18b0d80ac89f 100644 --- a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java +++ b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java @@ -635,7 +635,7 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra canShowSettings() ? showSettings() : null, ActionManager.getInstance().getAction("UsageView.Rerun"), new CloseAction(), - ActionManager.getInstance().getAction("PinToolwindowTab"), + ActionManager.getInstance().getAction(IdeActions.ACTION_PIN_ACTIVE_TAB), createRecentFindUsagesAction(), expandAllAction, collapseAllAction,