*/
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.
* {@link com.intellij.openapi.wm.ToolWindowId#DEBUG}).
*/
public abstract String getToolWindowId();
+
public abstract Icon getToolWindowIcon();
/**
/**
* Returns the unique ID of the executor.
+ *
* @return the ID of the executor.
*/
@NotNull
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);
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;
}
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() {
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;
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) {
}
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);
}
@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());
}
return null;
}
final RunContentDescriptor oldDescriptor = getRunContentDescriptorByContent(content);
- if (oldDescriptor != null && !oldDescriptor.isContentReuseProhibited() ) {
+ if (oldDescriptor != null && !oldDescriptor.isContentReuseProhibited()) {
//content.setExecutionId(executionId);
return oldDescriptor;
}
}
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 {
{
if (killable) {
- String cancelText= ExecutionBundle.message("terminating.process.progress.kill");
+ String cancelText = ExecutionBundle.message("terminating.process.progress.kill");
setCancelText(cancelText);
setCancelTooltipText(cancelText);
}
<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"/>
</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"/>
<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>
</component>
</project-components>
- <project-components>
- <component>
- <implementation-class>com.jetbrains.python.console.PythonConsoleToolWindow</implementation-class>
- </component>
- </project-components>
<module value="com.intellij.modules.xml"/>
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>
<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"/>
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;
}
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) {
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) {
--- /dev/null
+/*
+ * 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) })
+
+ }
+ }
+
+ }
+ }
+
+}
--- /dev/null
+/*
+ * 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;
+ }
+}
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;
}
-
-
-
private AnAction createBackspaceHandlingAction() {
final AnAction upAction = new AnAction() {
@Override
+++ /dev/null
-/*
- * 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());
- }
-}
+++ /dev/null
-/*
- * 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();
- }
-}
}
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) {
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);
+++ /dev/null
-/*
- * 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();
- }
-}
+++ /dev/null
-/*
- * 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);
- }
-}