diff options
Diffstat (limited to 'python/src/com/jetbrains/python/console/PythonConsoleToolWindow.java')
-rw-r--r-- | python/src/com/jetbrains/python/console/PythonConsoleToolWindow.java | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/python/src/com/jetbrains/python/console/PythonConsoleToolWindow.java b/python/src/com/jetbrains/python/console/PythonConsoleToolWindow.java index e8c50e49280a..177c3528496f 100644 --- a/python/src/com/jetbrains/python/console/PythonConsoleToolWindow.java +++ b/python/src/com/jetbrains/python/console/PythonConsoleToolWindow.java @@ -1,8 +1,14 @@ 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.Key; import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowManager; import com.intellij.openapi.wm.ex.ToolWindowManagerEx; @@ -11,20 +17,25 @@ 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"); private final Project myProject; private boolean myInitialized = false; + private ActionCallback myActivation = new ActionCallback(); + public PythonConsoleToolWindow(Project project) { myProject = project; } @@ -33,6 +44,17 @@ public class PythonConsoleToolWindow { return project.getComponent(PythonConsoleToolWindow.class); } + public List<RunContentDescriptor> getConsoleContentDescriptors() { + return FluentIterable.from(Lists.newArrayList(getToolWindow().getContentManager().getContents())) + .transform(new Function<Content, RunContentDescriptor>() { + @Override + public RunContentDescriptor apply(@Nullable Content input) { + return input != null ? input.getUserData(CONTENT_DESCRIPTOR) : null; + } + }).filter( + Predicates.notNull()).toList(); + } + public void init(final @NotNull ToolWindow toolWindow, final @NotNull RunContentDescriptor contentDescriptor) { addContent(toolWindow, contentDescriptor); @@ -42,7 +64,7 @@ public class PythonConsoleToolWindow { } } - private void doInit(final ToolWindow toolWindow) { + private void doInit(@NotNull final ToolWindow toolWindow) { myInitialized = true; toolWindow.setToHideOnEmptyContent(true); @@ -58,7 +80,8 @@ public class PythonConsoleToolWindow { if (window != null) { boolean visible = window.isVisible(); if (visible && toolWindow.getContentManager().getContentCount() == 0) { - RunPythonConsoleAction.runPythonConsole(myProject, null, toolWindow); + PydevConsoleRunner runner = PythonConsoleRunnerFactory.getInstance().createConsoleRunner(myProject, null); + runner.run(); } } } @@ -98,10 +121,11 @@ public class PythonConsoleToolWindow { private static void resetContent(RunContentDescriptor contentDescriptor, SimpleToolWindowPanel panel, Content content) { panel.setContent(contentDescriptor.getComponent()); - //panel.addFocusListener(createFocusListener(toolWindow)); content.setComponent(panel); content.setPreferredFocusableComponent(contentDescriptor.getComponent()); + + content.putUserData(CONTENT_DESCRIPTOR, contentDescriptor); } private static FocusListener createFocusListener(final ToolWindow toolWindow) { @@ -124,4 +148,13 @@ public class PythonConsoleToolWindow { 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); + } } |