From 25fab69fdf1be216e9beb7528f80e3e12fa900d7 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Sat, 8 Jun 2019 17:41:37 +0200 Subject: [PATCH] init TouchBar only after project open EDT task (part 3 - project registration) GitOrigin-RevId: d016536961a21f78fee81d043dd7876f6bc9887f --- .../src/com/intellij/ide/IdeEventQueue.java | 7 +- .../CustomizableActionsPanel.java | 7 +- .../ui/impl/DialogWrapperPeerImpl.java | 12 +- .../ui/mac/touchbar/TouchBarsManager.java | 103 +++++++++++------- .../intellij/ui/messages/SheetMessage.java | 10 +- 5 files changed, 85 insertions(+), 54 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index 7b87f9d4ba5f..cbba6bf0359c 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -677,10 +677,13 @@ public final class IdeEventQueue extends EventQueue { return; } - if (e instanceof InputEvent) + if (e instanceof InputEvent && SystemInfoRt.isMac) { TouchBarsManager.onInputEvent((InputEvent)e); + } - if (dispatchByCustomDispatchers(e)) return; + if (dispatchByCustomDispatchers(e)) { + return; + } if (e instanceof InputMethodEvent) { if (SystemInfoRt.isMac && myKeyEventDispatcher.isWaitingForSecondKeyStroke()) { diff --git a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.java b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.java index 72a879a07854..ec63e0795b08 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/customization/CustomizableActionsPanel.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.ui.customization; import com.intellij.icons.AllIcons; @@ -19,6 +19,7 @@ import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.ui.TextFieldWithBrowseButton; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.SystemInfoRt; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; @@ -184,7 +185,9 @@ public class CustomizableActionsPanel { restorePathsAfterTreeOptimization(treePaths); CustomActionsSchema.getInstance().copyFrom(mySelectedSchema); CustomActionsSchema.setCustomizationSchemaForCurrentProjects(); - TouchBarsManager.reloadAll(); + if (SystemInfoRt.isMac) { + TouchBarsManager.reloadAll(); + } } private void restorePathsAfterTreeOptimization(final List treePaths) { diff --git a/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java b/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java index be35d6779f61..7f96e60c9f61 100644 --- a/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/ui/impl/DialogWrapperPeerImpl.java @@ -421,9 +421,12 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer { myDialog.getWindow().setAutoRequestFocus(!Registry.is("suppress.focus.stealing")); - final Disposable tb = TouchBarsManager.showDialogWrapperButtons(myDialog.getContentPane()); - if (tb != null) - myDisposeActions.add(() -> Disposer.dispose(tb)); + if (SystemInfoRt.isMac) { + final Disposable tb = TouchBarsManager.showDialogWrapperButtons(myDialog.getContentPane()); + if (tb != null) { + myDisposeActions.add(() -> Disposer.dispose(tb)); + } + } try { myDialog.show(); @@ -433,7 +436,8 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer { commandProcessor.leaveModal(); if (perProjectModality) { LaterInvocator.leaveModal(project, myDialog.getWindow()); - } else { + } + else { LaterInvocator.leaveModal(myDialog); } } 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 86a6e032e657..180dad73e511 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 @@ -26,6 +26,7 @@ import com.intellij.openapi.project.ProjectManagerListener; import com.intellij.openapi.startup.StartupManager; import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.SystemInfoRt; import com.intellij.openapi.wm.ToolWindowId; import com.intellij.ui.mac.TouchbarDataKeys; import com.intellij.ui.popup.list.ListPopupImpl; @@ -63,6 +64,10 @@ public final class TouchBarsManager { registerEditor(editor); } + for (Project project : ProjectManager.getInstance().getOpenProjects()) { + registerProject(project); + } + isInitialized = true; EditorFactory.getInstance().addEditorFactoryListener(new EditorFactoryListener() { @@ -80,42 +85,7 @@ public final class TouchBarsManager { ApplicationManager.getApplication().getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerListener() { @Override public void projectOpened(@NotNull Project project) { - ApplicationManager.getApplication().assertIsDispatchThread(); - // System.out.println("opened project " + project + ", set default touchbar"); - - final ProjectData pd = new ProjectData(project); - synchronized (ourProjectData) { - final ProjectData prev = ourProjectData.put(project, pd); - if (prev != null) { - LOG.error("previous project data wasn't removed: " + project); - prev.releaseAll(); - } - } - - StartupManager.getInstance(project).registerPostStartupActivity(() -> pd.get(BarType.DEFAULT).show()); - - project.getMessageBus().connect().subscribe(ExecutionManager.EXECUTION_TOPIC, new ExecutionListener() { - @Override - public void processStarted(@NotNull String executorId, @NotNull ExecutionEnvironment env, @NotNull ProcessHandler handler) { - ApplicationManager.getApplication().invokeLater(TouchBarsManager::_updateCurrentTouchbar); - } - @Override - public void processTerminated(@NotNull String executorId, @NotNull ExecutionEnvironment env, @NotNull ProcessHandler handler, int exitCode) { - // TODO: probably, need to remove debugger-panel from stack completely - final String twid = env.getExecutor().getToolWindowId(); - ourStack.pop(topContainer -> { - if (topContainer.getType() != BarType.DEBUGGER) - return false; - - if (!ToolWindowId.DEBUG.equals(twid) && !ToolWindowId.RUN_DASHBOARD.equals(twid) && !ToolWindowId.SERVICES.equals(twid)) - return false; - - // System.out.println("processTerminated, dbgSessionsCount=" + pd.getDbgSessions()); - return !_hasAnyActiveSession(project, handler) || pd.getDbgSessions() <= 0; - }); - ApplicationManager.getApplication().invokeLater(TouchBarsManager::_updateCurrentTouchbar); - } - }); + registerProject(project); } @Override @@ -140,11 +110,59 @@ public final class TouchBarsManager { _initExecutorsGroup(); } - public static boolean isTouchBarAvailable() { return NST.isAvailable(); } + private static void registerProject(@NotNull Project project) { + if (project.isDisposed()) { + return; + } + + // System.out.println("opened project " + project + ", set default touchbar"); + + final ProjectData projectData = new ProjectData(project); + synchronized (ourProjectData) { + final ProjectData prev = ourProjectData.put(project, projectData); + if (prev != null) { + LOG.error("previous project data wasn't removed: " + project); + prev.releaseAll(); + } + } + + StartupManager.getInstance(project).registerPostStartupActivity(() -> projectData.get(BarType.DEFAULT).show()); + + project.getMessageBus().connect().subscribe(ExecutionManager.EXECUTION_TOPIC, new ExecutionListener() { + @Override + public void processStarted(@NotNull String executorId, @NotNull ExecutionEnvironment env, @NotNull ProcessHandler handler) { + ApplicationManager.getApplication().invokeLater(TouchBarsManager::_updateCurrentTouchbar); + } + + @Override + public void processTerminated(@NotNull String executorId, @NotNull ExecutionEnvironment env, @NotNull ProcessHandler handler, int exitCode) { + // TODO: probably, need to remove debugger-panel from stack completely + final String twid = env.getExecutor().getToolWindowId(); + ourStack.pop(topContainer -> { + if (topContainer.getType() != BarType.DEBUGGER) { + return false; + } + + if (!ToolWindowId.DEBUG.equals(twid) && !ToolWindowId.RUN_DASHBOARD.equals(twid) && !ToolWindowId.SERVICES.equals(twid)) { + return false; + } + + // System.out.println("processTerminated, dbgSessionsCount=" + pd.getDbgSessions()); + return !_hasAnyActiveSession(project, handler) || projectData.getDbgSessions() <= 0; + }); + ApplicationManager.getApplication().invokeLater(TouchBarsManager::_updateCurrentTouchbar); + } + }); + } + + public static boolean isTouchBarAvailable() { + return SystemInfoRt.isMac && NST.isAvailable(); + } public static void reloadAll() { - if (!isTouchBarAvailable()) + if (!isInitialized || !isTouchBarAvailable()) { return; + } synchronized (ourProjectData) { ourProjectData.forEach((p, pd)->pd.reloadAll()); @@ -153,13 +171,15 @@ public final class TouchBarsManager { } public static void onInputEvent(InputEvent e) { - if (!isTouchBarAvailable()) + if (!isInitialized || !isTouchBarAvailable()) { return; + } // NOTE: skip wheel-events, because scrolling by touchpad produces mouse-wheel events with pressed modifier, example: // MouseWheelEvent[MOUSE_WHEEL,(890,571),absolute(0,0),button=0,modifiers=SHIFT,extModifiers=SHIFT,clickCount=0,scrollType=WHEEL_UNIT_SCROLL,scrollAmount=1,wheelRotation=0,preciseWheelRotation=0.1] on frame0 - if (e instanceof MouseWheelEvent) + if (e instanceof MouseWheelEvent) { return; + } ourStack.updateKeyMask(e.getModifiersEx() & ProjectData.getUsedKeyMask()); } @@ -366,8 +386,9 @@ public final class TouchBarsManager { } public static @Nullable Disposable showDialogWrapperButtons(@NotNull Container contentPane) { - if (!isTouchBarAvailable()) + if (!isTouchBarAvailable()) { return null; + } final ModalityState ms = Utils.getCurrentModalityState(); final BarType btype = ModalityState.NON_MODAL.equals(ms) ? BarType.DIALOG : BarType.MODAL_DIALOG; diff --git a/platform/platform-impl/src/com/intellij/ui/messages/SheetMessage.java b/platform/platform-impl/src/com/intellij/ui/messages/SheetMessage.java index d318800cfd0b..afd1db340067 100755 --- a/platform/platform-impl/src/com/intellij/ui/messages/SheetMessage.java +++ b/platform/platform-impl/src/com/intellij/ui/messages/SheetMessage.java @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ui.messages; import com.apple.eawt.FullScreenUtilities; @@ -19,8 +19,6 @@ import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.lang.ref.WeakReference; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import static com.intellij.openapi.wm.IdeFocusManager.getGlobalInstance; @@ -163,12 +161,14 @@ class SheetMessage implements Disposable { } private void _showTouchBar() { - if (!TouchBarsManager.isTouchBarAvailable()) + if (!TouchBarsManager.isTouchBarAvailable()) { return; + } final Disposable tb = TouchBarsManager.showDialogWrapperButtons(myController.getSheetPanel()); - if (tb != null) + if (tb != null) { Disposer.register(this, tb); + } } private static void maximizeIfNeeded(final Window owner) {