Merge remote-tracking branch 'origin/master'
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Mon, 11 Aug 2014 17:38:57 +0000 (19:38 +0200)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Mon, 11 Aug 2014 17:38:57 +0000 (19:38 +0200)
18 files changed:
python/gen/icons/PythonIcons.java
python/pluginResources/META-INF/plugin.xml
python/pluginSrc/META-INF/python-plugin-core.xml
python/pluginSrc/com/jetbrains/python/run/RunPythonConsoleAction.java
python/resources/icons/com/jetbrains/python/pythonConsole.png [new file with mode: 0644]
python/resources/icons/com/jetbrains/python/pythonConsole@2x.png [new file with mode: 0644]
python/resources/icons/com/jetbrains/python/pythonConsole@2x_dark.png [new file with mode: 0644]
python/resources/icons/com/jetbrains/python/pythonConsole_dark.png [new file with mode: 0644]
python/src/META-INF/PyCharmCorePlugin.xml
python/src/META-INF/pycharm-community.xml [new file with mode: 0644]
python/src/com/jetbrains/python/actions/PyExecuteSelectionAction.java
python/src/com/jetbrains/python/console/PydevConsoleRunner.java
python/src/com/jetbrains/python/console/PydevConsoleRunnerFactory.java [new file with mode: 0644]
python/src/com/jetbrains/python/console/PythonConsoleRunnerFactory.java [new file with mode: 0644]
python/src/com/jetbrains/python/console/PythonConsoleToolWindow.java
python/src/com/jetbrains/python/console/PythonConsoleToolWindowFactory.java
python/src/com/jetbrains/python/console/PythonToolWindowConsoleRunner.java
python/src/com/jetbrains/python/console/PythonToolWindowConsoleRunnerFactory.java [new file with mode: 0644]

index 268a92fc5166af6aa5bfceeb2626ca1eedbbea13..f98387fedc293a3546db8738803f6b91f3a00516 100644 (file)
@@ -49,6 +49,7 @@ public class PythonIcons {
     public static final Icon Python = load("/icons/com/jetbrains/python/python.png"); // 16x16
     public static final Icon Python_24 = load("/icons/com/jetbrains/python/python_24.png"); // 24x24
     public static final Icon PythonClosed = load("/icons/com/jetbrains/python/pythonClosed.png"); // 16x16
+    public static final Icon PythonConsole = load("/icons/com/jetbrains/python/pythonConsole.png"); // 16x16
     public static final Icon PythonConsoleToolWindow = load("/icons/com/jetbrains/python/pythonConsoleToolWindow.png"); // 13x13
     public static final Icon PythonTests = load("/icons/com/jetbrains/python/pythonTests.png"); // 16x16
     public static final Icon TemplateRoot = load("/icons/com/jetbrains/python/templateRoot.png"); // 16x16
index 31f714c875a8111bc25bd1cd9579e95b4593602a..4539edaa107bb4ae7f08911fc208ed24ae4efa66 100644 (file)
@@ -22,4 +22,11 @@ The Python plug-in provides smart editing for Python scripts. The feature set of
   <vendor url="http://www.jetbrains.com/pycharm/" logo="/com/jetbrains/python/python.png">JetBrains</vendor>
   <xi:include href="/META-INF/python-core.xml" xpointer="xpointer(/idea-plugin/*)"/>
   <xi:include href="/META-INF/python-plugin-core.xml" xpointer="xpointer(/idea-plugin/*)"/>
+
+  <application-components>
+    <component>
+      <interface-class>com.jetbrains.python.console.PythonConsoleRunnerFactory</interface-class>
+      <implementation-class>com.jetbrains.python.console.PydevConsoleRunnerFactory</implementation-class>
+    </component>
+  </application-components>
 </idea-plugin>
index 428ddf37b83ed2a66fa800b3be7903d298a84cf4..d797dc8138d2ba522c086ec41d24b9d8c5022acd 100644 (file)
@@ -40,6 +40,7 @@
       <add-to-group group-id="ToolsMenu" anchor="last"/>
     </action>
 
+    <!-- Console -->
     <action id="com.jetbrains.python.run.RunPythonConsoleAction"
             class="com.jetbrains.python.run.RunPythonConsoleAction"
             text="Run Python Console..." description="Allows to quickly run Python console">
index 9fc88f65b42180f4908324c20789abb1e7975916..6b9e631a83f8d9350419391bb9b2077a4abf67f3 100644 (file)
@@ -25,6 +25,7 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.projectRoots.Sdk;
 import com.intellij.openapi.util.Pair;
 import com.jetbrains.python.console.PydevConsoleRunner;
+import com.jetbrains.python.console.PythonConsoleRunnerFactory;
 import icons.PythonIcons;
 
 /**
@@ -34,7 +35,7 @@ public class RunPythonConsoleAction extends AnAction implements DumbAware {
 
   public RunPythonConsoleAction() {
     super();
-    getTemplatePresentation().setIcon(PythonIcons.Python.Python);
+    getTemplatePresentation().setIcon(PythonIcons.Python.PythonConsole);
   }
 
   @Override
@@ -51,6 +52,7 @@ public class RunPythonConsoleAction extends AnAction implements DumbAware {
   }
 
   public void actionPerformed(final AnActionEvent e) {
-    PydevConsoleRunner.runPythonConsole(e.getData(CommonDataKeys.PROJECT), e.getData(LangDataKeys.MODULE), PydevConsoleRunner.factory());
+    PydevConsoleRunner runner = PythonConsoleRunnerFactory.getInstance().createConsoleRunner(e.getData(CommonDataKeys.PROJECT), e.getData(LangDataKeys.MODULE));
+    runner.run();
   }
 }
diff --git a/python/resources/icons/com/jetbrains/python/pythonConsole.png b/python/resources/icons/com/jetbrains/python/pythonConsole.png
new file mode 100644 (file)
index 0000000..74231f2
Binary files /dev/null and b/python/resources/icons/com/jetbrains/python/pythonConsole.png differ
diff --git a/python/resources/icons/com/jetbrains/python/pythonConsole@2x.png b/python/resources/icons/com/jetbrains/python/pythonConsole@2x.png
new file mode 100644 (file)
index 0000000..77922c7
Binary files /dev/null and b/python/resources/icons/com/jetbrains/python/pythonConsole@2x.png differ
diff --git a/python/resources/icons/com/jetbrains/python/pythonConsole@2x_dark.png b/python/resources/icons/com/jetbrains/python/pythonConsole@2x_dark.png
new file mode 100644 (file)
index 0000000..24167e3
Binary files /dev/null and b/python/resources/icons/com/jetbrains/python/pythonConsole@2x_dark.png differ
diff --git a/python/resources/icons/com/jetbrains/python/pythonConsole_dark.png b/python/resources/icons/com/jetbrains/python/pythonConsole_dark.png
new file mode 100644 (file)
index 0000000..9cdc3ac
Binary files /dev/null and b/python/resources/icons/com/jetbrains/python/pythonConsole_dark.png differ
index a250bdc539d7cdb3646045394021a37cd391703d..99a39a1d0cc7ba82d5e7181b55ff9059e1fdc91d 100644 (file)
@@ -1,4 +1,4 @@
 <idea-plugin version="2" xmlns:xi="http://www.w3.org/2001/XInclude">
-  <xi:include href="/META-INF/pycharm-core.xml" xpointer="xpointer(/idea-plugin/*)"/>
+  <xi:include href="/META-INF/pycharm-community.xml" xpointer="xpointer(/idea-plugin/*)"/>
   <xi:include href="/META-INF/python-core.xml" xpointer="xpointer(/idea-plugin/*)"/>
 </idea-plugin>
diff --git a/python/src/META-INF/pycharm-community.xml b/python/src/META-INF/pycharm-community.xml
new file mode 100644 (file)
index 0000000..6851857
--- /dev/null
@@ -0,0 +1,11 @@
+<idea-plugin version="2" xmlns:xi="http://www.w3.org/2001/XInclude">
+  <!-- Components and extensions declared in this file work ONLY in PyCharm, not in Python plugin. -->
+  <xi:include href="/META-INF/pycharm-core.xml" xpointer="xpointer(/idea-plugin/*)"/>
+
+  <application-components>
+    <component>
+      <interface-class>com.jetbrains.python.console.PythonConsoleRunnerFactory</interface-class>
+      <implementation-class>com.jetbrains.python.console.PythonToolWindowConsoleRunnerFactory</implementation-class>
+    </component>
+  </application-components>
+</idea-plugin>
index f31082c07dc279fc21b12e40ee7532489a98bff3..4aea63a8a19638fc5273d85667bdd28c07c50785 100644 (file)
@@ -32,6 +32,7 @@ import com.intellij.util.Consumer;
 import com.intellij.util.NotNullFunction;
 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;
@@ -237,7 +238,8 @@ public class PyExecuteSelectionAction extends AnAction {
       });
     }
     else {
-      PydevConsoleRunner runner = PydevConsoleRunner.runPythonConsole(project, context, PydevConsoleRunner.factory());
+      PythonConsoleRunnerFactory consoleRunnerFactory = PythonConsoleRunnerFactory.getInstance();
+      PydevConsoleRunner runner = consoleRunnerFactory.createConsoleRunner(project, null);
       runner.addConsoleListener(new PydevConsoleRunner.ConsoleListener() {
         @Override
         public void handleConsoleInitialized(LanguageConsoleView consoleView) {
@@ -246,6 +248,7 @@ public class PyExecuteSelectionAction extends AnAction {
           }
         }
       });
+      runner.run();
     }
   }
 
index 8b01ad2f9f07076dabc0e61ce196cf9a77600b54..b3ebacd83ae335eaa37b166deee60f73cc7ea7c0 100644 (file)
@@ -56,14 +56,12 @@ import com.intellij.openapi.project.DumbAware;
 import com.intellij.openapi.project.DumbAwareAction;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.projectRoots.Sdk;
-import com.intellij.openapi.roots.ModuleRootManager;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.Couple;
 import com.intellij.openapi.util.Key;
 import com.intellij.openapi.util.Pair;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.io.StreamUtil;
-import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vfs.CharsetToolkit;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.openapi.vfs.encoding.EncodingManager;
@@ -83,7 +81,6 @@ import com.intellij.xdebugger.XDebugProcessStarter;
 import com.intellij.xdebugger.XDebugSession;
 import com.intellij.xdebugger.XDebuggerManager;
 import com.jetbrains.python.PythonHelpersLocator;
-import com.jetbrains.python.buildout.BuildoutFacet;
 import com.jetbrains.python.console.completion.PydevConsoleElement;
 import com.jetbrains.python.console.parsing.PythonConsoleData;
 import com.jetbrains.python.console.pydev.ConsoleCommunication;
@@ -96,7 +93,6 @@ import com.jetbrains.python.run.ProcessRunner;
 import com.jetbrains.python.run.PythonCommandLineState;
 import com.jetbrains.python.run.PythonTracebackFilter;
 import com.jetbrains.python.sdk.PySdkUtil;
-import com.jetbrains.python.sdk.PythonEnvUtil;
 import com.jetbrains.python.sdk.PythonSdkType;
 import com.jetbrains.python.sdk.flavors.PythonSdkFlavor;
 import icons.PythonIcons;
@@ -149,96 +145,23 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
 
   private String myConsoleTitle = null;
 
-  protected PydevConsoleRunner(@NotNull final Project project,
+  public PydevConsoleRunner(@NotNull final Project project,
                                @NotNull Sdk sdk, @NotNull final PyConsoleType consoleType,
                                @Nullable final String workingDir,
-                               Map<String, String> environmentVariables, String[] statementsToExecute) {
+                               Map<String, String> environmentVariables, String ... statementsToExecute) {
     super(project, consoleType.getTitle(), workingDir);
     mySdk = sdk;
     myConsoleType = consoleType;
     myEnvironmentVariables = environmentVariables;
+    myStatementsToExecute = statementsToExecute;
   }
 
-  @NotNull
-  public static PydevConsoleRunner runPythonConsole(@NotNull Project project,
-                                                    @Nullable Module contextModule,
-                                                    @NotNull PythonConsoleRunnerFactory runnerFactory) {
-    Pair<Sdk, Module> sdkAndModule = findPythonSdkAndModule(project, contextModule);
-
-    Module module = sdkAndModule.second;
-    Sdk sdk = sdkAndModule.first;
-
-    assert sdk != null;
-
-    PathMappingSettings mappingSettings = getMappings(project, sdk);
-
-    String[] setupFragment;
-
-    PyConsoleOptions.PyConsoleSettings settingsProvider = PyConsoleOptions.getInstance(project).getPythonConsoleSettings();
-    Collection<String> pythonPath = PythonCommandLineState.collectPythonPath(module, settingsProvider.addContentRoots(),
-                                                                             settingsProvider.addSourceRoots());
-
-    if (mappingSettings != null) {
-      pythonPath = mappingSettings.convertToRemote(pythonPath);
-    }
-
-    String customStartScript = settingsProvider == null ? "" : settingsProvider.getCustomStartScript();
-
-    if (customStartScript.trim().length() > 0) {
-      customStartScript = "\n" + customStartScript;
-    }
-
-    String selfPathAppend = constructPythonPathCommand(pythonPath, customStartScript);
-
-    String workingDir = settingsProvider.getWorkingDirectory();
-    if (StringUtil.isEmpty(workingDir)) {
-      if (module != null && ModuleRootManager.getInstance(module).getContentRoots().length > 0) {
-        workingDir = ModuleRootManager.getInstance(module).getContentRoots()[0].getPath();
-      }
-      else {
-        if (ModuleManager.getInstance(project).getModules().length > 0) {
-          VirtualFile[] roots = ModuleRootManager.getInstance(ModuleManager.getInstance(project).getModules()[0]).getContentRoots();
-          if (roots.length > 0) {
-            workingDir = roots[0].getPath();
-          }
-        }
-      }
-    }
-
-    if (mappingSettings != null) {
-      workingDir = mappingSettings.convertToRemote(workingDir);
-    }
-
-    BuildoutFacet facet = null;
-    if (module != null) {
-      facet = BuildoutFacet.getInstance(module);
-    }
-
-    if (facet != null) {
-      List<String> path = facet.getAdditionalPythonPath();
-      if (mappingSettings != null) {
-        path = mappingSettings.convertToRemote(path);
-      }
-      String prependStatement = facet.getPathPrependStatement(path);
-      setupFragment = new String[]{prependStatement, selfPathAppend};
-    }
-    else {
-      setupFragment = new String[]{selfPathAppend};
-    }
-
-    Map<String, String> envs = Maps.newHashMap(settingsProvider.getEnvs());
-    String ipythonEnabled = PyConsoleOptions.getInstance(project).isIpythonEnabled() ? "True" : "False";
-    envs.put(PythonEnvUtil.IPYTHONENABLE, ipythonEnabled);
-
-    return createAndRun(runnerFactory, project, sdk, PyConsoleType.PYTHON, workingDir, envs, setupFragment);
-  }
-
-
   public static PathMappingSettings getMappings(Project project, Sdk sdk) {
     PathMappingSettings mappingSettings = null;
     if (PySdkUtil.isRemote(sdk)) {
       PythonRemoteInterpreterManager instance = PythonRemoteInterpreterManager.getInstance();
       if (instance != null) {
+        //noinspection ConstantConditions
         mappingSettings =
           instance.setupMappings(project, (PyRemoteSdkAdditionalDataBase)sdk.getSdkAdditionalData(), null);
       }
@@ -247,7 +170,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
   }
 
   @NotNull
-  public static Pair<Sdk, Module> findPythonSdkAndModule(Project project, Module contextModule) {
+  public static Pair<Sdk, Module> findPythonSdkAndModule(@NotNull Project project, @Nullable Module contextModule) {
     Sdk sdk = null;
     Module module = null;
     PyConsoleOptions.PyConsoleSettings settings = PyConsoleOptions.getInstance(project).getPythonConsoleSettings();
@@ -358,20 +281,6 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
     return actions;
   }
 
-  @NotNull
-  public static PydevConsoleRunner createAndRun(@NotNull PythonConsoleRunnerFactory runnerFactory,
-                                                @NotNull final Project project,
-                                                @NotNull final Sdk sdk,
-                                                @NotNull final PyConsoleType consoleType,
-                                                @Nullable final String workingDirectory,
-                                                @NotNull final Map<String, String> environmentVariables,
-                                                final String... statements2execute) {
-    final PydevConsoleRunner consoleRunner =
-      runnerFactory.createConsoleRunner(project, sdk, consoleType, workingDirectory, environmentVariables, statements2execute);
-    consoleRunner.run();
-    return consoleRunner;
-  }
-
   public void run() {
     UIUtil.invokeAndWaitIfNeeded(new Runnable() {
       @Override
@@ -1089,26 +998,6 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory<PythonC
   }
 
   public static PythonConsoleRunnerFactory factory() {
-    return new PythonConsoleRunnerFactory() {
-      @Override
-      public PydevConsoleRunner createConsoleRunner(@NotNull Project project,
-                                                    @NotNull Sdk sdk,
-                                                    @NotNull PyConsoleType consoleType,
-                                                    @Nullable String workingDirectory,
-                                                    @NotNull Map<String, String> environmentVariables,
-                                                    String... statements2execute) {
-        return new PydevConsoleRunner(project, sdk, consoleType, workingDirectory, environmentVariables, statements2execute);
-      }
-    };
-  }
-
-
-  public interface PythonConsoleRunnerFactory {
-    PydevConsoleRunner createConsoleRunner(@NotNull final Project project,
-                                           @NotNull final Sdk sdk,
-                                           @NotNull final PyConsoleType consoleType,
-                                           @Nullable final String workingDirectory,
-                                           @NotNull final Map<String, String> environmentVariables,
-                                           final String... statements2execute);
+    return new PydevConsoleRunnerFactory();
   }
 }
diff --git a/python/src/com/jetbrains/python/console/PydevConsoleRunnerFactory.java b/python/src/com/jetbrains/python/console/PydevConsoleRunnerFactory.java
new file mode 100644 (file)
index 0000000..5bed751
--- /dev/null
@@ -0,0 +1,122 @@
+/*
+ * 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.collect.Maps;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.module.ModuleManager;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.projectRoots.Sdk;
+import com.intellij.openapi.roots.ModuleRootManager;
+import com.intellij.openapi.util.Pair;
+import com.intellij.openapi.util.text.StringUtil;
+import com.intellij.openapi.vfs.VirtualFile;
+import com.intellij.util.PathMappingSettings;
+import com.jetbrains.python.buildout.BuildoutFacet;
+import com.jetbrains.python.run.PythonCommandLineState;
+import com.jetbrains.python.sdk.PythonEnvUtil;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+/**
+* @author traff
+*/
+public class PydevConsoleRunnerFactory extends PythonConsoleRunnerFactory {
+  @Override
+  public PydevConsoleRunner createConsoleRunner(@NotNull Project project,
+                                                @Nullable Module contextModule) {
+    Pair<Sdk, Module> sdkAndModule = PydevConsoleRunner.findPythonSdkAndModule(project, contextModule);
+
+    Module module = sdkAndModule.second;
+    Sdk sdk = sdkAndModule.first;
+
+    assert sdk != null;
+
+    PathMappingSettings mappingSettings = PydevConsoleRunner.getMappings(project, sdk);
+
+    String[] setupFragment;
+
+    PyConsoleOptions.PyConsoleSettings settingsProvider = PyConsoleOptions.getInstance(project).getPythonConsoleSettings();
+    Collection<String> pythonPath = PythonCommandLineState.collectPythonPath(module, settingsProvider.addContentRoots(),
+                                                                             settingsProvider.addSourceRoots());
+
+    if (mappingSettings != null) {
+      pythonPath = mappingSettings.convertToRemote(pythonPath);
+    }
+
+    String customStartScript = settingsProvider == null ? "" : settingsProvider.getCustomStartScript();
+
+    if (customStartScript.trim().length() > 0) {
+      customStartScript = "\n" + customStartScript;
+    }
+
+    String selfPathAppend = PydevConsoleRunner.constructPythonPathCommand(pythonPath, customStartScript);
+
+    String workingDir = settingsProvider.getWorkingDirectory();
+    if (StringUtil.isEmpty(workingDir)) {
+      if (module != null && ModuleRootManager.getInstance(module).getContentRoots().length > 0) {
+        workingDir = ModuleRootManager.getInstance(module).getContentRoots()[0].getPath();
+      }
+      else {
+        if (ModuleManager.getInstance(project).getModules().length > 0) {
+          VirtualFile[] roots = ModuleRootManager.getInstance(ModuleManager.getInstance(project).getModules()[0]).getContentRoots();
+          if (roots.length > 0) {
+            workingDir = roots[0].getPath();
+          }
+        }
+      }
+    }
+
+    if (mappingSettings != null) {
+      workingDir = mappingSettings.convertToRemote(workingDir);
+    }
+
+    BuildoutFacet facet = null;
+    if (module != null) {
+      facet = BuildoutFacet.getInstance(module);
+    }
+
+    if (facet != null) {
+      List<String> path = facet.getAdditionalPythonPath();
+      if (mappingSettings != null) {
+        path = mappingSettings.convertToRemote(path);
+      }
+      String prependStatement = facet.getPathPrependStatement(path);
+      setupFragment = new String[]{prependStatement, selfPathAppend};
+    }
+    else {
+      setupFragment = new String[]{selfPathAppend};
+    }
+
+    Map<String, String> envs = Maps.newHashMap(settingsProvider.getEnvs());
+    String ipythonEnabled = PyConsoleOptions.getInstance(project).isIpythonEnabled() ? "True" : "False";
+    envs.put(PythonEnvUtil.IPYTHONENABLE, ipythonEnabled);
+
+
+    return createConsoleRunner(project, sdk, workingDir, envs, PyConsoleType.PYTHON, setupFragment);
+  }
+
+  protected PydevConsoleRunner createConsoleRunner(Project project,
+                                                   Sdk sdk,
+                                                   String workingDir,
+                                                   Map<String, String> envs, PyConsoleType consoleType, String ... setupFragment) {
+    return new PydevConsoleRunner(project, sdk, consoleType, workingDir, envs, setupFragment);
+  }
+}
diff --git a/python/src/com/jetbrains/python/console/PythonConsoleRunnerFactory.java b/python/src/com/jetbrains/python/console/PythonConsoleRunnerFactory.java
new file mode 100644 (file)
index 0000000..0963865
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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.components.ServiceManager;
+import com.intellij.openapi.module.Module;
+import com.intellij.openapi.project.Project;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+* @author traff
+*/
+public abstract class PythonConsoleRunnerFactory {
+  @NotNull
+  public static PythonConsoleRunnerFactory getInstance() {
+    return ServiceManager.getService(PythonConsoleRunnerFactory.class);
+  }
+  public abstract PydevConsoleRunner createConsoleRunner(@NotNull final Project project,
+                                         @Nullable Module contextModule);
+}
index 481d9269f4c1a7cbcc362dfa311a927296363a7b..177c3528496f7b29f655557f5f7ff36fe40a6a31 100644 (file)
@@ -6,7 +6,6 @@ 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.projectRoots.Sdk;
 import com.intellij.openapi.ui.SimpleToolWindowPanel;
 import com.intellij.openapi.util.ActionCallback;
 import com.intellij.openapi.util.Key;
@@ -24,7 +23,6 @@ import javax.swing.*;
 import java.awt.event.FocusEvent;
 import java.awt.event.FocusListener;
 import java.util.List;
-import java.util.Map;
 
 /**
  * @author traff
@@ -82,30 +80,14 @@ public class PythonConsoleToolWindow {
         if (window != null) {
           boolean visible = window.isVisible();
           if (visible && toolWindow.getContentManager().getContentCount() == 0) {
-            PydevConsoleRunner.runPythonConsole(myProject, null, toolWindowConsole(window));
+            PydevConsoleRunner runner = PythonConsoleRunnerFactory.getInstance().createConsoleRunner(myProject, null);
+            runner.run();
           }
         }
       }
     });
   }
 
-  public static PydevConsoleRunner.PythonConsoleRunnerFactory toolWindowConsole(@Nullable final ToolWindow toolWindow) {
-    return new PydevConsoleRunner.PythonConsoleRunnerFactory() {
-      @Override
-      public PydevConsoleRunner createConsoleRunner(@NotNull Project project,
-                                                    @NotNull Sdk sdk,
-                                                    @NotNull PyConsoleType consoleType,
-                                                    @Nullable String workingDirectory,
-                                                    @NotNull Map<String, String> environmentVariables,
-                                                    String... statements2execute) {
-        PythonToolWindowConsoleRunner consoleRunner =
-          new PythonToolWindowConsoleRunner(project, sdk, consoleType, workingDirectory, environmentVariables, statements2execute);
-        consoleRunner.setToolWindow(toolWindow);
-        return consoleRunner;
-      }
-    };
-  }
-
   private static void addContent(ToolWindow toolWindow, RunContentDescriptor contentDescriptor) {
     toolWindow.getComponent().putClientProperty(ToolWindowContentUi.HIDE_ID_LABEL, "true");
 
@@ -171,10 +153,6 @@ public class PythonConsoleToolWindow {
     myActivation.setDone();
   }
 
-  public ActionCallback getActivation() {
-    return myActivation;
-  }
-
   public void activate(@NotNull Runnable runnable) {
     myActivation.doWhenDone(runnable);
     getToolWindow().activate(null);
index 816e95d7b19605677278596f717a0356eed3f304..2a49d5efedd3d4832dd6eca5471e9548287b0cde 100644 (file)
@@ -30,12 +30,13 @@ public class PythonConsoleToolWindowFactory implements ToolWindowFactory, DumbAw
 
   @Override
   public void createToolWindowContent(final @NotNull Project project, final @NotNull ToolWindow toolWindow) {
-    PydevConsoleRunner runner = PydevConsoleRunner.runPythonConsole(project, null, PythonConsoleToolWindow.toolWindowConsole(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 bcf805bc3dd1947de5bf202b6608386158aa2a82..4fbb92964a0293f691ca129eeca0b740264bf76f 100644 (file)
@@ -38,7 +38,7 @@ import java.util.Map;
 public class PythonToolWindowConsoleRunner extends PydevConsoleRunner {
   private ToolWindow myToolWindow;
 
-  protected PythonToolWindowConsoleRunner(@NotNull Project project,
+  public PythonToolWindowConsoleRunner(@NotNull Project project,
                                           @NotNull Sdk sdk,
                                           @NotNull PyConsoleType consoleType,
                                           @Nullable String workingDir, Map<String, String> environmentVariables,
@@ -53,11 +53,6 @@ public class PythonToolWindowConsoleRunner extends PydevConsoleRunner {
     return myToolWindow;
   }
 
-  public void setToolWindow(ToolWindow toolWindow) {
-    myToolWindow = toolWindow;
-  }
-
-
   @Override
   protected void showConsole(Executor defaultExecutor, RunContentDescriptor contentDescriptor) {
     PythonConsoleToolWindow terminalView = PythonConsoleToolWindow.getInstance(getProject());
diff --git a/python/src/com/jetbrains/python/console/PythonToolWindowConsoleRunnerFactory.java b/python/src/com/jetbrains/python/console/PythonToolWindowConsoleRunnerFactory.java
new file mode 100644 (file)
index 0000000..240f3ab
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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 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, String ... setupFragment) {
+    return new PythonToolWindowConsoleRunner(project, sdk, consoleType, workingDir, envs, setupFragment);
+  }
+}