22
33import com .intellij .openapi .options .SearchableConfigurable ;
44import com .intellij .openapi .project .Project ;
5+ import com .intellij .openapi .ui .ComboBox ;
56import com .intellij .ui .components .JBCheckBox ;
67import com .intellij .ui .components .JBLabel ;
78import com .intellij .ui .components .JBTextField ;
1415
1516public class CSharpierSettingsComponent implements SearchableConfigurable {
1617
18+ private final ComboItem [] runOnSaveItems = {
19+ new ComboItem (null , "Use Global Setting" ),
20+ new ComboItem (true , "True" ),
21+ new ComboItem (false , "False" ),
22+ };
1723 private final Project project ;
18- private JBCheckBox runOnSaveCheckBox = new JBCheckBox ("Run on Save" );
24+ private ComboBox <ComboItem > solutionRunOnSaveComboBox = new ComboBox <>(runOnSaveItems );
25+ private JBCheckBox globalRunOnSaveCheckBox = new JBCheckBox ("Run on Save (Global)" );
1926 private JBCheckBox disableCSharpierServerCheckBox = new JBCheckBox ("Disable CSharpier Server" );
2027 private JBCheckBox useCustomPath = new JBCheckBox ("Override CSharpier Executable" );
2128 private JBTextField customPathTextField = new JBTextField ();
@@ -66,7 +73,13 @@ private JComponent createSectionHeader(String label) {
6673 return FormBuilder .createFormBuilder ()
6774 .addComponent (createSectionHeader ("General Settings" ))
6875 .setFormLeftIndent (leftIndent )
69- .addComponent (this .runOnSaveCheckBox , topInset )
76+ .addLabeledComponent (
77+ new JBLabel ("Run on save (Solution):" ),
78+ this .solutionRunOnSaveComboBox ,
79+ topInset ,
80+ false
81+ )
82+ .addComponent (this .globalRunOnSaveCheckBox , topInset )
7083 .setFormLeftIndent (0 )
7184 .addComponent (createSectionHeader ("Developer Settings" ), 20 )
7285 .setFormLeftIndent (leftIndent )
@@ -82,11 +95,15 @@ private JComponent createSectionHeader(String label) {
8295 .getPanel ();
8396 }
8497
98+ private Boolean getSelectedSolutionRunOnSave () {
99+ return ((ComboItem ) this .solutionRunOnSaveComboBox .getSelectedItem ()).value ;
100+ }
101+
85102 @ Override
86103 public boolean isModified () {
87104 return (
88105 CSharpierSettings .getInstance (this .project ).getRunOnSave () !=
89- this .runOnSaveCheckBox . isSelected () ||
106+ this .getSelectedSolutionRunOnSave () ||
90107 CSharpierSettings .getInstance (this .project ).getCustomPath () !=
91108 this .customPathTextField .getText () ||
92109 CSharpierSettings .getInstance (this .project ).getUseCustomPath () !=
@@ -100,18 +117,40 @@ public boolean isModified() {
100117 public void apply () {
101118 var settings = CSharpierSettings .getInstance (this .project );
102119
103- settings .setRunOnSave (this .runOnSaveCheckBox . isSelected ());
120+ settings .setRunOnSave (this .getSelectedSolutionRunOnSave ());
104121 settings .setCustomPath (this .customPathTextField .getText ());
105122 settings .setDisableCSharpierServer (this .disableCSharpierServerCheckBox .isSelected ());
106123 settings .setUseCustomPath (this .useCustomPath .isSelected ());
124+
125+ CSharpierGlobalSettings .getInstance ()
126+ .setRunOnSave (this .globalRunOnSaveCheckBox .isSelected ());
107127 }
108128
109129 @ Override
110130 public void reset () {
111131 var settings = CSharpierSettings .getInstance (this .project );
112- this .runOnSaveCheckBox .setSelected (settings .getRunOnSave ());
132+
133+ var index = -1 ;
134+ for (var i = 0 ; i < runOnSaveItems .length ; i ++) {
135+ if (runOnSaveItems [i ].value == settings .getRunOnSave ()) {
136+ index = i ;
137+ break ;
138+ }
139+ }
140+
141+ this .solutionRunOnSaveComboBox .setSelectedIndex (index );
142+ this .globalRunOnSaveCheckBox .setSelected (
143+ CSharpierGlobalSettings .getInstance ().getRunOnSave ()
144+ );
113145 this .useCustomPath .setSelected (settings .getUseCustomPath ());
114146 this .customPathTextField .setText (settings .getCustomPath ());
115147 this .disableCSharpierServerCheckBox .setSelected (settings .getDisableCSharpierServer ());
116148 }
149+
150+ public record ComboItem (Boolean value , String label ) {
151+ @ Override
152+ public String toString () {
153+ return label ;
154+ }
155+ }
117156}
0 commit comments