Use combobox for module/script selection instead of a check-box

This commit is contained in:
Dmitry Trofimov
2017-09-27 18:00:40 +02:00
parent 639c76bab9
commit a4f6373647
2 changed files with 62 additions and 55 deletions
@@ -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="9" 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="8" 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"/>
@@ -8,14 +8,6 @@
<properties/>
<border type="none"/>
<children>
<component id="20d07" class="javax.swing.JLabel" binding="myScriptLabel">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text resource-bundle="com/jetbrains/python/PyBundle" key="runcfg.labels.script"/>
</properties>
</component>
<component id="ae354" class="com.intellij.ui.components.JBLabel" binding="myScriptParametersLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
@@ -25,26 +17,9 @@
<text resource-bundle="com/jetbrains/python/PyBundle" key="runcfg.labels.script_parameters"/>
</properties>
</component>
<component id="4b96a" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myScriptTextField">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="1" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="9c0aa" class="com.intellij.ui.RawCommandLineEditor" binding="myScriptParametersTextField">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<dialogCaption resource-bundle="com/jetbrains/python/PyBundle" key="runcfg.captions.script_parameters_dialog"/>
<text value=""/>
</properties>
</component>
<vspacer id="f8c96">
<constraints>
<grid row="8" 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="7" 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">
@@ -72,15 +47,6 @@
<text value="Emulate terminal in output console"/>
</properties>
</component>
<component id="cd1ba" class="com.intellij.ui.components.JBCheckBox" binding="myRunModuleCheckBox">
<constraints>
<grid row="7" 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="false"/>
<text value="Run module"/>
</properties>
</component>
<component id="99b13" class="com.intellij.ui.components.JBCheckBox" binding="myShowCommandLineCheckbox">
<constraints>
<grid row="6" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
@@ -90,26 +56,54 @@
<text value="Show command line afterwards"/>
</properties>
</component>
<component id="bf829" class="javax.swing.JLabel" binding="myModuleLabel">
<component id="f3803" class="com.intellij.openapi.ui.ComboBox" binding="myTargetComboBox">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
<text resource-bundle="com/jetbrains/python/PyBundle" key="runcfg.labels.module"/>
<visible value="false"/>
<model>
<item value="Script path"/>
<item value="Module name"/>
</model>
</properties>
</component>
<component id="4bd06" class="com.intellij.ui.RawCommandLineEditor" binding="myModuleField">
<grid id="e2419" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="4b96a" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myScriptTextField">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="4bd06" class="com.intellij.ui.RawCommandLineEditor" binding="myModuleField">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<dialogCaption resource-bundle="com/jetbrains/python/PyBundle" key="runcfg.captions.script_parameters_dialog"/>
<text value=""/>
<visible value="false"/>
</properties>
</component>
</children>
</grid>
<component id="9c0aa" class="com.intellij.ui.RawCommandLineEditor" binding="myScriptParametersTextField">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<dialogCaption resource-bundle="com/jetbrains/python/PyBundle" key="runcfg.captions.script_parameters_dialog"/>
<text value=""/>
<visible value="false"/>
</properties>
</component>
</children>
@@ -17,6 +17,7 @@ package com.jetbrains.python.run;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.ComponentWithBrowseButton;
import com.intellij.openapi.ui.TextComponentAccessor;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
@@ -50,10 +51,8 @@ public class PythonRunConfigurationForm implements PythonRunConfigurationParams,
private final Project myProject;
private JBCheckBox myShowCommandLineCheckbox;
private JBCheckBox myEmulateTerminalCheckbox;
private JBCheckBox myRunModuleCheckBox;
private JLabel myModuleLabel;
private RawCommandLineEditor myModuleField;
private JLabel myScriptLabel;
private ComboBox myTargetComboBox;
private boolean myModuleMode;
public PythonRunConfigurationForm(PythonRunConfiguration configuration) {
@@ -91,6 +90,7 @@ public class PythonRunConfigurationForm implements PythonRunConfigurationParams,
emulateTerminalEnabled(false);
}
myTargetComboBox.setSelectedIndex(0);
myEmulateTerminalCheckbox.setSelected(false);
myEmulateTerminalCheckbox.addChangeListener(
@@ -98,12 +98,24 @@ public class PythonRunConfigurationForm implements PythonRunConfigurationParams,
setAnchor(myCommonOptionsForm.getAnchor());
myRunModuleCheckBox.addChangeListener(
(ChangeEvent e) -> updateRunModuleMode());
myTargetComboBox.addActionListener(e -> updateRunModuleMode());
}
private void updateRunModuleMode() {
setModuleModeInternal(myRunModuleCheckBox.isSelected());
boolean mode = myTargetComboBox.getSelectedIndex() == 1;
checkTargetComboConsistency(mode);
setModuleModeInternal(mode);
}
private void checkTargetComboConsistency(boolean mode) {
Object item = myTargetComboBox.getSelectedItem();
if (item == null) {
throw new IllegalArgumentException("item is null");
}
else //noinspection StringToUpperCaseOrToLowerCaseWithoutLocale
if (mode && !item.toString().toLowerCase().contains("module")) {
throw new IllegalArgumentException("This option should refer to a module");
}
}
private void updateShowCommandLineEnabled() {
@@ -128,7 +140,8 @@ public class PythonRunConfigurationForm implements PythonRunConfigurationParams,
public String getScriptName() {
if (isModuleMode()) {
return myModuleField.getText().trim();
} else {
}
else {
return FileUtil.toSystemIndependentName(myScriptTextField.getText().trim());
}
}
@@ -137,7 +150,8 @@ public class PythonRunConfigurationForm implements PythonRunConfigurationParams,
public void setScriptName(String scriptName) {
if (isModuleMode()) {
myModuleField.setText(StringUtil.notNullize(scriptName));
} else {
}
else {
myScriptTextField.setText(scriptName == null ? "" : FileUtil.toSystemDependentName(scriptName));
}
}
@@ -198,15 +212,14 @@ public class PythonRunConfigurationForm implements PythonRunConfigurationParams,
@Override
public void setModuleMode(boolean moduleMode) {
myRunModuleCheckBox.setSelected(moduleMode);
myTargetComboBox.setSelectedIndex(moduleMode ? 1 : 0);
checkTargetComboConsistency(moduleMode);
}
private void setModuleModeInternal(boolean moduleMode) {
myModuleMode = moduleMode;
myScriptLabel.setVisible(!moduleMode);
myScriptTextField.setVisible(!moduleMode);
myModuleLabel.setVisible(moduleMode);
myModuleField.setVisible(moduleMode);
}
}