IDEA-133828 Regression: middle-clicking on tool window header doesn't close it anymore
authorVassiliy.Kudryashov <Vassiliy.Kudryashov@jetbrains.com>
Thu, 5 Mar 2015 12:13:46 +0000 (15:13 +0300)
committerVassiliy.Kudryashov <Vassiliy.Kudryashov@jetbrains.com>
Thu, 5 Mar 2015 12:16:14 +0000 (15:16 +0300)
platform/platform-impl/src/com/intellij/openapi/wm/impl/ToolWindowHeader.java
platform/util/src/com/intellij/ui/MouseForwarder.java [new file with mode: 0644]

index 9e9460e8b896a4b0f8e117ca665f7b4243d4ac36..20f304ea1ae818ecb26e8dfb91615530aec4cf83 100644 (file)
@@ -30,10 +30,7 @@ import com.intellij.openapi.wm.ToolWindow;
 import com.intellij.openapi.wm.ToolWindowAnchor;
 import com.intellij.openapi.wm.ToolWindowType;
 import com.intellij.openapi.wm.impl.content.ToolWindowContentUi;
-import com.intellij.ui.DoubleClickListener;
-import com.intellij.ui.InplaceButton;
-import com.intellij.ui.PopupHandler;
-import com.intellij.ui.UIBundle;
+import com.intellij.ui.*;
 import com.intellij.ui.components.panels.Wrapper;
 import com.intellij.ui.tabs.TabsUtil;
 import com.intellij.util.BitUtil;
@@ -224,6 +221,7 @@ public abstract class ToolWindowHeader extends JPanel implements Disposable, UIS
         return true;
       }
     }.installOn(westPanel);
+    MouseForwarder.installOn(westPanel, this, true);
   }
 
   @Override
diff --git a/platform/util/src/com/intellij/ui/MouseForwarder.java b/platform/util/src/com/intellij/ui/MouseForwarder.java
new file mode 100644 (file)
index 0000000..cb07abf
--- /dev/null
@@ -0,0 +1,70 @@
+package com.intellij.ui;
+
+import com.intellij.openapi.Disposable;
+import org.jetbrains.annotations.NotNull;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+
+public class MouseForwarder implements MouseListener{
+  @NotNull private Component myTarget;
+  private boolean myLater;
+
+  public static Disposable installOn(@NotNull final Component component, @NotNull Component target, boolean later) {
+    final MouseForwarder forwarder = new MouseForwarder(target, later);
+    component.addMouseListener(forwarder);
+    return new Disposable() {
+      @Override
+      public void dispose() {
+        component.removeMouseListener(forwarder);
+      }
+    };
+  }
+
+  private MouseForwarder(@NotNull Component target, boolean later) {
+    myTarget = target;
+    myLater = later;
+  }
+  private void redispatch(final MouseEvent e) {
+    Runnable runnable = new Runnable() {
+      @Override
+      public void run() {
+        myTarget.dispatchEvent(SwingUtilities.convertMouseEvent(e.getComponent(), e, myTarget));
+      }
+    };
+    if (myLater) {
+      //noinspection SSBasedInspection
+      SwingUtilities.invokeLater(runnable);
+    }
+    else {
+      runnable.run();
+    }
+  }
+
+  @Override
+  public void mouseClicked(MouseEvent e) {
+    redispatch(e);
+  }
+
+  @Override
+  public void mousePressed(MouseEvent e) {
+    redispatch(e);
+  }
+
+  @Override
+  public void mouseReleased(MouseEvent e) {
+    redispatch(e);
+  }
+
+  @Override
+  public void mouseEntered(MouseEvent e) {
+    redispatch(e);
+  }
+
+  @Override
+  public void mouseExited(MouseEvent e) {
+    redispatch(e);
+  }
+}