Add new action: Maximize/Restore Active Dialog
authorVassiliy.Kudryashov <Vassiliy.Kudryashov@jetbrains.com>
Mon, 24 Oct 2016 14:39:30 +0000 (17:39 +0300)
committerVassiliy.Kudryashov <Vassiliy.Kudryashov@jetbrains.com>
Mon, 24 Oct 2016 15:09:14 +0000 (18:09 +0300)
platform/platform-impl/src/com/intellij/ide/actions/MaximizeActiveDialog.java [new file with mode: 0644]
platform/platform-resources/src/idea/PlatformActions.xml

diff --git a/platform/platform-impl/src/com/intellij/ide/actions/MaximizeActiveDialog.java b/platform/platform-impl/src/com/intellij/ide/actions/MaximizeActiveDialog.java
new file mode 100644 (file)
index 0000000..1c0f412
--- /dev/null
@@ -0,0 +1,42 @@
+package com.intellij.ide.actions;
+
+import com.intellij.openapi.actionSystem.AnActionEvent;
+import com.intellij.openapi.project.DumbAwareAction;
+import com.intellij.ui.ScreenUtil;
+
+import javax.swing.FocusManager;
+import javax.swing.*;
+import java.awt.*;
+
+public class MaximizeActiveDialog extends DumbAwareAction {
+  {
+    setEnabledInModalContext(true);
+  }
+
+  @Override
+  public void actionPerformed(AnActionEvent e) {
+    Window window = FocusManager.getCurrentManager().getActiveWindow();
+    if (window instanceof JDialog && ((JDialog)window).isResizable()) {
+      JDialog d = (JDialog)window;
+      JRootPane rootPane = d.getRootPane();
+      if (rootPane == null) return;
+      Rectangle screenRectangle = ScreenUtil.getScreenRectangle(d);
+
+
+      if (d.getBounds().equals(screenRectangle)) {
+        //We have to restore normal state
+        Object value = rootPane.getClientProperty("NORMAL_BOUNDS");
+        if (value instanceof Rectangle) {
+          Rectangle bounds = (Rectangle)value;
+          ScreenUtil.fitToScreen(bounds);
+          d.setBounds(bounds);
+          rootPane.putClientProperty("NORMAL_BOUNDS", null);
+        }
+      }
+      else {
+        rootPane.putClientProperty("NORMAL_BOUNDS", d.getBounds());
+        d.setBounds(screenRectangle);
+      }
+    }
+  }
+}
index 81f55d0afab1404d7460bb38d2cbdecd6fee8653..c8d0120fe6cc45757e34a6af447d97cd454cabb2 100644 (file)
     <action id="DecrementWindowWidth" class="com.intellij.ide.actions.WindowAction$DecrementWidth" use-shortcut-of="ResizeToolWindowLeft"/>
     <action id="IncrementWindowHeight" class="com.intellij.ide.actions.WindowAction$IncrementHeight" use-shortcut-of="ResizeToolWindowDown"/>
     <action id="DecrementWindowHeight" class="com.intellij.ide.actions.WindowAction$DecrementHeight" use-shortcut-of="ResizeToolWindowUp"/>
+    <action id="MaximizeActiveDialog" class="com.intellij.ide.actions.MaximizeActiveDialog" text="Maximize/Restore Active Dialog"/>
 
     <action id="ExportTestResults" class="com.intellij.execution.testframework.export.ExportTestResultsAction" icon="AllIcons.Actions.Export"/>