10
10
*******************************************************************************/
11
11
package org .eclipse .cdt .cmake .ui .internal ;
12
12
13
+ import java .util .HashMap ;
13
14
import java .util .Map ;
14
15
15
16
import org .eclipse .cdt .cmake .core .internal .CMakeBuildConfiguration ;
32
33
33
34
public class CMakeBuildTab extends CommonBuildTab {
34
35
36
+ /**
37
+ * Checkbox allowing user to choose these settings over the default operating system defaults.
38
+ * This is connected to the CMakeBuildConfiguration.CMAKE_USE_UI_OVERRIDES preference.
39
+ */
40
+ private Button useUiCmakeSettings ;
35
41
private Button unixGenButton ;
36
42
private Button ninjaGenButton ;
37
43
private Text cmakeArgsText ;
38
44
private Text buildCommandText ;
39
45
private Text cleanCommandText ;
46
+ private Label generatorLabel ;
47
+ private Label cmakeArgsLabel ;
48
+ private Label buildCommandLabel ;
49
+ private Label cleanCommandLabel ;
40
50
41
51
@ Override
42
52
protected String getBuildConfigProviderId () {
@@ -57,8 +67,19 @@ public void createControl(Composite parent) {
57
67
cmakeGroup .setLayoutData (new GridData (SWT .FILL , SWT .FILL , true , true ));
58
68
cmakeGroup .setLayout (new GridLayout ());
59
69
60
- Label label = new Label (cmakeGroup , SWT .NONE );
61
- label .setText (Messages .CMakeBuildTab_Generator );
70
+ useUiCmakeSettings = new Button (cmakeGroup , SWT .CHECK );
71
+ useUiCmakeSettings .setText (Messages .CMakeBuildTab_useUICmakeSettings );
72
+ useUiCmakeSettings .setToolTipText (Messages .CMakeBuildTab_useUICmakeSettingsTip );
73
+ useUiCmakeSettings .addSelectionListener (new SelectionAdapter () {
74
+ @ Override
75
+ public void widgetSelected (SelectionEvent e ) {
76
+ updateEnablement ();
77
+ updateLaunchConfigurationDialog ();
78
+ }
79
+ });
80
+
81
+ generatorLabel = new Label (cmakeGroup , SWT .NONE );
82
+ generatorLabel .setText (Messages .CMakeBuildTab_Generator );
62
83
63
84
Composite genComp = new Composite (cmakeGroup , SWT .BORDER );
64
85
genComp .setLayout (new GridLayout (2 , true ));
@@ -81,31 +102,50 @@ public void widgetSelected(SelectionEvent e) {
81
102
}
82
103
});
83
104
84
- label = new Label (cmakeGroup , SWT .NONE );
85
- label .setText (Messages .CMakeBuildTab_CMakeArgs );
105
+ cmakeArgsLabel = new Label (cmakeGroup , SWT .NONE );
106
+ cmakeArgsLabel .setText (Messages .CMakeBuildTab_CMakeArgs );
86
107
87
108
cmakeArgsText = new Text (cmakeGroup , SWT .BORDER );
88
109
cmakeArgsText .setLayoutData (new GridData (SWT .FILL , SWT .CENTER , true , false ));
89
110
cmakeArgsText .addModifyListener (e -> updateLaunchConfigurationDialog ());
90
111
91
- label = new Label (cmakeGroup , SWT .NONE );
92
- label .setText (Messages .CMakeBuildTab_BuildCommand );
112
+ buildCommandLabel = new Label (cmakeGroup , SWT .NONE );
113
+ buildCommandLabel .setText (Messages .CMakeBuildTab_BuildCommand );
93
114
94
115
buildCommandText = new Text (cmakeGroup , SWT .BORDER );
95
116
buildCommandText .setLayoutData (new GridData (SWT .FILL , SWT .CENTER , true , false ));
96
117
buildCommandText .addModifyListener (e -> updateLaunchConfigurationDialog ());
97
118
98
- label = new Label (cmakeGroup , SWT .NONE );
99
- label .setText (Messages .CMakeBuildTab_CleanCommand );
119
+ cleanCommandLabel = new Label (cmakeGroup , SWT .NONE );
120
+ cleanCommandLabel .setText (Messages .CMakeBuildTab_CleanCommand );
100
121
101
122
cleanCommandText = new Text (cmakeGroup , SWT .BORDER );
102
123
cleanCommandText .setLayoutData (new GridData (SWT .FILL , SWT .CENTER , true , false ));
103
124
cleanCommandText .addModifyListener (e -> updateLaunchConfigurationDialog ());
104
125
}
105
126
127
+ /**
128
+ * Updates the enabled state of the CMake settings controls based on useUiCmakeSettings checkbox
129
+ */
130
+ private void updateEnablement () {
131
+ boolean isSelected = useUiCmakeSettings .getSelection ();
132
+ generatorLabel .setEnabled (isSelected );
133
+ unixGenButton .setEnabled (isSelected );
134
+ ninjaGenButton .setEnabled (isSelected );
135
+ cmakeArgsLabel .setEnabled (isSelected );
136
+ cmakeArgsText .setEnabled (isSelected );
137
+ buildCommandLabel .setEnabled (isSelected );
138
+ buildCommandText .setEnabled (isSelected );
139
+ cleanCommandLabel .setEnabled (isSelected );
140
+ cleanCommandText .setEnabled (isSelected );
141
+ }
142
+
106
143
@ Override
107
144
public void setDefaults (ILaunchConfigurationWorkingCopy configuration ) {
108
- // TODO
145
+ // Set defaults for Build Settings
146
+ ICBuildConfiguration buildConfig = getBuildConfiguration ();
147
+ buildConfig .setProperty (CMakeBuildConfiguration .CMAKE_USE_UI_OVERRIDES ,
148
+ CMakeBuildConfiguration .CMAKE_USE_UI_OVERRIDES_DEFAULT );
109
149
}
110
150
111
151
@ Override
@@ -133,10 +173,14 @@ public void initializeFrom(ILaunchConfiguration configuration) {
133
173
134
174
String cleanCommand = buildConfig .getProperty (CMakeBuildConfiguration .CLEAN_COMMAND );
135
175
if (cleanCommand != null ) {
136
- cleanCommandText .setText (buildCommand );
176
+ cleanCommandText .setText (cleanCommand );
137
177
} else {
138
178
cleanCommandText .setText ("" ); //$NON-NLS-1$
139
179
}
180
+
181
+ boolean isSelected = Boolean .valueOf (buildConfig .getProperty (CMakeBuildConfiguration .CMAKE_USE_UI_OVERRIDES ));
182
+ useUiCmakeSettings .setSelection (isSelected );
183
+ updateEnablement ();
140
184
}
141
185
142
186
private void updateGeneratorButtons (String generator ) {
@@ -153,8 +197,8 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
153
197
154
198
ICBuildConfiguration buildConfig = getBuildConfiguration ();
155
199
156
- buildConfig . setProperty ( CMakeBuildConfiguration . CMAKE_GENERATOR ,
157
- ninjaGenButton . getSelection () ? "Ninja" : "Unix Makefiles" ); //$NON-NLS-1$ //$NON-NLS-2$
200
+ String gen = ninjaGenButton . getSelection () ? "Ninja" : "Unix Makefiles" ; //$NON-NLS-1$ //$NON-NLS-2$
201
+ buildConfig . setProperty ( CMakeBuildConfiguration . CMAKE_GENERATOR , gen );
158
202
159
203
String cmakeArgs = cmakeArgsText .getText ().trim ();
160
204
if (!cmakeArgs .isEmpty ()) {
@@ -176,6 +220,13 @@ public void performApply(ILaunchConfigurationWorkingCopy configuration) {
176
220
} else {
177
221
buildConfig .removeProperty (CMakeBuildConfiguration .CLEAN_COMMAND );
178
222
}
223
+
224
+ boolean isSelected = useUiCmakeSettings .getSelection ();
225
+ buildConfig .setProperty (CMakeBuildConfiguration .CMAKE_USE_UI_OVERRIDES , Boolean .toString (isSelected ));
226
+
227
+ Map <String , String > saved = new HashMap <>();
228
+ saved .put (CMakeBuildConfiguration .CMAKE_USE_UI_OVERRIDES , Boolean .toString (isSelected ));
229
+ getBuildConfiguration ().setProperties (saved );
179
230
}
180
231
181
232
@ Override
0 commit comments