Get rid of PythonConsoleToolWindow, PythonConsoleToolWindowFactory, PythonToolWindowC...
authorfitermay <fiterman@gmail.com>
Mon, 12 Sep 2016 01:59:07 +0000 (21:59 -0400)
committerfitermay <fiterman@gmail.com>
Sun, 18 Sep 2016 00:39:26 +0000 (20:39 -0400)
16 files changed:
platform/lang-api/src/com/intellij/execution/Executor.java
platform/lang-impl/src/com/intellij/execution/runners/AbstractConsoleRunnerWithHistory.java
platform/lang-impl/src/com/intellij/execution/ui/RunContentManagerImpl.java
platform/platform-resources/src/META-INF/LangExtensionPoints.xml
python/educational-python/src/META-INF/PyCharmEduPlugin.xml
python/ide/src/META-INF/PyCharmCorePlugin.xml
python/ide/src/META-INF/pycharm-core.xml
python/src/com/jetbrains/python/actions/PyExecuteSelectionAction.java
python/src/com/jetbrains/python/console/PyConsoleStarter.kt [new file with mode: 0644]
python/src/com/jetbrains/python/console/PyConsoleToolWindowExecutor.java [new file with mode: 0644]
python/src/com/jetbrains/python/console/PydevConsoleRunner.java
python/src/com/jetbrains/python/console/PythonConsoleToolWindow.java [deleted file]
python/src/com/jetbrains/python/console/PythonConsoleToolWindowFactory.java [deleted file]
python/src/com/jetbrains/python/console/PythonConsoleView.java
python/src/com/jetbrains/python/console/PythonToolWindowConsoleRunner.java [deleted file]
python/src/com/jetbrains/python/console/PythonToolWindowConsoleRunnerFactory.java [deleted file]

index 3275cbd5112543dbabd782ed1f0e4f6f15517dc8..d5cec10d5f8420fbeaabd3bc3192e288345e40c5 100644 (file)
@@ -33,6 +33,9 @@ import javax.swing.*;
  */
 public abstract class Executor {
   public static final ExtensionPointName<Executor> EXECUTOR_EXTENSION_NAME = ExtensionPointName.create("com.intellij.executor");
+  /* Extension point for non-user facing executors, in order to use RunContentManager with custom toolwindows */
+  public static final ExtensionPointName<Executor> INTERNAL_EXECUTOR_EXTENSION_NAME =
+    ExtensionPointName.create("com.intellij.internal_executor");
 
   /**
    * Returns the ID of the toolwindow in which the run tabs created by this executor will be displayed.
@@ -41,6 +44,7 @@ public abstract class Executor {
    * {@link com.intellij.openapi.wm.ToolWindowId#DEBUG}).
    */
   public abstract String getToolWindowId();
+
   public abstract Icon getToolWindowIcon();
 
   /**
@@ -70,6 +74,7 @@ public abstract class Executor {
 
   /**
    * Returns the unique ID of the executor.
+   *
    * @return the ID of the executor.
    */
   @NotNull
index 86e3656003613e8824d0b6caa2f6186ed3753295..c99cb450ddf8f7e694fa23675ad7ebe036d2ea0e 100644 (file)
@@ -110,8 +110,12 @@ public abstract class AbstractConsoleRunnerWithHistory<T extends LanguageConsole
     myProcessHandler.startNotify();
   }
 
+  protected Executor getExecutor() {
+    return DefaultRunExecutor.getRunExecutorInstance();
+  }
+
   protected void createContentDescriptorAndActions() {
-    final Executor defaultExecutor = DefaultRunExecutor.getRunExecutorInstance();
+    final Executor defaultExecutor = getExecutor();
     final DefaultActionGroup toolbarActions = new DefaultActionGroup();
     final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, toolbarActions, false);
 
index 189b6fa2a98274001b1f52310a7ddf7c077c9da7..e53676eb12bcbe730eeeb291b485f628ceac36bc 100644 (file)
@@ -30,6 +30,7 @@ import com.intellij.openapi.actionSystem.DataProvider;
 import com.intellij.openapi.actionSystem.PlatformDataKeys;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.diagnostic.Logger;
+import com.intellij.openapi.extensions.Extensions;
 import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.progress.ProgressManager;
 import com.intellij.openapi.progress.Task;
@@ -87,7 +88,11 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
     }
 
     for (Executor executor : ExecutorRegistry.getInstance().getRegisteredExecutors()) {
-      registerToolwindow(executor, toolWindowManager);
+      registerToolwindow(executor, toolWindowManager, true);
+    }
+
+    for (Executor executor : Extensions.getExtensions(Executor.INTERNAL_EXECUTOR_EXTENSION_NAME)) {
+      registerToolwindow(executor, toolWindowManager, false);
     }
 
     toolWindowManager.addToolWindowManagerListener(new ToolWindowManagerAdapter() {
@@ -116,7 +121,9 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
   public void dispose() {
   }
 
-  private void registerToolwindow(@NotNull final Executor executor, @NotNull ToolWindowManagerEx toolWindowManager) {
+  private void registerToolwindow(@NotNull final Executor executor,
+                                  @NotNull ToolWindowManagerEx toolWindowManager,
+                                  boolean autoRemoveOnEmpty) {
     final String toolWindowId = executor.getToolWindowId();
     if (toolWindowManager.getToolWindow(toolWindowId) != null) {
       return;
@@ -146,7 +153,9 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
 
     toolWindow.setIcon(executor.getToolWindowIcon());
     myToolwindowIdToBaseIconMap.put(toolWindowId, executor.getToolWindowIcon());
-    new ContentManagerWatcher(toolWindow, contentManager);
+    if (autoRemoveOnEmpty) {
+      new ContentManagerWatcher(toolWindow, contentManager);
+    }
     contentManager.addContentManagerListener(new ContentManagerAdapter() {
       @Override
       public void selectionChanged(final ContentManagerEvent event) {
@@ -255,7 +264,8 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
     }
 
     final ContentManager contentManager = getContentManagerForRunner(executor);
-    RunContentDescriptor oldDescriptor = chooseReuseContentForDescriptor(contentManager, descriptor, executionId, descriptor.getDisplayName());
+    RunContentDescriptor oldDescriptor =
+      chooseReuseContentForDescriptor(contentManager, descriptor, executionId, descriptor.getDisplayName());
     final Content content;
     if (oldDescriptor == null) {
       content = createNewContent(contentManager, descriptor, executor);
@@ -363,7 +373,9 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
   }
 
   @Override
-  public void showRunContent(@NotNull Executor info, @NotNull RunContentDescriptor descriptor, @Nullable RunContentDescriptor contentToReuse) {
+  public void showRunContent(@NotNull Executor info,
+                             @NotNull RunContentDescriptor descriptor,
+                             @Nullable RunContentDescriptor contentToReuse) {
     copyContentAndBehavior(descriptor, contentToReuse);
     showRunContent(info, descriptor, descriptor.getExecutionId());
   }
@@ -409,7 +421,7 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
       return null;
     }
     final RunContentDescriptor oldDescriptor = getRunContentDescriptorByContent(content);
-    if (oldDescriptor != null && !oldDescriptor.isContentReuseProhibited() ) {
+    if (oldDescriptor != null && !oldDescriptor.isContentReuseProhibited()) {
       //content.setExecutionId(executionId);
       return oldDescriptor;
     }
@@ -608,7 +620,8 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
       }
       final boolean destroyProcess;
       //noinspection deprecation
-      if (processHandler.isSilentlyDestroyOnClose() || Boolean.TRUE.equals(processHandler.getUserData(ProcessHandler.SILENTLY_DESTROY_ON_CLOSE))) {
+      if (processHandler.isSilentlyDestroyOnClose() ||
+          Boolean.TRUE.equals(processHandler.getUserData(ProcessHandler.SILENTLY_DESTROY_ON_CLOSE))) {
         destroyProcess = true;
       }
       else {
@@ -641,7 +654,7 @@ public class RunContentManagerImpl implements RunContentManager, Disposable {
 
       {
         if (killable) {
-          String cancelText= ExecutionBundle.message("terminating.process.progress.kill");
+          String cancelText = ExecutionBundle.message("terminating.process.progress.kill");
           setCancelText(cancelText);
           setCancelTooltipText(cancelText);
         }
index 016b8f89683d21f9ca4b1f4c8d48044ea29af1f6..52ed6952c0c6ac69d6f6a5c69f3e00a6c11c9453 100644 (file)
@@ -9,7 +9,8 @@
     <extensionPoint name="generalCodeStyleOptionsProvider" beanClass="com.intellij.application.options.GeneralCodeStyleOptionsProviderEP">
       <with attribute="instance" implements="com.intellij.application.options.GeneralCodeStyleOptionsProvider"/>
     </extensionPoint>
-    <extensionPoint name="autoImportOptionsProvider" beanClass="com.intellij.application.options.editor.AutoImportOptionsProviderEP" area="IDEA_PROJECT">
+    <extensionPoint name="autoImportOptionsProvider" beanClass="com.intellij.application.options.editor.AutoImportOptionsProviderEP"
+                    area="IDEA_PROJECT">
       <with attribute="instance" implements="com.intellij.application.options.editor.AutoImportOptionsProvider"/>
     </extensionPoint>
     <!--suppress ExtensionPointBeanClass -->
     <extensionPoint name="executor"
                     interface="com.intellij.execution.Executor"/>
 
+    <extensionPoint name="internal_executor"
+                    interface="com.intellij.execution.Executor"/>
+
+
     <extensionPoint name="executionTargetProvider"
                     interface="com.intellij.execution.ExecutionTargetProvider"/>
 
 
     <extensionPoint name="goto.nonProjectScopeDisabler" beanClass="com.intellij.ide.actions.NonProjectScopeDisablerEP"/>
     <extensionPoint name="searchEverywhereClassifier" interface="com.intellij.ide.actions.SearchEverywhereClassifier"/>
-    <extensionPoint qualifiedName="com.intellij.equivalenceDescriptorProvider" interface="com.intellij.dupLocator.equivalence.EquivalenceDescriptorProvider"/>
+    <extensionPoint qualifiedName="com.intellij.equivalenceDescriptorProvider"
+                    interface="com.intellij.dupLocator.equivalence.EquivalenceDescriptorProvider"/>
 
     <extensionPoint name="previewPanelProvider" interface="com.intellij.openapi.preview.PreviewPanelProvider" area="IDEA_PROJECT"/>
     <extensionPoint name="inspectionElementsMerger" interface="com.intellij.codeInspection.ex.InspectionElementsMerger"/>
index 31efe5e5c30e3025246feb3c149250be9dab43f2..79f3dd061d98f17e3a68dfa49b7dca310125a3e0 100644 (file)
     </component>
     <component>
       <interface-class>com.jetbrains.python.console.PythonConsoleRunnerFactory</interface-class>
-      <implementation-class>com.jetbrains.python.console.PythonToolWindowConsoleRunnerFactory</implementation-class>
+      <implementation-class>com.jetbrains.python.console.PydevConsoleRunnerFactory</implementation-class>
     </component>
   </application-components>
 
+  <extensions defaultExtensionNs="com.intellij">
+    <internal_executor id="PyConsoleToolWindowExecutor" implementation="com.jetbrains.python.console.PyConsoleToolWindowExecutor"/>
+    <postStartupActivity implementation="com.jetbrains.python.console.PyConsoleStarter"/>
+
+  </extensions>
+
   <extensions defaultExtensionNs="com.intellij">
       <programRunner implementation="com.jetbrains.python.edu.debugger.PyEduDebugRunner"/>
       <executor implementation="com.jetbrains.python.edu.debugger.PyEduDebugExecutor" order="first,after run"/>
index ac8651e95fadeb7015882834da1087ed40940a33..47ad96b0654579658acf44f6e8802ce67e7bbda2 100644 (file)
@@ -7,10 +7,14 @@
       <implementation-class>com.jetbrains.python.PyCharmInitialConfigurator</implementation-class>
       <headless-implementation-class/>
     </component>
-
     <component>
       <interface-class>com.jetbrains.python.console.PythonConsoleRunnerFactory</interface-class>
-      <implementation-class>com.jetbrains.python.console.PythonToolWindowConsoleRunnerFactory</implementation-class>
+      <implementation-class>com.jetbrains.python.console.PydevConsoleRunnerFactory</implementation-class>
     </component>
+
   </application-components>
+  <extensions defaultExtensionNs="com.intellij">
+    <internal_executor id="PyConsoleToolWindowExecutor" implementation="com.jetbrains.python.console.PyConsoleToolWindowExecutor"/>
+    <postStartupActivity implementation="com.jetbrains.python.console.PyConsoleStarter"/>
+  </extensions>
 </idea-plugin>
index e61485813422ff5b0cbbc8f764e14bee9653ed8c..b01cb9fc6f69b3c105ff2e3373726f1c0628d9ce 100644 (file)
     </component>
   </project-components>
 
-  <project-components>
-    <component>
-      <implementation-class>com.jetbrains.python.console.PythonConsoleToolWindow</implementation-class>
-    </component>
-  </project-components>
 
   <module value="com.intellij.modules.xml"/>
 
@@ -58,7 +53,8 @@
                         serviceImplementation="com.jetbrains.python.PythonModuleTypeManager"/>
 
     <fileStructureGroupRuleProvider implementation="com.intellij.usages.impl.rules.FileGroupingRuleProvider" order="first"/>
-    <fileStructureGroupRuleProvider implementation="com.jetbrains.python.findUsages.PyClassGroupingRuleProvider" order="before py-function"/>
+    <fileStructureGroupRuleProvider implementation="com.jetbrains.python.findUsages.PyClassGroupingRuleProvider"
+                                    order="before py-function"/>
     <diffPreviewProvider implementation="com.jetbrains.python.configuration.PyDiffPreviewProvider"/>
 
     <applicationService serviceInterface="com.jetbrains.python.run.PyCommonOptionsFormFactory"
     <renameHandler implementation="com.intellij.platform.renameProject.ProjectFolderRenameHandler"/>
 
     <!-- Console -->
-    <toolWindow id="Python Console" anchor="bottom" icon="PythonIcons.Python.PythonConsoleToolWindow"
-                factoryClass="com.jetbrains.python.console.PythonConsoleToolWindowFactory" secondary="false"/>
 
     <directoryIndexExcludePolicy implementation="com.jetbrains.python.PyDirectoryIndexExcludePolicy"/>
+
   </extensions>
 
   <actions>
@@ -96,7 +91,7 @@
       <add-to-group group-id="PlatformOpenProjectGroup" anchor="after" relative-to-action="NewDirectoryProject"/>
     </action>
 
-    <action id="SaveAs" class="com.intellij.ide.actions.SaveAsAction" text="Save As.." >
+    <action id="SaveAs" class="com.intellij.ide.actions.SaveAsAction" text="Save As..">
       <add-to-group group-id="FileOpenGroup" anchor="after" relative-to-action="OpenFile"/>
     </action>
 
             icon="AllIcons.RunConfigurations.RerunFailedTests"/>
 
     <group id="WelcomeScreen.Platform.NewProject">
-      <action id="WelcomeScreen.CreateDirectoryProject" class="com.jetbrains.python.newProject.actions.PyCharmNewProjectStep" icon="AllIcons.Welcome.CreateNewProject"/>
+      <action id="WelcomeScreen.CreateDirectoryProject" class="com.jetbrains.python.newProject.actions.PyCharmNewProjectStep"
+              icon="AllIcons.Welcome.CreateNewProject"/>
       <action id="WelcomeScreen.OpenDirectoryProject" class="com.intellij.ide.actions.OpenFileAction" icon="AllIcons.General.OpenProject"/>
 
       <add-to-group group-id="WelcomeScreen.QuickStart" anchor="first"/>
index 08fab4314898a0a834b4b00592d24cba81dbb456..bc00af821211c229f33e3281f70131de83a55f6e 100644 (file)
@@ -33,7 +33,6 @@ import com.intellij.util.Consumer;
 import com.jetbrains.python.console.PyCodeExecutor;
 import com.jetbrains.python.console.PydevConsoleRunner;
 import com.jetbrains.python.console.PythonConsoleRunnerFactory;
-import com.jetbrains.python.console.PythonConsoleToolWindow;
 import com.jetbrains.python.psi.PyFile;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -180,22 +179,9 @@ public class PyExecuteSelectionAction extends AnAction {
   }
 
   private static Collection<RunContentDescriptor> getConsoles(Project project) {
-    PythonConsoleToolWindow toolWindow = PythonConsoleToolWindow.getInstance(project);
 
-    if (toolWindow != null && toolWindow.getToolWindow().isVisible()) {
-      RunContentDescriptor selectedContentDescriptor = toolWindow.getSelectedContentDescriptor();
-      return selectedContentDescriptor != null ? Lists.newArrayList(selectedContentDescriptor) : Lists.<RunContentDescriptor>newArrayList();
-    }
-
-    Collection<RunContentDescriptor> descriptors =
-      ExecutionHelper.findRunningConsole(project, dom -> dom.getExecutionConsole() instanceof PyCodeExecutor && isAlive(dom));
 
-    if (descriptors.isEmpty() && toolWindow != null) {
-      return toolWindow.getConsoleContentDescriptors();
-    }
-    else {
-      return descriptors;
-    }
+    return ExecutionHelper.findRunningConsole(project, dom -> dom.getExecutionConsole() instanceof PyCodeExecutor && isAlive(dom));
   }
 
   private static boolean isAlive(RunContentDescriptor dom) {
@@ -217,33 +203,21 @@ public class PyExecuteSelectionAction extends AnAction {
   private static void startConsole(final Project project,
                                    final Consumer<PyCodeExecutor> consumer,
                                    Module context) {
-    final PythonConsoleToolWindow toolWindow = PythonConsoleToolWindow.getInstance(project);
-
-    if (toolWindow != null) {
-      toolWindow.activate(() -> {
-        List<RunContentDescriptor> descs = toolWindow.getConsoleContentDescriptors();
 
-        RunContentDescriptor descriptor = descs.get(0);
-        if (descriptor != null && descriptor.getExecutionConsole() instanceof PyCodeExecutor) {
-          consumer.consume((PyCodeExecutor)descriptor.getExecutionConsole());
+    PythonConsoleRunnerFactory consoleRunnerFactory = PythonConsoleRunnerFactory.getInstance();
+    PydevConsoleRunner runner = consoleRunnerFactory.createConsoleRunner(project, null);
+    runner.addConsoleListener(new PydevConsoleRunner.ConsoleListener() {
+      @Override
+      public void handleConsoleInitialized(LanguageConsoleView consoleView) {
+        if (consoleView instanceof PyCodeExecutor) {
+          consumer.consume((PyCodeExecutor)consoleView);
         }
-      });
-    }
-    else {
-      PythonConsoleRunnerFactory consoleRunnerFactory = PythonConsoleRunnerFactory.getInstance();
-      PydevConsoleRunner runner = consoleRunnerFactory.createConsoleRunner(project, null);
-      runner.addConsoleListener(new PydevConsoleRunner.ConsoleListener() {
-        @Override
-        public void handleConsoleInitialized(LanguageConsoleView consoleView) {
-          if (consoleView instanceof PyCodeExecutor) {
-            consumer.consume((PyCodeExecutor)consoleView);
-          }
-        }
-      });
-      runner.run();
-    }
+      }
+    });
+    runner.run();
   }
 
+
   private static boolean canFindConsole(AnActionEvent e) {
     Project project = e.getProject();
     if (project != null) {
diff --git a/python/src/com/jetbrains/python/console/PyConsoleStarter.kt b/python/src/com/jetbrains/python/console/PyConsoleStarter.kt
new file mode 100644 (file)
index 0000000..f3e5732
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.jetbrains.python.console
+
+import com.intellij.execution.ExecutionManager
+import com.intellij.ide.util.PropertiesComponent
+import com.intellij.openapi.application.ApplicationManager
+import com.intellij.openapi.application.ModalityState
+import com.intellij.openapi.application.TransactionGuard
+import com.intellij.openapi.project.Project
+import com.intellij.openapi.startup.StartupActivity
+import com.intellij.openapi.util.Condition
+import com.intellij.openapi.wm.ToolWindow
+import com.intellij.openapi.wm.ToolWindowManager
+import com.intellij.openapi.wm.ex.ToolWindowManagerEx
+import com.intellij.openapi.wm.ex.ToolWindowManagerListener
+import com.intellij.openapi.wm.impl.content.ToolWindowContentUi
+import com.intellij.util.Alarm
+
+/**
+ * Created by Yuli Fiterman on 9/12/2016.
+ */
+class PyConsoleStarter : StartupActivity {
+  override fun runActivity(project: Project) {
+    ConsoleStateTracker(project)
+  }
+
+  private class ConsoleStateTracker(private val project: Project) {
+    private val VISIBLE: String = "com.jetbrains.python.console.ToolWindowVisible"
+    private var toolWindowVisible: Boolean = PropertiesComponent.getInstance(project).getBoolean(VISIBLE, false)
+      set(value) {
+        if (value != field) {
+          PropertiesComponent.getInstance(project).setValue(VISIBLE, value, false)
+        }
+        field = value
+      }
+
+    private val toolWindow: ToolWindow?
+      get() {
+        return ToolWindowManager.getInstance(project).getToolWindow(PyConsoleToolWindowExecutor.TOOLWINDOW_ID)
+      }
+
+
+    init {
+      ExecutionManager.getInstance(project).contentManager //Using this for the side effect. Force init
+      toolWindow!!.isAutoHide = false
+      toolWindow!!.isToHideOnEmptyContent = true
+      toolWindow!!.component.putClientProperty(ToolWindowContentUi.HIDE_ID_LABEL, "true")
+
+
+      val tvm = ToolWindowManager.getInstance(project) as ToolWindowManagerEx
+
+      tvm.addToolWindowManagerListener(object : ToolWindowManagerListener {
+        override fun toolWindowRegistered(id: String) {
+        }
+
+        override fun stateChanged() {
+          val toolW = toolWindow ?: return;
+          if (toolW.isVisible && toolW.contentManager.contentCount == 0) {
+            val runner = PythonConsoleRunnerFactory.getInstance().createConsoleRunner(project, null);
+            runner.runSync();
+          }
+          if (toolWindowVisible != toolW.isVisible) {
+            ApplicationManager.getApplication().invokeLater(
+                {
+                  toolWindowVisible = toolWindow?.isVisible ?: false
+                }, ModalityState.NON_MODAL, { !project.isOpen || project.isDisposed })
+
+
+          }
+        }
+      })
+
+
+      if (toolWindowVisible) {
+        toolWindow!!.setAvailable(true) {
+          TransactionGuard.submitTransaction(project, Runnable { toolWindow!!.show(null) })
+
+        }
+      }
+
+    }
+  }
+
+}
diff --git a/python/src/com/jetbrains/python/console/PyConsoleToolWindowExecutor.java b/python/src/com/jetbrains/python/console/PyConsoleToolWindowExecutor.java
new file mode 100644 (file)
index 0000000..fb5a683
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.jetbrains.python.console;
+
+import com.intellij.execution.Executor;
+import com.intellij.openapi.extensions.Extensions;
+import icons.PythonIcons;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import javax.swing.*;
+
+/**
+ * Created by Yuli Fiterman on 9/11/2016.
+ */
+public class PyConsoleToolWindowExecutor extends Executor {
+
+
+  public static final String ID = "PyConsoleToolWindowExecutor";
+  public static final String TOOLWINDOW_ID = "Python Console";
+
+  @Nullable
+  public static PyConsoleToolWindowExecutor findInstance() {
+    for (Executor t : Extensions.getExtensions(INTERNAL_EXECUTOR_EXTENSION_NAME)) {
+      if (PyConsoleToolWindowExecutor.class.isInstance(t)) {
+        return (PyConsoleToolWindowExecutor)t;
+      }
+    }
+
+    return null;
+  }
+
+  @Override
+  public String getToolWindowId() {
+    return TOOLWINDOW_ID;
+  }
+
+  @Override
+  public Icon getToolWindowIcon() {
+    return PythonIcons.Python.PythonConsoleToolWindow;
+  }
+
+  @NotNull
+  @Override
+  public Icon getIcon() {
+    return PythonIcons.Python.PythonConsoleToolWindow;
+  }
+
+  @Override
+  public Icon getDisabledIcon() {
+    return null;
+  }
+
+  @Override
+  public String getDescription() {
+    return null;
+  }
+
+  @NotNull
+  @Override
+  public String getActionName() {
+    return "Run Python Console";
+  }
+
+  @NotNull
+  @Override
+  public String getId() {
+    return ID;
+  }
+
+  @NotNull
+  @Override
+  public String getStartActionText() {
+    return "Starting Python Console";
+  }
+
+  @Override
+  public String getContextActionId() {
+    return "";
+  }
+
+  @Override
+  public String getHelpId() {
+    return null;
+  }
+}
index 938dff0b3344869ce6fae8e363f1720cb00a1a40..787fc78851b1d9b885dff7fb2db8742b001844d6 100644 (file)
@@ -193,6 +193,12 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
     return null;
   }
 
+  @Override
+  protected Executor getExecutor() {
+    PyConsoleToolWindowExecutor toolWindowExecutor = PyConsoleToolWindowExecutor.findInstance();
+    return toolWindowExecutor != null ? toolWindowExecutor : super.getExecutor();
+  }
+
   @NotNull
   public static Pair<Sdk, Module> findPythonSdkAndModule(@NotNull Project project, @Nullable Module contextModule) {
     Sdk sdk = null;
@@ -769,9 +775,6 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
   }
 
 
-
-
-
   private AnAction createBackspaceHandlingAction() {
     final AnAction upAction = new AnAction() {
       @Override
diff --git a/python/src/com/jetbrains/python/console/PythonConsoleToolWindow.java b/python/src/com/jetbrains/python/console/PythonConsoleToolWindow.java
deleted file mode 100644 (file)
index 37de07c..0000000
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright 2000-2014 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.jetbrains.python.console;
-
-import com.google.common.base.Function;
-import com.google.common.base.Predicates;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.Lists;
-import com.intellij.execution.ui.RunContentDescriptor;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.SimpleToolWindowPanel;
-import com.intellij.openapi.util.ActionCallback;
-import com.intellij.openapi.util.Disposer;
-import com.intellij.openapi.util.Key;
-import com.intellij.openapi.wm.ToolWindow;
-import com.intellij.openapi.wm.ToolWindowManager;
-import com.intellij.openapi.wm.ex.ToolWindowManagerEx;
-import com.intellij.openapi.wm.ex.ToolWindowManagerListener;
-import com.intellij.openapi.wm.impl.content.ToolWindowContentUi;
-import com.intellij.ui.content.Content;
-import com.intellij.ui.content.ContentFactory;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import javax.swing.*;
-import java.awt.event.FocusEvent;
-import java.awt.event.FocusListener;
-import java.util.List;
-
-/**
- * @author traff
- */
-public class PythonConsoleToolWindow {
-  public static final Key<RunContentDescriptor> CONTENT_DESCRIPTOR = Key.create("CONTENT_DESCRIPTOR");
-
-  public static final Function<Content, RunContentDescriptor>
-    CONTENT_TO_DESCRIPTOR_FUNCTION = new Function<Content, RunContentDescriptor>() {
-    @Override
-    public RunContentDescriptor apply(@Nullable Content input) {
-      return input != null ? input.getUserData(CONTENT_DESCRIPTOR) : null;
-    }
-  };
-
-  private final Project myProject;
-
-  private boolean myInitialized = false;
-
-  private ActionCallback myActivation = new ActionCallback();
-
-  public PythonConsoleToolWindow(Project project) {
-    myProject = project;
-  }
-
-  public static PythonConsoleToolWindow getInstance(@NotNull Project project) {
-    return project.getComponent(PythonConsoleToolWindow.class);
-  }
-
-  public List<RunContentDescriptor> getConsoleContentDescriptors() {
-    return FluentIterable.from(Lists.newArrayList(getToolWindow().getContentManager().getContents()))
-      .transform(CONTENT_TO_DESCRIPTOR_FUNCTION).filter(
-        Predicates.notNull()).toList();
-  }
-
-
-  public void init(final @NotNull ToolWindow toolWindow, final @NotNull RunContentDescriptor contentDescriptor) {
-    setContent(toolWindow, contentDescriptor);
-
-    if (!myInitialized) {
-      doInit(toolWindow);
-    }
-  }
-
-  private void doInit(@NotNull final ToolWindow toolWindow) {
-    myInitialized = true;
-
-    toolWindow.setToHideOnEmptyContent(true);
-
-    ((ToolWindowManagerEx)ToolWindowManager.getInstance(myProject)).addToolWindowManagerListener(new ToolWindowManagerListener() {
-      @Override
-      public void toolWindowRegistered(@NotNull String id) {
-      }
-
-      @Override
-      public void stateChanged() {
-        ToolWindow window = getToolWindow();
-        if (window != null) {
-          boolean visible = window.isVisible();
-          if (visible && toolWindow.getContentManager().getContentCount() == 0) {
-            PydevConsoleRunner runner = PythonConsoleRunnerFactory.getInstance().createConsoleRunner(myProject, null);
-            runner.run();
-          }
-        }
-      }
-    });
-  }
-
-  private static void setContent(ToolWindow toolWindow, RunContentDescriptor contentDescriptor) {
-    toolWindow.getComponent().putClientProperty(ToolWindowContentUi.HIDE_ID_LABEL, "true");
-
-    Content content = toolWindow.getContentManager().findContent(contentDescriptor.getDisplayName());
-    if (content == null) {
-      content = createContent(contentDescriptor);
-      toolWindow.getContentManager().addContent(content);
-    }
-    else {
-      SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true);
-      resetContent(contentDescriptor, panel, content);
-    }
-
-    toolWindow.getContentManager().setSelectedContent(content);
-  }
-
-  public ToolWindow getToolWindow() {
-    return ToolWindowManager.getInstance(myProject).getToolWindow(PythonConsoleToolWindowFactory.ID);
-  }
-
-  private static Content createContent(final @NotNull RunContentDescriptor contentDescriptor) {
-    SimpleToolWindowPanel panel = new SimpleToolWindowPanel(false, true);
-
-    Content content = ContentFactory.SERVICE.getInstance().createContent(panel, contentDescriptor.getDisplayName(), false);
-    content.setCloseable(true);
-
-    resetContent(contentDescriptor, panel, content);
-
-    return content;
-  }
-
-  private static void resetContent(RunContentDescriptor contentDescriptor, SimpleToolWindowPanel panel, Content content) {
-    RunContentDescriptor oldDescriptor = content.getDisposer() instanceof RunContentDescriptor ? (RunContentDescriptor)content.getDisposer() : null;
-    if (oldDescriptor != null) Disposer.dispose(oldDescriptor);
-
-    panel.setContent(contentDescriptor.getComponent());
-
-    content.setComponent(panel);
-    content.setDisposer(contentDescriptor);
-    content.setPreferredFocusableComponent(contentDescriptor.getComponent());
-
-    content.putUserData(CONTENT_DESCRIPTOR, contentDescriptor);
-  }
-
-  private static FocusListener createFocusListener(final ToolWindow toolWindow) {
-    return new FocusListener() {
-      @Override
-      public void focusGained(FocusEvent e) {
-        JComponent component = getComponentToFocus(toolWindow);
-        if (component != null) {
-          component.requestFocusInWindow();
-        }
-      }
-
-      @Override
-      public void focusLost(FocusEvent e) {
-
-      }
-    };
-  }
-
-  private static JComponent getComponentToFocus(ToolWindow window) {
-    return window.getContentManager().getComponent();
-  }
-
-  public void initialized() {
-    myActivation.setDone();
-  }
-
-  public void activate(@NotNull Runnable runnable) {
-    myActivation.doWhenDone(runnable);
-    getToolWindow().activate(null);
-  }
-
-  @Nullable
-  public RunContentDescriptor getSelectedContentDescriptor() {
-    return CONTENT_TO_DESCRIPTOR_FUNCTION.apply(getToolWindow().getContentManager().getSelectedContent());
-  }
-}
diff --git a/python/src/com/jetbrains/python/console/PythonConsoleToolWindowFactory.java b/python/src/com/jetbrains/python/console/PythonConsoleToolWindowFactory.java
deleted file mode 100644 (file)
index 2a49d5e..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright 2000-2014 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.jetbrains.python.console;
-
-import com.intellij.execution.console.LanguageConsoleView;
-import com.intellij.openapi.project.DumbAware;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.wm.ToolWindow;
-import com.intellij.openapi.wm.ToolWindowFactory;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * @author traff
- */
-public class PythonConsoleToolWindowFactory implements ToolWindowFactory, DumbAware {
-  public static final String ID = "Python Console";
-
-  @Override
-  public void createToolWindowContent(final @NotNull Project project, final @NotNull ToolWindow toolWindow) {
-    PydevConsoleRunner runner = PythonConsoleRunnerFactory.getInstance().createConsoleRunner(project, null);
-    runner.addConsoleListener(new PydevConsoleRunner.ConsoleListener() {
-      @Override
-      public void handleConsoleInitialized(LanguageConsoleView consoleView) {
-        PythonConsoleToolWindow.getInstance(project).initialized();
-      }
-    });
-    runner.run();
-  }
-}
index 3675ab0ad429dfd6e724a321b4904f980fa982c2..71d1e9fa1eab3e10da8a1166468a9b6c99539a2c 100644 (file)
@@ -148,13 +148,8 @@ public class PythonConsoleView extends LanguageConsoleImpl implements Observable
   }
 
   private void showConsole(@NotNull Runnable runnable) {
-    PythonConsoleToolWindow toolWindow = PythonConsoleToolWindow.getInstance(getProject());
-    if (toolWindow != null && toolWindow.getToolWindow() != null && !toolWindow.getToolWindow().isVisible() && !ApplicationManager.getApplication().isUnitTestMode()) {
-      toolWindow.getToolWindow().activate(runnable);
-    }
-    else {
-      runnable.run();
-    }
+
+    runnable.run();
   }
 
   private void doExecute(String code) {
@@ -296,7 +291,7 @@ public class PythonConsoleView extends LanguageConsoleImpl implements Observable
   private void splitWindow() {
     Component console = getComponent(0);
     removeAll();
-    JBSplitter p = new JBSplitter(false, 2f/3);
+    JBSplitter p = new JBSplitter(false, 2f / 3);
     p.setFirstComponent((JComponent)console);
     p.setSecondComponent(mySplitView.getPanel());
     p.setShowDividerControls(true);
diff --git a/python/src/com/jetbrains/python/console/PythonToolWindowConsoleRunner.java b/python/src/com/jetbrains/python/console/PythonToolWindowConsoleRunner.java
deleted file mode 100644 (file)
index bc209aa..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright 2000-2014 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.jetbrains.python.console;
-
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.collect.FluentIterable;
-import com.google.common.collect.Lists;
-import com.intellij.execution.Executor;
-import com.intellij.execution.ui.RunContentDescriptor;
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.projectRoots.Sdk;
-import com.intellij.openapi.wm.ToolWindow;
-import com.intellij.openapi.wm.ToolWindowManager;
-import com.intellij.ui.content.Content;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * @author traff
- */
-public class PythonToolWindowConsoleRunner extends PydevConsoleRunner {
-  private ToolWindow myToolWindow;
-
-  public PythonToolWindowConsoleRunner(@NotNull Project project,
-                                       @NotNull Sdk sdk,
-                                       @NotNull PyConsoleType consoleType,
-                                       @Nullable String workingDir, Map<String, String> environmentVariables,
-                                       @NotNull PyConsoleOptions.PyConsoleSettings settingsProvider,
-                                       String... statementsToExecute) {
-    super(project, sdk, consoleType, workingDir, environmentVariables, settingsProvider, statementsToExecute);
-  }
-
-  @Override
-  public void open() {
-    getToolWindow().activate(() -> {
-    }, true);
-  }
-
-  public ToolWindow getToolWindow() {
-    if (myToolWindow == null) {
-      myToolWindow = ToolWindowManager.getInstance(getProject()).getToolWindow(PythonConsoleToolWindowFactory.ID);
-    }
-    return myToolWindow;
-  }
-
-  @Override
-  protected void showConsole(Executor defaultExecutor, @NotNull RunContentDescriptor contentDescriptor) {
-    PythonConsoleToolWindow consoleToolWindow = PythonConsoleToolWindow.getInstance(getProject());
-    consoleToolWindow.init(getToolWindow(), contentDescriptor);
-  }
-
-  @Override
-  protected void clearContent(RunContentDescriptor descriptor) {
-    Content content = getToolWindow().getContentManager().findContent(descriptor.getDisplayName());
-    assert content != null;
-    getToolWindow().getContentManager().removeContent(content, true);
-  }
-
-  @Override
-  protected List<String> getActiveConsoleNames(final String consoleTitle) {
-    return FluentIterable.from(
-      Lists.newArrayList(PythonConsoleToolWindow.getInstance(getProject()).getToolWindow().getContentManager().getContents())).transform(
-      new Function<Content, String>() {
-        @Override
-        public String apply(Content input) {
-          return input.getDisplayName();
-        }
-      }).filter(new Predicate<String>() {
-      @Override
-      public boolean apply(String input) {
-        return input.contains(consoleTitle);
-      }
-    }).toList();
-  }
-}
diff --git a/python/src/com/jetbrains/python/console/PythonToolWindowConsoleRunnerFactory.java b/python/src/com/jetbrains/python/console/PythonToolWindowConsoleRunnerFactory.java
deleted file mode 100644 (file)
index 9ce9d58..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2000-2014 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.jetbrains.python.console;
-
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.projectRoots.Sdk;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.Map;
-
-/**
- * @author traff
- */
-public class PythonToolWindowConsoleRunnerFactory extends PydevConsoleRunnerFactory {
-  @Override
-  protected PydevConsoleRunner createConsoleRunner(Project project,
-                                                   Sdk sdk,
-                                                   String workingDir,
-                                                   Map<String, String> envs, PyConsoleType consoleType,
-                                                   @NotNull PyConsoleOptions.PyConsoleSettings settingsProvider, String... setupFragment) {
-    return new PythonToolWindowConsoleRunner(project, sdk, consoleType, workingDir, envs, settingsProvider, setupFragment);
-  }
-}