diff options
Diffstat (limited to 'python/src/com/jetbrains/python/console/PythonConsoleView.java')
-rw-r--r-- | python/src/com/jetbrains/python/console/PythonConsoleView.java | 69 |
1 files changed, 43 insertions, 26 deletions
diff --git a/python/src/com/jetbrains/python/console/PythonConsoleView.java b/python/src/com/jetbrains/python/console/PythonConsoleView.java index 699294eb1c8d..86cb0e98e05c 100644 --- a/python/src/com/jetbrains/python/console/PythonConsoleView.java +++ b/python/src/com/jetbrains/python/console/PythonConsoleView.java @@ -29,6 +29,7 @@ import com.intellij.execution.ui.ObservableConsoleView; import com.intellij.ide.GeneralSettings; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.colors.EditorColorsScheme; @@ -119,7 +120,7 @@ public class PythonConsoleView extends JPanel implements LanguageConsoleView, Ob myExecuteActionHandler = consoleExecuteActionHandler; } - private void addSaveContentFocusListener(JComponent component){ + private void addSaveContentFocusListener(JComponent component) { component.addFocusListener(new FocusListener() { @Override public void focusGained(FocusEvent e) { @@ -129,7 +130,8 @@ public class PythonConsoleView extends JPanel implements LanguageConsoleView, Ob } @Override - public void focusLost(FocusEvent e) {} + public void focusLost(FocusEvent e) { + } }); } @@ -150,38 +152,53 @@ public class PythonConsoleView extends JPanel implements LanguageConsoleView, Ob @Override public void executeCode(final @NotNull String code, @Nullable final Editor editor) { - ProgressManager.getInstance().run(new Task.Backgroundable(null, "Executing code in console...", false) { + showConsole(new Runnable() { @Override - public void run(@NotNull final ProgressIndicator indicator) { - long time = System.currentTimeMillis(); - while (!myExecuteActionHandler.isEnabled() || !myExecuteActionHandler.canExecuteNow()) { - if (indicator.isCanceled()) { - break; - } - if (System.currentTimeMillis() - time > 1000) { - if (editor != null) { - UIUtil.invokeLaterIfNeeded(new Runnable() { - @Override - public void run() { - HintManager.getInstance().showErrorHint(editor, myExecuteActionHandler.getCantExecuteMessage()); + public void run() { + ProgressManager.getInstance().run(new Task.Backgroundable(null, "Executing code in console...", false) { + @Override + public void run(@NotNull final ProgressIndicator indicator) { + long time = System.currentTimeMillis(); + while (!myExecuteActionHandler.isEnabled() || !myExecuteActionHandler.canExecuteNow()) { + if (indicator.isCanceled()) { + break; + } + if (System.currentTimeMillis() - time > 1000) { + if (editor != null) { + UIUtil.invokeLaterIfNeeded(new Runnable() { + @Override + public void run() { + HintManager.getInstance().showErrorHint(editor, myExecuteActionHandler.getCantExecuteMessage()); + } + }); } - }); + return; + } + try { + Thread.sleep(300); + } + catch (InterruptedException ignored) { + } + } + if (!indicator.isCanceled()) { + doExecute(code); } - return; - } - try { - Thread.sleep(300); - } - catch (InterruptedException ignored) { } - } - if (!indicator.isCanceled()) { - doExecute(code); - } + }); } }); } + private void showConsole(@NotNull Runnable runnable) { + PythonConsoleToolWindow toolWindow = PythonConsoleToolWindow.getInstance(myProject); + if (toolWindow != null && !ApplicationManager.getApplication().isUnitTestMode()) { + toolWindow.getToolWindow().activate(runnable); + } + else { + runnable.run(); + } + } + private void doExecute(String code) { String codeFragment = PyConsoleIndentUtil.normalize(code, myExecuteActionHandler.getCurrentIndentSize()); |