mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
unify pin-active-tab actions: TW, EW & content-tabs: part 2
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -377,6 +377,8 @@
|
||||
<separator/>
|
||||
</group>
|
||||
|
||||
<action id="PinActiveTab" class="com.intellij.ide.actions.PinActiveTabAction"/>
|
||||
|
||||
<group id="WindowMenu" popup="true">
|
||||
<action id="MinimizeCurrentWindow" class="com.intellij.ide.actions.MinimizeCurrentWindowAction"/>
|
||||
<action id="ZoomCurrentWindow" class="com.intellij.ide.actions.ZoomCurrentWindowAction"/>
|
||||
@@ -387,7 +389,7 @@
|
||||
<action id="HideActiveWindow" class="com.intellij.ide.actions.HideToolWindowAction"/>
|
||||
<action id="HideSideWindows" class="com.intellij.ide.actions.HideSideWindowsAction"/>
|
||||
<action id="HideAllWindows" class="com.intellij.ide.actions.HideAllToolWindowsAction"/>
|
||||
<action id="PinToolwindowTab" class="com.intellij.ui.content.tabs.PinToolwindowTabAction"/>
|
||||
<action id="PinToolwindowTab" class="com.intellij.ui.content.tabs.PinToolwindowTabAction" use-shortcut-of="PinActiveTab"/>
|
||||
<action id="CloseActiveTab" class="com.intellij.ide.actions.CloseActiveTabAction"/>
|
||||
<action id="JumpToLastWindow" class="com.intellij.ide.actions.JumpToLastWindowAction"/>
|
||||
<action id="MaximizeToolWindow" class="com.intellij.openapi.wm.impl.MaximizeToolWindowAction"/>
|
||||
@@ -410,7 +412,7 @@
|
||||
<group id="EditorTabsGroup" popup="true">
|
||||
<action id="NextTab" class="com.intellij.ide.actions.NextTabAction"/>
|
||||
<action id="PreviousTab" class="com.intellij.ide.actions.PreviousTabAction"/>
|
||||
<action id="PinActiveTab" class="com.intellij.ide.actions.PinActiveTabAction$EW"/>
|
||||
<action id="PinActiveEditorTab" class="com.intellij.ide.actions.PinActiveTabAction$EW" use-shortcut-of="PinActiveTab"/>
|
||||
<action id="TabList" class="com.intellij.ide.actions.TabListAction"/>
|
||||
<separator/>
|
||||
<group id="CloseEditorsGroup">
|
||||
@@ -547,7 +549,7 @@
|
||||
<action id="MoveEditorToOppositeTabGroup" class="com.intellij.openapi.fileEditor.impl.MoveEditorToOppositeTabGroupAction"/>
|
||||
<action id="OpenEditorInOppositeTabGroup" class="com.intellij.openapi.fileEditor.impl.OpenEditorInOppositeTabGroupAction"/>
|
||||
<reference ref="ChangeSplitOrientation"/>
|
||||
<reference ref="PinActiveTab"/>
|
||||
<reference ref="PinActiveEditorTab"/>
|
||||
<reference ref="TabsPlacementGroup"/>
|
||||
<reference ref="TabsAlphabeticalMode"/>
|
||||
<reference ref="AddNewTabToTheEndMode"/>
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user