IDEA-305403 Remove usages and deprecate HideableDecorator component

- PyPluginCommonOptionsForm

GitOrigin-RevId: b8806490c5138a7acb07a5def3300a1cabb2a230
This commit is contained in:
Pavel Porvatov
2022-11-11 21:42:51 +01:00
committed by intellij-monorepo-bot
parent fa89d5463d
commit 28b43ff791
4 changed files with 140 additions and 237 deletions

View File

@@ -1,144 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.python.run.PyPluginCommonOptionsForm">
<grid id="42d7b" binding="myHideablePanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<xy x="20" y="20" width="457" height="297"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="9" column-count="3" 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/>
<border type="none"/>
<children>
<component id="c3528" class="com.intellij.ui.components.JBLabel" binding="myWorkingDirectoryJBLabel">
<constraints>
<grid row="5" 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>
<labelFor value=""/>
<text resource-bundle="messages/PyBundle" key="runcfg.labels.working_directory"/>
</properties>
</component>
<component id="78c75" class="com.intellij.openapi.ui.TextFieldWithBrowseButton" binding="myWorkingDirectoryTextField">
<constraints>
<grid row="5" column="1" row-span="1" col-span="2" 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/>
</component>
<component id="32654" class="com.intellij.execution.configuration.EnvironmentVariablesComponent" binding="myEnvsComponent">
<constraints>
<grid row="0" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelLocation value="West" noi18n="true"/>
<text resource-bundle="messages/PyBundle" key="runcfg.labels.environment_variables"/>
</properties>
</component>
<component id="cdd29" class="com.intellij.ui.components.JBLabel" binding="myInterpreterOptionsJBLabel">
<constraints>
<grid row="4" 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="messages/PyBundle" key="runcfg.labels.interpreter_options"/>
</properties>
</component>
<component id="1a856" class="com.intellij.ui.RawCommandLineEditor" binding="myInterpreterOptionsTextField">
<constraints>
<grid row="4" column="1" row-span="1" col-span="2" 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="messages/PyBundle" key="runcfg.captions.interpreter_options_dialog"/>
<text value=""/>
</properties>
</component>
<component id="a4f87" class="com.intellij.ui.components.JBLabel" binding="myPythonInterpreterJBLabel">
<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"/>
</constraints>
<properties>
<text resource-bundle="messages/PyBundle" key="runcfg.labels.python.interpreter"/>
</properties>
</component>
<component id="64e87" class="javax.swing.JRadioButton" binding="myUseModuleSdkRadioButton" default-binding="true">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<selected value="true"/>
<text resource-bundle="messages/PyBundle" key="runcfg.labels.use.sdk.of.module"/>
</properties>
</component>
<component id="5f300" class="com.intellij.application.options.ModulesComboBox" binding="myModuleComboBox">
<constraints>
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="b7269" class="javax.swing.JRadioButton" binding="myUseSpecifiedSdkRadioButton">
<constraints>
<grid row="2" column="1" 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="messages/PyBundle" key="runcfg.labels.interpreter"/>
</properties>
</component>
<component id="3f9aa" class="com.intellij.openapi.ui.ComboBox" binding="myInterpreterComboBox" default-binding="true">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<vspacer id="a3bda">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false">
<minimum-size width="-1" height="15"/>
<preferred-size width="-1" height="15"/>
<maximum-size width="-1" height="15"/>
</grid>
</constraints>
</vspacer>
<component id="86ab7" class="com.intellij.execution.util.PathMappingsComponent" binding="myPathMappingsComponent">
<constraints>
<grid row="6" column="0" row-span="1" col-span="3" vsize-policy="3" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<labelLocation value="West" noi18n="true"/>
<text resource-bundle="messages/PyBundle" key="runcfg.labels.path.mappings"/>
</properties>
</component>
<component id="d919b" class="com.intellij.ui.components.JBCheckBox" binding="myAddContentRootsCheckbox">
<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="true"/>
<text resource-bundle="messages/PyBundle" key="runcfg.labels.add.content.roots.to.pythonpath"/>
</properties>
</component>
<component id="1c6cd" class="com.intellij.ui.components.JBCheckBox" binding="myAddSourceRootsCheckbox">
<constraints>
<grid row="8" 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 resource-bundle="messages/PyBundle" key="runcfg.labels.add.source.roots.to.pythonpath"/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<buttonGroups>
<group name="buttonGroup1">
<member id="64e87"/>
<member id="b7269"/>
</group>
</buttonGroups>
</form>

View File

@@ -1,10 +1,6 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.run;
import com.intellij.application.options.ModulesComboBox;
import com.intellij.execution.configuration.EnvironmentVariablesComponent;
import com.intellij.execution.util.PathMappingsComponent;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
@@ -12,18 +8,11 @@ import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.roots.ui.configuration.ModulesAlphaComparator;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.ui.CollectionComboBoxModel;
import com.intellij.ui.HideableDecorator;
import com.intellij.ui.RawCommandLineEditor;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.PathMappingSettings;
import com.jetbrains.python.PyBundle;
import com.jetbrains.python.sdk.PreferredSdkComparator;
import com.jetbrains.python.sdk.PySdkListCellRenderer;
import com.jetbrains.python.sdk.PythonSdkUtil;
import org.jetbrains.annotations.Nullable;
@@ -38,21 +27,7 @@ import java.util.function.Consumer;
public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
private final Project myProject;
private TextFieldWithBrowseButton myWorkingDirectoryTextField;
private EnvironmentVariablesComponent myEnvsComponent;
private RawCommandLineEditor myInterpreterOptionsTextField;
private ComboBox myInterpreterComboBox;
private JRadioButton myUseModuleSdkRadioButton;
private ModulesComboBox myModuleComboBox;
private JPanel myMainPanel;
private JRadioButton myUseSpecifiedSdkRadioButton;
private JBLabel myPythonInterpreterJBLabel;
private JBLabel myInterpreterOptionsJBLabel;
private JBLabel myWorkingDirectoryJBLabel;
private JPanel myHideablePanel;
private PathMappingsComponent myPathMappingsComponent;
private JBCheckBox myAddContentRootsCheckbox;
private JBCheckBox myAddSourceRootsCheckbox;
private final PyPluginCommonOptionsPanel content;
private JComponent labelAnchor;
private final List<Consumer<Boolean>> myRemoteInterpreterModeListeners = new ArrayList<>();
@@ -60,17 +35,15 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
public PyPluginCommonOptionsForm(PyCommonOptionsFormData data) {
// setting modules
myProject = data.getProject();
content = new PyPluginCommonOptionsPanel();
final List<Module> validModules = data.getValidModules();
validModules.sort(new ModulesAlphaComparator());
Module selection = validModules.size() > 0 ? validModules.get(0) : null;
myModuleComboBox.setModules(validModules);
myModuleComboBox.setSelectedModule(selection);
content.moduleComboBox.setModules(validModules);
content.moduleComboBox.setSelectedModule(selection);
myInterpreterComboBox.setMinimumAndPreferredWidth(100);
myInterpreterComboBox
.setRenderer(new PySdkListCellRenderer("<" + PyBundle.message("python.sdk.rendering.project.default") + ">"));
myWorkingDirectoryTextField.addBrowseFolderListener(PyBundle.message("configurable.select.working.directory"), "", data.getProject(),
FileChooserDescriptorFactory.createSingleFolderDescriptor());
content.workingDirectoryTextField.addBrowseFolderListener(PyBundle.message("configurable.select.working.directory"), "", data.getProject(),
FileChooserDescriptorFactory.createSingleFolderDescriptor());
ActionListener listener = new ActionListener() {
@Override
@@ -78,35 +51,11 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
updateControls();
}
};
myUseSpecifiedSdkRadioButton.addActionListener(listener);
myUseModuleSdkRadioButton.addActionListener(listener);
myInterpreterComboBox.addActionListener(listener);
myModuleComboBox.addActionListener(listener);
content.useSpecifiedSdkRadioButton.addActionListener(listener);
content.useModuleSdkRadioButton.addActionListener(listener);
content.interpreterComboBox.addActionListener(listener);
content.moduleComboBox.addActionListener(listener);
setAnchor(myEnvsComponent.getLabel());
final HideableDecorator decorator =
new HideableDecorator(myHideablePanel, PyBundle.message("python.sdk.common.options.environment"), false) {
@Override
protected void on() {
super.on();
storeState();
}
@Override
protected void off() {
super.off();
storeState();
}
private void storeState() {
PropertiesComponent.getInstance().setValue(EXPAND_PROPERTY_KEY, String.valueOf(isExpanded()), "true");
}
};
decorator.setOn(PropertiesComponent.getInstance().getBoolean(EXPAND_PROPERTY_KEY, true));
decorator.setContentComponent(myMainPanel);
myPathMappingsComponent.setAnchor(myEnvsComponent.getLabel());
updateControls();
addInterpreterComboBoxActionListener(new ActionListener() {
@@ -120,14 +69,12 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
}
private void updateControls() {
myModuleComboBox.setEnabled(myUseModuleSdkRadioButton.isSelected());
myInterpreterComboBox.setEnabled(myUseSpecifiedSdkRadioButton.isSelected());
myPathMappingsComponent.setVisible(PythonSdkUtil.isRemote(getSelectedSdk()));
content.pathMappingsRow.visible(PythonSdkUtil.isRemote(getSelectedSdk()));
}
@Override
public JPanel getMainPanel() {
return myHideablePanel;
return content.panel;
}
@Override
@@ -136,12 +83,12 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
@Override
public void addInterpreterComboBoxActionListener(ActionListener listener) {
myInterpreterComboBox.addActionListener(listener);
content.interpreterComboBox.addActionListener(listener);
}
@Override
public void removeInterpreterComboBoxActionListener(ActionListener listener) {
myInterpreterComboBox.removeActionListener(listener);
content.interpreterComboBox.removeActionListener(listener);
}
@Override
@@ -151,28 +98,28 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
@Override
public String getInterpreterOptions() {
return myInterpreterOptionsTextField.getText().trim();
return content.interpreterOptionsTextField.getText().trim();
}
@Override
public void setInterpreterOptions(String interpreterOptions) {
myInterpreterOptionsTextField.setText(interpreterOptions);
content.interpreterOptionsTextField.setText(interpreterOptions);
}
@Override
public String getWorkingDirectory() {
return FileUtil.toSystemIndependentName(myWorkingDirectoryTextField.getText().trim());
return FileUtil.toSystemIndependentName(content.workingDirectoryTextField.getText().trim());
}
@Override
public void setWorkingDirectory(String workingDirectory) {
myWorkingDirectoryTextField.setText(workingDirectory == null ? "" : FileUtil.toSystemDependentName(workingDirectory));
content.workingDirectoryTextField.setText(workingDirectory == null ? "" : FileUtil.toSystemDependentName(workingDirectory));
}
@Override
@Nullable
public String getSdkHome() {
Sdk selectedSdk = (Sdk)myInterpreterComboBox.getSelectedItem();
Sdk selectedSdk = (Sdk)content.interpreterComboBox.getSelectedItem();
return selectedSdk == null ? null : selectedSdk.getHomePath();
}
@@ -189,12 +136,12 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
sdkList.add(sdk);
}
myInterpreterComboBox.setModel(new CollectionComboBoxModel(sdkList, selection));
content.interpreterComboBox.setModel(new CollectionComboBoxModel<>(sdkList, selection));
}
@Override
public Module getModule() {
return myModuleComboBox.getSelectedModule();
return content.moduleComboBox.getSelectedModule();
}
@Override
@@ -205,53 +152,53 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
@Override
public void setModule(Module module) {
myModuleComboBox.setSelectedModule(module);
content.moduleComboBox.setSelectedModule(module);
}
@Override
public boolean isUseModuleSdk() {
return myUseModuleSdkRadioButton.isSelected();
return content.useModuleSdkRadioButton.isSelected();
}
@Override
public void setUseModuleSdk(boolean useModuleSdk) {
if (useModuleSdk) {
myUseModuleSdkRadioButton.setSelected(true);
content.useModuleSdkRadioButton.setSelected(true);
}
else {
myUseSpecifiedSdkRadioButton.setSelected(true);
content.useSpecifiedSdkRadioButton.setSelected(true);
}
updateControls();
}
@Override
public boolean isPassParentEnvs() {
return myEnvsComponent.isPassParentEnvs();
return content.envsComponent.isPassParentEnvs();
}
@Override
public void setPassParentEnvs(boolean passParentEnvs) {
myEnvsComponent.setPassParentEnvs(passParentEnvs);
content.envsComponent.setPassParentEnvs(passParentEnvs);
}
@Override
public Map<String, String> getEnvs() {
return myEnvsComponent.getEnvs();
return content.envsComponent.getEnvs();
}
@Override
public void setEnvs(Map<String, String> envs) {
myEnvsComponent.setEnvs(envs);
content.envsComponent.setEnvs(envs);
}
@Override
public PathMappingSettings getMappingSettings() {
return myPathMappingsComponent.getMappingSettings();
return content.pathMappingsComponent.getMappingSettings();
}
@Override
public void setMappingSettings(@Nullable PathMappingSettings mappingSettings) {
myPathMappingsComponent.setMappingSettings(mappingSettings);
content.pathMappingsComponent.setMappingSettings(mappingSettings);
}
private Sdk getSelectedSdk() {
@@ -259,7 +206,7 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
Module module = getModule();
return module == null ? null : ModuleRootManager.getInstance(module).getSdk();
}
Sdk sdk = (Sdk)myInterpreterComboBox.getSelectedItem();
Sdk sdk = (Sdk)content.interpreterComboBox.getSelectedItem();
if (sdk == null) {
return ProjectRootManager.getInstance(myProject).getProjectSdk();
}
@@ -274,29 +221,25 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
@Override
public void setAnchor(JComponent anchor) {
labelAnchor = anchor;
myPythonInterpreterJBLabel.setAnchor(anchor);
myInterpreterOptionsJBLabel.setAnchor(anchor);
myWorkingDirectoryJBLabel.setAnchor(anchor);
myEnvsComponent.setAnchor(anchor);
}
@Override
public boolean shouldAddContentRoots() {
return myAddContentRootsCheckbox.isSelected();
return content.addContentRootsCheckbox.isSelected();
}
@Override
public boolean shouldAddSourceRoots() {
return myAddSourceRootsCheckbox.isSelected();
return content.addSourceRootsCheckbox.isSelected();
}
@Override
public void setAddContentRoots(boolean flag) {
myAddContentRootsCheckbox.setSelected(flag);
content.addContentRootsCheckbox.setSelected(flag);
}
@Override
public void setAddSourceRoots(boolean flag) {
myAddSourceRootsCheckbox.setSelected(flag);
content.addSourceRootsCheckbox.setSelected(flag);
}
}

View File

@@ -0,0 +1,102 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.run
import com.intellij.application.options.ModulesComboBox
import com.intellij.execution.configuration.EnvironmentVariablesComponent
import com.intellij.execution.util.PathMappingsComponent
import com.intellij.ide.util.PropertiesComponent
import com.intellij.openapi.projectRoots.Sdk
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.ui.TextFieldWithBrowseButton
import com.intellij.ui.RawCommandLineEditor
import com.intellij.ui.dsl.builder.*
import com.intellij.ui.layout.selected
import com.jetbrains.python.PyBundle
import com.jetbrains.python.sdk.PySdkListCellRenderer
import javax.swing.JCheckBox
import javax.swing.JRadioButton
class PyPluginCommonOptionsPanel {
lateinit var envsComponent: EnvironmentVariablesComponent
lateinit var useModuleSdkRadioButton: JRadioButton
lateinit var moduleComboBox: ModulesComboBox
lateinit var useSpecifiedSdkRadioButton: JRadioButton
lateinit var interpreterComboBox: ComboBox<Sdk>
lateinit var interpreterOptionsTextField: RawCommandLineEditor
lateinit var workingDirectoryTextField: TextFieldWithBrowseButton
lateinit var pathMappingsRow: Row
lateinit var pathMappingsComponent: PathMappingsComponent
lateinit var addContentRootsCheckbox: JCheckBox
lateinit var addSourceRootsCheckbox: JCheckBox
@JvmField
val panel = panel {
collapsibleGroup(PyBundle.message("python.sdk.common.options.environment")) {
row {
envsComponent = cell(EnvironmentVariablesComponent())
.label(PyBundle.message("runcfg.labels.environment_variables"), LabelPosition.TOP)
.align(AlignX.FILL)
.applyToComponent { remove(label) }
.component
}
buttonsGroup {
row(PyBundle.message("runcfg.labels.python.interpreter")) {
useModuleSdkRadioButton = radioButton(PyBundle.message("runcfg.labels.use.sdk.of.module"))
.applyToComponent { isSelected = true }
.gap(RightGap.SMALL)
.component
moduleComboBox = cell(ModulesComboBox())
.align(AlignX.FILL)
.enabledIf(useModuleSdkRadioButton.selected)
.component
}.layout(RowLayout.PARENT_GRID)
row("") {
useSpecifiedSdkRadioButton = radioButton(PyBundle.message("runcfg.labels.interpreter"))
.gap(RightGap.SMALL)
.component
interpreterComboBox = comboBox(listOf<Sdk>(),
PySdkListCellRenderer("<" + PyBundle.message("python.sdk.rendering.project.default") + ">"))
.enabledIf(useSpecifiedSdkRadioButton.selected)
.align(AlignX.FILL)
.component
}.layout(RowLayout.PARENT_GRID)
.bottomGap(BottomGap.SMALL)
}
row(PyBundle.message("runcfg.labels.interpreter_options")) {
interpreterOptionsTextField = cell(RawCommandLineEditor())
.align(AlignX.FILL)
.component
}
row(PyBundle.message("runcfg.labels.working_directory")) {
workingDirectoryTextField = cell(TextFieldWithBrowseButton())
.align(AlignX.FILL)
.component
}
pathMappingsRow = row(PyBundle.message("runcfg.labels.path.mappings")) {
pathMappingsComponent = cell(PathMappingsComponent())
.applyToComponent { remove(label) }
.align(AlignX.FILL)
.component
}
row {
addContentRootsCheckbox = checkBox(PyBundle.message("runcfg.labels.add.content.roots.to.pythonpath"))
.applyToComponent { isSelected = true }
.component
}
row {
addSourceRootsCheckbox = checkBox(PyBundle.message("runcfg.labels.add.source.roots.to.pythonpath"))
.applyToComponent { isSelected = true }
.component
}
}.apply {
expanded = PropertiesComponent.getInstance().getBoolean(AbstractPyCommonOptionsForm.EXPAND_PROPERTY_KEY, true)
addExpandedListener {
PropertiesComponent.getInstance().setValue(AbstractPyCommonOptionsForm.EXPAND_PROPERTY_KEY, it.toString(), "true")
}
}
}
}