mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
nodewebkit RC — macro aware
This commit is contained in:
+53
-32
@@ -33,10 +33,12 @@ import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.ui.MacroAwareTextBrowseFolderListener;
|
||||
import com.intellij.ui.PanelWithAnchor;
|
||||
import com.intellij.ui.RawCommandLineEditor;
|
||||
import com.intellij.ui.TextAccessor;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.serialization.PathMacroUtil;
|
||||
|
||||
@@ -48,17 +50,28 @@ import java.util.List;
|
||||
|
||||
public class CommonProgramParametersPanel extends JPanel implements PanelWithAnchor {
|
||||
private LabeledComponent<RawCommandLineEditor> myProgramParametersComponent;
|
||||
private LabeledComponent<JPanel> myWorkingDirectoryComponent;
|
||||
private TextFieldWithBrowseButton myWorkingDirectoryField;
|
||||
private LabeledComponent<JComponent> myWorkingDirectoryComponent;
|
||||
protected TextFieldWithBrowseButton myWorkingDirectoryField;
|
||||
private EnvironmentVariablesComponent myEnvVariablesComponent;
|
||||
protected JComponent myAnchor;
|
||||
|
||||
private Module myModuleContext = null;
|
||||
|
||||
public CommonProgramParametersPanel() {
|
||||
this(true);
|
||||
}
|
||||
|
||||
public CommonProgramParametersPanel(boolean init) {
|
||||
super();
|
||||
|
||||
setLayout(new VerticalFlowLayout(VerticalFlowLayout.MIDDLE, 0, 5, true, false));
|
||||
|
||||
if (init) {
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
initComponents();
|
||||
copyDialogCaption(myProgramParametersComponent);
|
||||
updateUI();
|
||||
@@ -86,34 +99,7 @@ public class CommonProgramParametersPanel extends JPanel implements PanelWithAnc
|
||||
}
|
||||
});
|
||||
|
||||
final JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.add(myWorkingDirectoryField, BorderLayout.CENTER);
|
||||
|
||||
final FixedSizeButton button = new FixedSizeButton(myWorkingDirectoryField);
|
||||
button.setIcon(AllIcons.RunConfigurations.Variables);
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final List<String> macros = new SmartList<String>(PathMacros.getInstance().getUserMacroNames());
|
||||
if (myModuleContext != null) {
|
||||
macros.add(PathMacroUtil.MODULE_DIR_MACRO_NAME);
|
||||
}
|
||||
|
||||
final JList list = new JBList(ArrayUtil.toStringArray(macros));
|
||||
JBPopupFactory.getInstance().createListPopupBuilder(list).setItemChoosenCallback(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Object value = list.getSelectedValue();
|
||||
if (value instanceof String) {
|
||||
setWorkingDirectory("$" + value + "$");
|
||||
}
|
||||
}
|
||||
}).setMovable(false).setResizable(false).createPopup().showUnderneathOf(button);
|
||||
}
|
||||
});
|
||||
panel.add(button, BorderLayout.EAST);
|
||||
|
||||
myWorkingDirectoryComponent = LabeledComponent.create(panel, ExecutionBundle.message("run.configuration.working.directory.label"));
|
||||
myWorkingDirectoryComponent = LabeledComponent.create(createComponentWithMacroBrowse(myWorkingDirectoryField), ExecutionBundle.message("run.configuration.working.directory.label"));
|
||||
myEnvVariablesComponent = new EnvironmentVariablesComponent();
|
||||
|
||||
myEnvVariablesComponent.setLabelLocation(BorderLayout.WEST);
|
||||
@@ -127,6 +113,36 @@ public class CommonProgramParametersPanel extends JPanel implements PanelWithAnc
|
||||
setAnchor(myEnvVariablesComponent.getLabel());
|
||||
}
|
||||
|
||||
protected JComponent createComponentWithMacroBrowse(@NotNull final TextFieldWithBrowseButton textAccessor) {
|
||||
final FixedSizeButton button = new FixedSizeButton(textAccessor);
|
||||
button.setIcon(AllIcons.RunConfigurations.Variables);
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
List<String> macros = new SmartList<String>(PathMacros.getInstance().getUserMacroNames());
|
||||
if (myModuleContext != null) {
|
||||
macros.add(PathMacroUtil.MODULE_DIR_MACRO_NAME);
|
||||
}
|
||||
|
||||
final JList list = new JBList(ArrayUtil.toStringArray(macros));
|
||||
JBPopupFactory.getInstance().createListPopupBuilder(list).setItemChoosenCallback(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Object value = list.getSelectedValue();
|
||||
if (value instanceof String) {
|
||||
textAccessor.setText('$' + ((String)value) + '$');
|
||||
}
|
||||
}
|
||||
}).setMovable(false).setResizable(false).createPopup().showUnderneathOf(button);
|
||||
}
|
||||
});
|
||||
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
panel.add(textAccessor, BorderLayout.CENTER);
|
||||
panel.add(button, BorderLayout.EAST);
|
||||
return panel;
|
||||
}
|
||||
|
||||
protected void addComponents() {
|
||||
add(myProgramParametersComponent);
|
||||
add(myWorkingDirectoryComponent);
|
||||
@@ -174,13 +190,18 @@ public class CommonProgramParametersPanel extends JPanel implements PanelWithAnc
|
||||
}
|
||||
|
||||
public void applyTo(CommonProgramRunConfigurationParameters configuration) {
|
||||
configuration.setProgramParameters(myProgramParametersComponent.getComponent().getText());
|
||||
configuration.setWorkingDirectory(myWorkingDirectoryField.getText());
|
||||
configuration.setProgramParameters(fromTextField(myProgramParametersComponent.getComponent(), configuration));
|
||||
configuration.setWorkingDirectory(fromTextField(myWorkingDirectoryField, configuration));
|
||||
|
||||
configuration.setEnvs(myEnvVariablesComponent.getEnvs());
|
||||
configuration.setPassParentEnvs(myEnvVariablesComponent.isPassParentEnvs());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected String fromTextField(@NotNull TextAccessor textAccessor, @NotNull CommonProgramRunConfigurationParameters configuration) {
|
||||
return textAccessor.getText();
|
||||
}
|
||||
|
||||
public void reset(CommonProgramRunConfigurationParameters configuration) {
|
||||
setProgramParameters(configuration.getProgramParameters());
|
||||
setWorkingDirectory(PathUtil.toSystemDependentName(configuration.getWorkingDirectory()));
|
||||
|
||||
@@ -31,7 +31,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.List;
|
||||
|
||||
public class RawCommandLineEditor extends JPanel {
|
||||
public class RawCommandLineEditor extends JPanel implements TextAccessor {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.ui.RawCommandLineEditor");
|
||||
|
||||
private final TextFieldWithBrowseButton myTextField;
|
||||
@@ -44,6 +44,7 @@ public class RawCommandLineEditor extends JPanel {
|
||||
public RawCommandLineEditor(final Function<String, List<String>> lineParser, final Function<List<String>, String> lineJoiner) {
|
||||
super(new BorderLayout());
|
||||
myTextField = new TextFieldWithBrowseButton(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (myDialogCaption == null) {
|
||||
Container parent = getParent();
|
||||
@@ -73,10 +74,12 @@ public class RawCommandLineEditor extends JPanel {
|
||||
myDialogCaption = dialogCaption != null ? dialogCaption : "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setText(String text) {
|
||||
myTextField.setText(text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText() {
|
||||
return myTextField.getText();
|
||||
}
|
||||
@@ -93,6 +96,7 @@ public class RawCommandLineEditor extends JPanel {
|
||||
label.setLabelFor(myTextField.getTextField());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
super.setEnabled(enabled);
|
||||
myTextField.setEnabled(enabled);
|
||||
|
||||
+2
-1
@@ -28,6 +28,7 @@ import com.intellij.util.io.fs.IFile;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -144,7 +145,7 @@ public class XmlElementStorageTest extends LightPlatformLangTestCase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String collapsePath(final String path) {
|
||||
public String collapsePath(@Nullable String path) {
|
||||
throw new UnsupportedOperationException("Method collapsePath not implemented in " + getClass());
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -16,11 +16,14 @@
|
||||
package com.intellij.openapi.components;
|
||||
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface PathMacroSubstitutor {
|
||||
String expandPath(String path);
|
||||
String collapsePath(String path);
|
||||
|
||||
String collapsePath(@Nullable String path);
|
||||
|
||||
void expandPaths(Element element);
|
||||
|
||||
void collapsePaths(Element element);
|
||||
}
|
||||
|
||||
+2
-2
@@ -112,7 +112,7 @@ public class BasePathMacroManager extends PathMacroManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String collapsePath(final String path) {
|
||||
public String collapsePath(@Nullable String path) {
|
||||
return getReplacePathMap().substitute(path, SystemInfo.isFileSystemCaseSensitive);
|
||||
}
|
||||
|
||||
@@ -177,7 +177,7 @@ public class BasePathMacroManager extends PathMacroManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String collapsePath(final String path) {
|
||||
public String collapsePath(@Nullable String path) {
|
||||
return getReplacePathMap().substitute(path, SystemInfo.isFileSystemCaseSensitive);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user