Skip to content

Commit 6af34e4

Browse files
committed
(#22) Run configuration: demonstrate the new default path better
1 parent 6284108 commit 6af34e4

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

src/main/java/com/intellij/plugin/powershell/ide/run/PowerShellRunSettingsEditor.java

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
import org.jetbrains.annotations.NotNull;
1818

1919
import javax.swing.*;
20+
import javax.swing.event.DocumentEvent;
21+
import javax.swing.event.DocumentListener;
2022
import java.io.File;
21-
import java.util.Objects;
2223

2324
import static com.intellij.openapi.util.io.NioFiles.toPath;
2425

@@ -39,6 +40,29 @@ public PowerShellRunSettingsEditor(Project project, PowerShellRunConfiguration r
3940

4041
FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, false, false);
4142
scriptTextField.addBrowseFolderListener("Chose Script", "Please choose script to run", project, descriptor);
43+
44+
var textChangeListener = new DocumentListener() {
45+
@Override
46+
public void insertUpdate(DocumentEvent e) {
47+
changedUpdate(e);
48+
}
49+
50+
@Override
51+
public void removeUpdate(DocumentEvent e) {
52+
changedUpdate(e);
53+
}
54+
55+
@Override
56+
public void changedUpdate(DocumentEvent e) {
57+
if (StringUtil.isEmpty(workingDirectoryTextField.getText())) {
58+
var path = toPath(scriptTextField.getText());
59+
var defaultWorkingDir = PSExecutionUtilKt.getDefaultWorkingDirectory(path);
60+
workingDirectoryTextField.getEmptyText().setText(defaultWorkingDir.toString());
61+
}
62+
}
63+
};
64+
scriptTextField.getTextField().getDocument().addDocumentListener(textChangeListener);
65+
workingDirectoryTextField.getDocument().addDocumentListener(textChangeListener);
4266
}
4367

4468
@Override
@@ -49,13 +73,8 @@ protected void resetEditorFrom(@NotNull PowerShellRunConfiguration configuration
4973
EnvironmentVariablesData envVars = configuration.getEnvironmentVariables();
5074
String executablePath = configuration.getExecutablePath();
5175

52-
var path = toPath(scriptPath);
53-
var customWorkingDirPath = customWorkingDir == null ? null : toPath(customWorkingDir);
54-
if (Objects.equals(customWorkingDirPath, PSExecutionUtilKt.getDefaultWorkingDirectory(path))) {
55-
workingDirectoryTextField.getEmptyText().setText(customWorkingDir);
56-
} else {
57-
workingDirectoryTextFieldWithBrowseBtn.setText(customWorkingDir);
58-
}
76+
workingDirectoryTextFieldWithBrowseBtn.setText(customWorkingDir);
77+
5978
String scriptParameters = configuration.getScriptParameters();
6079
String commandOptions = configuration.getCommandOptions();
6180
if (!StringUtil.isEmpty(scriptPath)) {

0 commit comments

Comments
 (0)