mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Console init moved out of the event dispatch thread.
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package com.jetbrains.python.console;
|
||||
|
||||
import com.intellij.codeInsight.hint.HintManager;
|
||||
import com.intellij.execution.console.LanguageConsoleImpl;
|
||||
import com.intellij.execution.console.LanguageConsoleViewImpl;
|
||||
import com.intellij.execution.process.ConsoleHistoryModel;
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.execution.process.ProcessOutputTypes;
|
||||
import com.intellij.execution.runners.ConsoleExecuteActionHandler;
|
||||
@@ -37,6 +39,7 @@ public class PydevConsoleExecuteActionHandler extends ConsoleExecuteActionHandle
|
||||
private IndentHelper myIndentHelper;
|
||||
|
||||
private final ConsoleCommunication myConsoleCommunication;
|
||||
private boolean myEnabled = false;
|
||||
|
||||
public PydevConsoleExecuteActionHandler(LanguageConsoleViewImpl consoleView,
|
||||
ProcessHandler myProcessHandler,
|
||||
@@ -177,4 +180,25 @@ public class PydevConsoleExecuteActionHandler extends ConsoleExecuteActionHandle
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void runExecuteAction(LanguageConsoleImpl languageConsole,
|
||||
ConsoleHistoryModel consoleHistoryModel) {
|
||||
if (isEnabled()) {
|
||||
super.runExecuteAction(languageConsole, consoleHistoryModel);
|
||||
} else {
|
||||
HintManager.getInstance().showErrorHint(languageConsole.getConsoleEditor(), getConsoleIsNotEnabledMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected String getConsoleIsNotEnabledMessage() {
|
||||
return "Console is not enabled.";
|
||||
}
|
||||
|
||||
protected void setEnabled(boolean flag) {
|
||||
myEnabled = flag;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return myEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,10 @@ import com.intellij.execution.runners.ConsoleExecuteActionHandler;
|
||||
import com.intellij.execution.ui.RunContentDescriptor;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.Key;
|
||||
@@ -41,6 +45,7 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory {
|
||||
private final int[] myPorts;
|
||||
private PydevConsoleCommunication myPydevConsoleCommunication;
|
||||
private PyConsoleProcessHandler myProcessHandler;
|
||||
private PydevConsoleExecuteActionHandler myConsoleExecuteActionHandler;
|
||||
|
||||
public static Key<ConsoleCommunication> CONSOLE_KEY = new Key<ConsoleCommunication>("PYDEV_CONSOLE_KEY");
|
||||
|
||||
@@ -98,12 +103,17 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory {
|
||||
};
|
||||
|
||||
final PydevConsoleRunner consoleRunner = new PydevConsoleRunner(project, sdk, consoleTitle, provider, projectRoot, ports);
|
||||
try {
|
||||
consoleRunner.initAndRun(statements2execute);
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
ExecutionHelper.showErrors(project, Arrays.<Exception>asList(e), consoleTitle, null);
|
||||
}
|
||||
ProgressManager.getInstance().run(new Task.Backgroundable(null, "Connecting to console", false) {
|
||||
public void run(@NotNull final ProgressIndicator indicator) {
|
||||
indicator.setText("Connecting to console...");
|
||||
try {
|
||||
consoleRunner.initAndRun(statements2execute);
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
ExecutionHelper.showErrors(project, Arrays.<Exception>asList(e), consoleTitle, null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -133,28 +143,49 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory {
|
||||
public void initAndRun(final String... statements2execute) throws ExecutionException {
|
||||
super.initAndRun();
|
||||
|
||||
// Propagate console communication to language console
|
||||
((PydevLanguageConsoleView)getConsoleView()).setConsoleCommunication(myPydevConsoleCommunication);
|
||||
|
||||
final LanguageConsoleImpl console = getConsoleView().getConsole();
|
||||
|
||||
if (handshake()) {
|
||||
// Make executed statements visible to developers
|
||||
PyConsoleHighlightingUtil.processOutput(console, PYTHON_ENV_COMMAND, ProcessOutputTypes.SYSTEM);
|
||||
getConsoleExecuteActionHandler().processLine(PYTHON_ENV_COMMAND);
|
||||
|
||||
for (String statement : statements2execute) {
|
||||
PyConsoleHighlightingUtil.processOutput(console, statement + "\n", ProcessOutputTypes.SYSTEM);
|
||||
getConsoleExecuteActionHandler().processLine(statement + "\n");
|
||||
}
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// Propagate console communication to language console
|
||||
((PydevLanguageConsoleView)getConsoleView()).setConsoleCommunication(myPydevConsoleCommunication);
|
||||
|
||||
final LanguageConsoleImpl console = getConsoleView().getConsole();
|
||||
|
||||
enableConsoleExecuteAction();
|
||||
|
||||
// Make executed statements visible to developers
|
||||
PyConsoleHighlightingUtil.processOutput(console, PYTHON_ENV_COMMAND, ProcessOutputTypes.SYSTEM);
|
||||
|
||||
getConsoleExecuteActionHandler().processLine(PYTHON_ENV_COMMAND);
|
||||
|
||||
for (String statement : statements2execute) {
|
||||
PyConsoleHighlightingUtil.processOutput(console, statement + "\n", ProcessOutputTypes.SYSTEM);
|
||||
getConsoleExecuteActionHandler().processLine(statement + "\n");
|
||||
}
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
console.flushAllUiUpdates();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
final LanguageConsoleImpl console = getConsoleView().getConsole();
|
||||
PyConsoleHighlightingUtil.processOutput(console, "Couldn't connect to console process.", ProcessOutputTypes.STDERR);
|
||||
myProcessHandler.destroyProcess();
|
||||
finishConsole();
|
||||
}
|
||||
}
|
||||
|
||||
private void enableConsoleExecuteAction() {
|
||||
myConsoleExecuteActionHandler.setEnabled(true);
|
||||
}
|
||||
|
||||
private boolean handshake() {
|
||||
boolean res;
|
||||
long started = System.currentTimeMillis();
|
||||
@@ -198,7 +229,6 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory {
|
||||
return createConsoleStoppingAction(generalCloseAction);
|
||||
}
|
||||
|
||||
|
||||
private AnAction createConsoleStoppingAction(final AnAction generalStopAction) {
|
||||
final AnAction stopAction = new AnAction() {
|
||||
@Override
|
||||
@@ -231,7 +261,10 @@ public class PydevConsoleRunner extends AbstractConsoleRunnerWithHistory {
|
||||
@NotNull
|
||||
@Override
|
||||
protected ConsoleExecuteActionHandler createConsoleExecuteActionHandler() {
|
||||
return new PydevConsoleExecuteActionHandler(getConsoleView(), getProcessHandler(), myPydevConsoleCommunication);
|
||||
myConsoleExecuteActionHandler =
|
||||
new PydevConsoleExecuteActionHandler(getConsoleView(), getProcessHandler(), myPydevConsoleCommunication);
|
||||
myConsoleExecuteActionHandler.setEnabled(false);
|
||||
return myConsoleExecuteActionHandler;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-19
@@ -1,9 +1,6 @@
|
||||
package com.jetbrains.python.debugger;
|
||||
|
||||
import com.intellij.codeInsight.hint.HintManager;
|
||||
import com.intellij.execution.console.LanguageConsoleImpl;
|
||||
import com.intellij.execution.console.LanguageConsoleViewImpl;
|
||||
import com.intellij.execution.process.ConsoleHistoryModel;
|
||||
import com.intellij.execution.process.ProcessHandler;
|
||||
import com.intellij.xdebugger.XDebugSessionListener;
|
||||
import com.jetbrains.python.console.PydevConsoleExecuteActionHandler;
|
||||
@@ -13,7 +10,6 @@ import com.jetbrains.python.console.pydev.ConsoleCommunication;
|
||||
* @author traff
|
||||
*/
|
||||
public class PydevDebugConsoleExecuteActionHandler extends PydevConsoleExecuteActionHandler implements XDebugSessionListener {
|
||||
private boolean myEnabled = false;
|
||||
|
||||
public PydevDebugConsoleExecuteActionHandler(LanguageConsoleViewImpl consoleView,
|
||||
ProcessHandler myProcessHandler,
|
||||
@@ -21,21 +17,9 @@ public class PydevDebugConsoleExecuteActionHandler extends PydevConsoleExecuteAc
|
||||
super(consoleView, myProcessHandler, consoleCommunication);
|
||||
}
|
||||
|
||||
public void runExecuteAction(LanguageConsoleImpl languageConsole,
|
||||
ConsoleHistoryModel consoleHistoryModel) {
|
||||
if (isEnabled()) {
|
||||
super.runExecuteAction(languageConsole, consoleHistoryModel);
|
||||
} else {
|
||||
HintManager.getInstance().showErrorHint(languageConsole.getConsoleEditor(), "Pause the process to use command-line.");
|
||||
}
|
||||
}
|
||||
|
||||
private void setEnabled(boolean flag) {
|
||||
myEnabled = flag;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return myEnabled;
|
||||
@Override
|
||||
protected String getConsoleIsNotEnabledMessage() {
|
||||
return "Pause the process to use command-line.";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user