Skip to content

Commit 4cbb4fb

Browse files
committed
Move CMake Tools option out of advanced settings
Also make it persistent like entry point naming preferences, and make both update whenever toggled, rather than only updating when projects are created
1 parent 97c49e8 commit 4cbb4fb

File tree

3 files changed

+46
-3
lines changed

3 files changed

+46
-3
lines changed

src/settings.mts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export type GlobalStateType = Memento & {
3434

3535
const LAST_PROJECT_ROOT_STATE_KEY = "lastProjectRoot";
3636
const ENTRY_POINT_NAMING_PREF = "entryPointNamingPref";
37+
const CMAKE_TOOLS_PREF = "cmakeToolsPref";
3738

3839
export default class Settings {
3940
private static instance?: Settings;
@@ -149,4 +150,12 @@ export default class Settings {
149150
public getEntryPointNamingPref(): boolean {
150151
return this.globalState.get<boolean>(ENTRY_POINT_NAMING_PREF, true);
151152
}
153+
154+
public async setCMakeToolsPref(useCMakeTools: boolean): Promise<void> {
155+
await this.globalState.update(CMAKE_TOOLS_PREF, useCMakeTools);
156+
}
157+
158+
public getCMakeToolsPref(): boolean {
159+
return this.globalState.get<boolean>(CMAKE_TOOLS_PREF, false);
160+
}
152161
}

src/webview/newProjectPanel.mts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ interface SubmitMessageValue extends ImportProjectMessageValue {
120120

121121
export interface WebviewMessage {
122122
command: string;
123-
value: object | string | SubmitMessageValue;
123+
value: object | string | SubmitMessageValue | boolean;
124+
key?: string;
124125
}
125126

126127
enum BoardType {
@@ -768,6 +769,20 @@ export class NewProjectPanel {
768769
);
769770
}
770771
break;
772+
case 'updateSetting':
773+
{
774+
const key = message.key as string;
775+
const value = message.value as boolean;
776+
switch (key) {
777+
case "cmakeTools":
778+
await this._settings.setCMakeToolsPref(value);
779+
break;
780+
case "entryProjectName":
781+
await this._settings.setEntryPointNamingPref(value);
782+
break;
783+
}
784+
}
785+
break;
771786
}
772787
},
773788
null,
@@ -1633,8 +1648,11 @@ export class NewProjectPanel {
16331648
// Restrict the webview to only load specific scripts
16341649
const nonce = getNonce();
16351650
const isWindows = process.platform === "win32";
1651+
1652+
// Get the default values from global state
16361653
const useProjectNameAsEntryPointFileName =
16371654
this._settings.getEntryPointNamingPref();
1655+
const defaultUseCmakeTools = this._settings.getCMakeToolsPref();
16381656

16391657
return `<!DOCTYPE html>
16401658
<html lang="en">
@@ -2163,11 +2181,15 @@ export class NewProjectPanel {
21632181
</div>
21642182
</div>
21652183
</div>
2166-
<div id="section-extension-integration" class="snap-end advanced-option" hidden>
2184+
<div id="section-extension-integration" class="snap-end">
21672185
<h3 class="text-xl font-semibold text-gray-900 dark:text-white mb-8">CMake Tools</h3>
21682186
<div class="flex items-stretch space-x-4">
21692187
<div class="flex items-center px-4 py-2 border border-gray-200 rounded dark:border-gray-700">
2170-
<input id="use-cmake-tools-cb" type="checkbox" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 outline-none focus:ring-0 focus:ring-offset-5 dark:bg-gray-700 dark:border-gray-600">
2188+
<input id="use-cmake-tools-cb" type="checkbox" class="w-4 h-4 text-blue-600 bg-gray-100 border-gray-300 outline-none focus:ring-0 focus:ring-offset-5 dark:bg-gray-700 dark:border-gray-600" ${
2189+
defaultUseCmakeTools
2190+
? 'checked'
2191+
: ''
2192+
}>
21712193
<label for="use-cmake-tools-cb" class="w-full py-4 ml-2 text-sm font-medium text-gray-900 dark:text-gray-300">Enable CMake-Tools extension integration</label>
21722194
</div>
21732195
</div>

web/state.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,12 @@ function setupStateSystem(vscode) {
401401
break;
402402
case "entry-project-name-code-gen-cblist":
403403
state.entryProjectNameCodeGen = checkbox.checked;
404+
// Send message to update the global preference
405+
vscode.postMessage({
406+
command: 'updateSetting',
407+
key: 'entryProjectName',
408+
value: checkbox.checked
409+
});
404410
break;
405411
case "cpp-code-gen-cblist":
406412
state.cppCodeGen = checkbox.checked;
@@ -416,6 +422,12 @@ function setupStateSystem(vscode) {
416422
break;
417423
case "use-cmake-tools-cb":
418424
state.useCMakeTools = checkbox.checked;
425+
// Send message to update the global preference
426+
vscode.postMessage({
427+
command: 'updateSetting',
428+
key: 'cmakeTools',
429+
value: checkbox.checked
430+
});
419431
break;
420432
}
421433

0 commit comments

Comments
 (0)