From 117cfcf93261eee147516cfc49597bbbeaf748f7 Mon Sep 17 00:00:00 2001 From: Artem Bochkarev Date: Fri, 4 May 2018 11:40:25 +0700 Subject: [PATCH] IDEA-163208: new logic for showing debugger panel show debugger-panel until user manually closes it, restore when user activates debugger-tool-window --- .../intellij/ui/mac/touchbar/TouchBar.java | 2 ++ .../ui/mac/touchbar/TouchBarDebugger.java | 2 +- .../ui/mac/touchbar/TouchBarDebuggerAlt.java | 2 +- .../ui/mac/touchbar/TouchBarsManager.java | 34 +++++++++++++------ 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBar.java b/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBar.java index c6a03995bc11..f17b127d4fe1 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBar.java +++ b/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBar.java @@ -28,6 +28,8 @@ public class TouchBar implements NSTLibrary.ItemCreator { myNativePeer = NST.createTouchBar(touchbarName, this, myCustomEsc != null ? myCustomEsc.myUid : null); } + public boolean isManualClose() { return myCustomEsc != null; } + @Override public String toString() { return myName + "_" + myNativePeer; } diff --git a/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBarDebugger.java b/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBarDebugger.java index fbec46c29941..a018cb05eefa 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBarDebugger.java +++ b/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBarDebugger.java @@ -10,7 +10,7 @@ import java.awt.*; public class TouchBarDebugger extends TouchBarActionBase { TouchBarDebugger(@NotNull Project project, Component component) { - super("debugger", project, component); + super("debugger", project, component, true); addButton(AllIcons.Actions.Restart, null, new PlatformAction(IdeActions.ACTION_RERUN)); addAnActionButton("Pause"); diff --git a/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBarDebuggerAlt.java b/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBarDebuggerAlt.java index 35ec5f312387..f262f4afce91 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBarDebuggerAlt.java +++ b/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBarDebuggerAlt.java @@ -8,7 +8,7 @@ import java.awt.*; public class TouchBarDebuggerAlt extends TouchBarActionBase { public TouchBarDebuggerAlt(@NotNull Project project, Component component) { - super("debugger_alt", project, component); + super("debugger_alt", project, component, true); addFlexibleSpacing(); addAnActionButton("ViewBreakpoints", false); diff --git a/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBarsManager.java b/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBarsManager.java index eb80755a3473..fbd04ab53d51 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBarsManager.java +++ b/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TouchBarsManager.java @@ -55,13 +55,11 @@ public class TouchBarsManager { @Override public void focusGained(Editor editor) { - if (!hasTemporary()) - showTouchBar(myEditorBar); + _elevateTouchBar(myEditorBar); } @Override public void focusLost(Editor editor) { - if (!hasTemporary()) - closeTouchBar(myEditorBar); + closeTouchBar(myEditorBar); } }); } @@ -116,12 +114,14 @@ public class TouchBarsManager { public void stateChanged() { final String activeId = twm.getActiveToolWindowId(); if (activeId != null && activeId.equals("Debug")) { + // TODO: + // 1. check whether some debug session is running + // 2. stateChanged can be skipped sometimes when user clicks debug tool-window, need check by focus events or fix stateChanged-subscription if (myDebuggerBar == null) { myDebuggerBar = ProjectBarsStorage.instance(project).createBarContainer(ProjectBarsStorage.DEBUGGER, twm.getToolWindow(activeId).getComponent()); } showTouchBar(myDebuggerBar); - } else - closeTouchBar(myDebuggerBar); + } } }); } @@ -147,10 +147,6 @@ public class TouchBarsManager { } } - synchronized public static boolean hasTemporary() { - return ourTouchBarStack.stream().anyMatch((bc)->bc.isTemporary()); - } - synchronized public static void showTempTouchBar(TouchBar tb) { if (tb == null) return; @@ -188,6 +184,24 @@ public class TouchBarsManager { _setBarContainer(bar); } + synchronized private static void _elevateTouchBar(@NotNull BarContainer bar) { + final BarContainer top = ourTouchBarStack.peek(); + if (top == bar) + return; + + final boolean preserveTop = top != null && (top.isTemporary() || top.get().isManualClose()); + if (preserveTop) { + ourTouchBarStack.remove(bar); + ourTouchBarStack.remove(top); + ourTouchBarStack.push(bar); + ourTouchBarStack.push(top); + } else { + ourTouchBarStack.remove(bar); + ourTouchBarStack.push(bar); + _setBarContainer(bar); + } + } + synchronized public static void closeTouchBar(BarContainer tb) { if (tb == null || ourTouchBarStack.isEmpty()) return;