IDEA-270878 Tool windows dnd: add the "Dock" button to the header in Floating mode

GitOrigin-RevId: b6160fc81da4b9d1e29ae2f00f846f48e2084417
This commit is contained in:
Vassiliy.Kudryashov
2021-06-06 17:40:46 +03:00
committed by intellij-monorepo-bot
parent 5ad3bc44a0
commit 11a51563ff
5 changed files with 55 additions and 3 deletions

View File

@@ -93,7 +93,7 @@ public final class ToolWindowMoveAction extends DumbAwareAction implements FusAw
}
@NotNull
private Icon getIcon() {
public Icon getIcon() {
switch (this) {
case LeftTop:
return AllIcons.Actions.MoveToLeftTop;
@@ -118,7 +118,7 @@ public final class ToolWindowMoveAction extends DumbAwareAction implements FusAw
return getAnchor() == window.getAnchor() && window.isSplitMode() == isSplit();
}
void applyTo(@NotNull ToolWindow window) {
public void applyTo(@NotNull ToolWindow window) {
window.setAnchor(getAnchor(), null);
window.setSplitMode(isSplit(), null);
}

View File

@@ -0,0 +1,50 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.wm.impl;
import com.intellij.ide.actions.ToolWindowMoveAction;
import com.intellij.idea.ActionsBundle;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowType;
import com.intellij.openapi.wm.ex.ToolWindowEx;
import org.jetbrains.annotations.NotNull;
public class DockToolWindowAction extends DumbAwareAction /*implements FusAwareAction*/ {
public DockToolWindowAction() {
super(ActionsBundle.messagePointer("action.DockToolWindow.text"));
}
@Override
public void update(@NotNull AnActionEvent e) {
Project project = e.getProject();
if (project == null || project.isDisposed()) return;
ToolWindow toolWindow = e.getData(PlatformDataKeys.TOOL_WINDOW);
if (!(toolWindow instanceof ToolWindowImpl)) return;
e.getPresentation().setIcon(ToolWindowMoveAction.Anchor.fromWindowInfo(((ToolWindowImpl)toolWindow).getWindowInfo()).getIcon());
e.getPresentation()
.setEnabledAndVisible(toolWindow.getType() == ToolWindowType.FLOATING || toolWindow.getType() == ToolWindowType.WINDOWED);
}
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getProject();
if (project == null || project.isDisposed()) return;
ToolWindow toolWindow = e.getData(PlatformDataKeys.TOOL_WINDOW);
if (!(toolWindow instanceof ToolWindowImpl)) return;
toolWindow.setType(((ToolWindowEx)toolWindow).getInternalType(), null);
ToolWindowMoveAction.Anchor.fromWindowInfo(((ToolWindowImpl)toolWindow).getWindowInfo()).applyTo(toolWindow);
}
//@Override
//public @NotNull List<EventPair<?>> getAdditionalUsageData(@NotNull AnActionEvent event) {
// ToolWindow toolWindow = event.getData(PlatformDataKeys.TOOL_WINDOW);
// if (toolWindow != null) {
// return Collections.singletonList(ToolwindowFusEventFields.TOOLWINDOW.with(toolWindow.getId()));
// }
// return Collections.emptyList();
//}
}

View File

@@ -63,7 +63,7 @@ abstract class ToolWindowHeader internal constructor(
object : ActionGroup(), DumbAware {
private val children by lazy<Array<AnAction>> {
val tabListAction = ActionManager.getInstance().getAction("TabList")
arrayOf(tabListAction, actionGroup, ShowOptionsAction(), HideAction())
arrayOf(tabListAction, actionGroup, DockToolWindowAction(), ShowOptionsAction(), HideAction())
}
override fun getChildren(e: AnActionEvent?) = children

View File

@@ -1075,6 +1075,7 @@ action.ResizeToolWindowDown.text=Stretch to Bottom
action.ResizeToolWindowDown.description=Resize active tool window to the bottom
action.ResizeToolWindowMaximize.text=Maximize Tool Window
action.ResizeToolWindowMaximize.text.alternative=Restore Tool Window Size
action.DockToolWindow.text=Dock
action.IncrementWindowWidth.text=Increment Width
action.DecrementWindowWidth.text=Decrement Width
action.IncrementWindowHeight.text=Increment Height

View File

@@ -716,6 +716,7 @@
<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"/>
<action id="DockToolWindow" class="com.intellij.openapi.wm.impl.DockToolWindowAction"/>
<separator/>
<group id="TW.ViewModeGroup" class="com.intellij.ide.actions.ToolWindowViewModeAction$Group" popup="true"/>
<group id="TW.MoveToGroup" class="com.intellij.ide.actions.ToolWindowMoveAction$Group"/>