17
17
import org .jetbrains .annotations .NotNull ;
18
18
19
19
import javax .swing .*;
20
+ import javax .swing .event .DocumentEvent ;
21
+ import javax .swing .event .DocumentListener ;
20
22
import java .io .File ;
21
- import java .util .Objects ;
22
23
23
24
import static com .intellij .openapi .util .io .NioFiles .toPath ;
24
25
@@ -39,6 +40,29 @@ public PowerShellRunSettingsEditor(Project project, PowerShellRunConfiguration r
39
40
40
41
FileChooserDescriptor descriptor = new FileChooserDescriptor (true , false , false , false , false , false );
41
42
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 );
42
66
}
43
67
44
68
@ Override
@@ -49,13 +73,8 @@ protected void resetEditorFrom(@NotNull PowerShellRunConfiguration configuration
49
73
EnvironmentVariablesData envVars = configuration .getEnvironmentVariables ();
50
74
String executablePath = configuration .getExecutablePath ();
51
75
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
+
59
78
String scriptParameters = configuration .getScriptParameters ();
60
79
String commandOptions = configuration .getCommandOptions ();
61
80
if (!StringUtil .isEmpty (scriptPath )) {
0 commit comments