Allow show command line option only in RunPythonScript Run Configuration.

This commit is contained in:
Dmitry Trofimov
2014-08-21 19:01:03 +02:00
parent 750e3c1d39
commit 5326853eb7
10 changed files with 69 additions and 57 deletions
@@ -7,7 +7,7 @@
<properties/>
<border type="none"/>
<children>
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="11" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="10" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints border-constraint="Center"/>
<properties/>
@@ -15,7 +15,7 @@
<children>
<vspacer id="a7e1d">
<constraints>
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="62f63" class="javax.swing.JLabel">
@@ -121,15 +121,6 @@
<text value="Add source roots to PYTHONPATH"/>
</properties>
</component>
<component id="a8a84" class="com.intellij.ui.components.JBCheckBox" binding="myShowCommandLineCheckbox">
<constraints>
<grid row="9" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text value="Show command line afterwards"/>
</properties>
</component>
</children>
</grid>
</children>
@@ -71,7 +71,6 @@ public class PyIdeCommonOptionsForm implements AbstractPyCommonOptionsForm {
private JPanel myHideablePanel;
private JBCheckBox myAddContentRootsCheckbox;
private JBCheckBox myAddSourceRootsCheckbox;
private JBCheckBox myShowCommandLineCheckbox;
private JComponent labelAnchor;
private final Project myProject;
@@ -296,16 +295,6 @@ public class PyIdeCommonOptionsForm implements AbstractPyCommonOptionsForm {
myAddSourceRootsCheckbox.setSelected(add);
}
@Override
public boolean showCommandLineAfterwards() {
return myShowCommandLineCheckbox.isSelected();
}
@Override
public void setShowCommandLineAfterwards(boolean showCommandLineAfterwards) {
myShowCommandLineCheckbox.setSelected(showCommandLineAfterwards);
}
private void createUIComponents() {
myInterpreterComboBox = new ComboBox(100);
}
@@ -64,7 +64,4 @@ public interface AbstractPythonRunConfigurationParams {
boolean addSourceRoots();
void addContentRoots(boolean add);
void addSourceRoots(boolean add);
boolean showCommandLineAfterwards();
void setShowCommandLineAfterwards(boolean showCommandLineAfterwards);
}
@@ -28,5 +28,8 @@ public interface PythonRunConfigurationParams {
String getScriptParameters();
void setScriptParameters(String scriptParameters);
boolean showCommandLineAfterwards();
void setShowCommandLineAfterwards(boolean showCommandLineAfterwards);
}
@@ -64,7 +64,6 @@ public abstract class AbstractPythonRunConfiguration<T extends AbstractRunConfig
private boolean myUseModuleSdk;
private boolean myAddContentRoots = true;
private boolean myAddSourceRoots = true;
private boolean myShowCommandLineAfterwards = false;
protected PathMappingSettings myMappingSettings;
@@ -230,7 +229,6 @@ public abstract class AbstractPythonRunConfiguration<T extends AbstractRunConfig
final String addSourceRoots = JDOMExternalizerUtil.readField(element, "ADD_SOURCE_ROOTS");
myAddSourceRoots = addSourceRoots == null|| Boolean.parseBoolean(addSourceRoots);
getConfigurationModule().readExternal(element);
myShowCommandLineAfterwards = Boolean.parseBoolean(JDOMExternalizerUtil.readField(element, "SHOW_COMMAND_LINE", "false"));
setMappingSettings(PathMappingSettings.readExternal(element));
// extension settings:
@@ -254,7 +252,6 @@ public abstract class AbstractPythonRunConfiguration<T extends AbstractRunConfig
JDOMExternalizerUtil.writeField(element, "IS_MODULE_SDK", Boolean.toString(myUseModuleSdk));
JDOMExternalizerUtil.writeField(element, "ADD_CONTENT_ROOTS", Boolean.toString(myAddContentRoots));
JDOMExternalizerUtil.writeField(element, "ADD_SOURCE_ROOTS", Boolean.toString(myAddSourceRoots));
JDOMExternalizerUtil.writeField(element, "SHOW_COMMAND_LINE", Boolean.toString(myShowCommandLineAfterwards));
getConfigurationModule().writeExternal(element);
// extension settings:
@@ -331,7 +328,6 @@ public abstract class AbstractPythonRunConfiguration<T extends AbstractRunConfig
target.setMappingSettings(source.getMappingSettings());
target.addContentRoots(source.addContentRoots());
target.addSourceRoots(source.addSourceRoots());
target.setShowCommandLineAfterwards(source.showCommandLineAfterwards());
}
/**
@@ -424,12 +420,4 @@ public abstract class AbstractPythonRunConfiguration<T extends AbstractRunConfig
}
return null;
}
public boolean showCommandLineAfterwards() {
return myShowCommandLineAfterwards;
}
public void setShowCommandLineAfterwards(boolean showCommandLineAfterwards) {
myShowCommandLineAfterwards = showCommandLineAfterwards;
}
}
@@ -51,9 +51,7 @@ import com.intellij.remote.RemoteProcessHandlerBase;
import com.intellij.util.PlatformUtils;
import com.intellij.util.containers.HashMap;
import com.jetbrains.python.PythonHelpersLocator;
import com.jetbrains.python.console.PyConsoleType;
import com.jetbrains.python.console.PyDebugConsoleBuilder;
import com.jetbrains.python.console.PydevConsoleRunner;
import com.jetbrains.python.debugger.PyDebugRunner;
import com.jetbrains.python.debugger.PyDebuggerOptionsProvider;
import com.jetbrains.python.facet.LibraryContributingFacet;
@@ -121,23 +119,12 @@ public abstract class PythonCommandLineState extends CommandLineState {
}
public ExecutionResult execute(Executor executor, CommandLinePatcher... patchers) throws ExecutionException {
if (myConfig.showCommandLineAfterwards()) {
PydevConsoleRunner runner =
new PydevConsoleRunner(myConfig.getProject(), myConfig.getSdk(), PyConsoleType.PYTHON, myConfig.getWorkingDirectory(),
myConfig.getEnvs());
final ProcessHandler processHandler = startProcess(patchers);
final ConsoleView console = createAndAttachConsole(myConfig.getProject(), processHandler, executor);
runner.run();
List<AnAction> actions = Lists.newArrayList(createActions(console, processHandler));
return new DefaultExecutionResult(runner.getConsoleView(), runner.getProcessHandler());
}
else {
final ProcessHandler processHandler = startProcess(patchers);
final ConsoleView console = createAndAttachConsole(myConfig.getProject(), processHandler, executor);
List<AnAction> actions = Lists.newArrayList(createActions(console, processHandler));
return new DefaultExecutionResult(console, processHandler, actions.toArray(new AnAction[actions.size()]));
}
return new DefaultExecutionResult(console, processHandler, actions.toArray(new AnAction[actions.size()]));
}
@NotNull
@@ -47,8 +47,10 @@ public class PythonRunConfiguration extends AbstractPythonRunConfiguration
public static final String SCRIPT_NAME = "SCRIPT_NAME";
public static final String PARAMETERS = "PARAMETERS";
public static final String MULTIPROCESS = "MULTIPROCESS";
public static final String SHOW_COMMAND_LINE = "SHOW_COMMAND_LINE";
private String myScriptName;
private String myScriptParameters;
private boolean myShowCommandLineAfterwards = false;
protected PythonRunConfiguration(Project project, ConfigurationFactory configurationFactory) {
super(project, configurationFactory);
@@ -98,17 +100,27 @@ public class PythonRunConfiguration extends AbstractPythonRunConfiguration
myScriptParameters = scriptParameters;
}
public boolean showCommandLineAfterwards() {
return myShowCommandLineAfterwards;
}
public void setShowCommandLineAfterwards(boolean showCommandLineAfterwards) {
myShowCommandLineAfterwards = showCommandLineAfterwards;
}
public void readExternal(Element element) throws InvalidDataException {
PathMacroManager.getInstance(getProject()).expandPaths(element);
super.readExternal(element);
myScriptName = JDOMExternalizerUtil.readField(element, SCRIPT_NAME);
myScriptParameters = JDOMExternalizerUtil.readField(element, PARAMETERS);
myShowCommandLineAfterwards = Boolean.parseBoolean(JDOMExternalizerUtil.readField(element, SHOW_COMMAND_LINE, "false"));
}
public void writeExternal(Element element) throws WriteExternalException {
super.writeExternal(element);
JDOMExternalizerUtil.writeField(element, SCRIPT_NAME, myScriptName);
JDOMExternalizerUtil.writeField(element, PARAMETERS, myScriptParameters);
JDOMExternalizerUtil.writeField(element, SHOW_COMMAND_LINE, Boolean.toString(myShowCommandLineAfterwards));
PathMacroManager.getInstance(getProject()).collapsePathsRecursively(element);
}
@@ -120,6 +132,7 @@ public class PythonRunConfiguration extends AbstractPythonRunConfiguration
AbstractPythonRunConfiguration.copyParams(source.getBaseParams(), target.getBaseParams());
target.setScriptName(source.getScriptName());
target.setScriptParameters(source.getScriptParameters());
target.setShowCommandLineAfterwards(source.showCommandLineAfterwards());
}
@Override
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.python.run.PythonRunConfigurationForm">
<grid id="27dc6" binding="myRootPanel" layout-manager="GridLayoutManager" row-count="5" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myRootPanel" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="507" height="400"/>
@@ -44,7 +44,7 @@
</component>
<vspacer id="f8c96">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<grid id="9b4b8" binding="myCommonOptionsPlaceholder" layout-manager="BorderLayout" hgap="0" vgap="0">
@@ -63,6 +63,15 @@
<border type="none"/>
<children/>
</grid>
<component id="99b13" class="com.intellij.ui.components.JBCheckBox" binding="myShowCommandLineCheckbox">
<constraints>
<grid row="4" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text value="Show command line afterwards"/>
</properties>
</component>
</children>
</grid>
</form>
@@ -25,6 +25,7 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.PanelWithAnchor;
import com.intellij.ui.RawCommandLineEditor;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.jetbrains.python.debugger.PyDebuggerOptionsProvider;
import org.jetbrains.annotations.NotNull;
@@ -44,6 +45,7 @@ public class PythonRunConfigurationForm implements PythonRunConfigurationParams,
private final AbstractPyCommonOptionsForm myCommonOptionsForm;
private JComponent anchor;
private final Project myProject;
private JBCheckBox myShowCommandLineCheckbox;
public PythonRunConfigurationForm(PythonRunConfiguration configuration) {
myCommonOptionsForm = PyCommonOptionsFormFactory.getInstance().createForm(configuration.getCommonOptionsFormData());
@@ -104,6 +106,16 @@ public class PythonRunConfigurationForm implements PythonRunConfigurationParams,
myScriptParametersTextField.setText(scriptParameters);
}
@Override
public boolean showCommandLineAfterwards() {
return myShowCommandLineCheckbox.isSelected();
}
@Override
public void setShowCommandLineAfterwards(boolean showCommandLineAfterwards) {
myShowCommandLineCheckbox.setSelected(showCommandLineAfterwards);
}
@Override
public JComponent getAnchor() {
return anchor;
@@ -15,11 +15,18 @@
*/
package com.jetbrains.python.run;
import com.intellij.execution.DefaultExecutionResult;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.ExecutionResult;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.configurations.ParametersList;
import com.intellij.execution.configurations.ParamsGroup;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.openapi.util.text.StringUtil;
import com.jetbrains.python.console.PyConsoleType;
import com.jetbrains.python.console.PydevConsoleRunner;
import org.jetbrains.annotations.NotNull;
/**
* @author yole
@@ -32,6 +39,23 @@ public class PythonScriptCommandLineState extends PythonCommandLineState {
myConfig = runConfiguration;
}
@NotNull
@Override
public ExecutionResult execute(Executor executor, CommandLinePatcher... patchers) throws ExecutionException {
if (myConfig.showCommandLineAfterwards()) {
PydevConsoleRunner runner =
new PydevConsoleRunner(myConfig.getProject(), myConfig.getSdk(), PyConsoleType.PYTHON, myConfig.getWorkingDirectory(),
myConfig.getEnvs());
runner.run();
return new DefaultExecutionResult(runner.getConsoleView(), runner.getProcessHandler());
}
else {
return super.execute(executor, patchers);
}
}
@Override
protected void buildCommandLineParameters(GeneralCommandLine commandLine) {
ParametersList parametersList = commandLine.getParametersList();
@@ -52,5 +76,4 @@ public class PythonScriptCommandLineState extends PythonCommandLineState {
commandLine.setWorkDirectory(myConfig.getWorkingDirectory());
}
}
}