Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@
"title": "Open Configuration UI",
"category": "Quick Commands",
"icon": "$(gear)"
},
{
"command": "quickCommandButtons.toggleConfigurationTarget",
"title": "Toggle Configuration Target (Workspace/Global)",
"category": "Quick Commands"
}
],
"viewsContainers": {
Expand Down Expand Up @@ -120,6 +125,16 @@
}
}
},
"quickCommandButtons.configurationTarget": {
"type": "string",
"enum": ["workspace", "global"],
"default": "workspace",
"description": "Where to save button configurations: 'workspace' saves to .vscode/settings.json (project-specific), 'global' saves to user settings (shared across all projects)",
"enumDescriptions": [
"Save to workspace settings (.vscode/settings.json) - project-specific commands",
"Save to user settings - shared across all projects"
]
},
"quickCommandButtons.buttons": {
"type": "array",
"default": [
Expand Down
23 changes: 23 additions & 0 deletions src/extension/src/config-constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as vscode from "vscode";

export const CONFIG_SECTION = "quickCommandButtons";

export const CONFIG_KEYS = {
BUTTONS: "buttons",
CONFIGURATION_TARGET: "configurationTarget",
REFRESH_BUTTON: "refreshButton",
} as const;

export const CONFIGURATION_TARGETS = {
WORKSPACE: "workspace",
GLOBAL: "global",
} as const;

export const VS_CODE_CONFIGURATION_TARGETS = {
[CONFIGURATION_TARGETS.WORKSPACE]: vscode.ConfigurationTarget.Workspace,
[CONFIGURATION_TARGETS.GLOBAL]: vscode.ConfigurationTarget.Global,
} as const;

export type ConfigurationTargetType =
(typeof CONFIGURATION_TARGETS)[keyof typeof CONFIGURATION_TARGETS];
export type ConfigKeyType = (typeof CONFIG_KEYS)[keyof typeof CONFIG_KEYS];
89 changes: 89 additions & 0 deletions src/extension/src/config-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import * as vscode from "vscode";
import { ButtonConfig } from "./types";
import {
CONFIG_SECTION,
CONFIG_KEYS,
CONFIGURATION_TARGETS,
VS_CODE_CONFIGURATION_TARGETS,
ConfigurationTargetType,
} from "./config-constants";

export class ConfigManager {
static getCurrentConfigurationTarget(): ConfigurationTargetType {
const config = vscode.workspace.getConfiguration(CONFIG_SECTION);
return config.get<ConfigurationTargetType>(
CONFIG_KEYS.CONFIGURATION_TARGET,
CONFIGURATION_TARGETS.WORKSPACE
);
}

static getVSCodeConfigurationTarget(): vscode.ConfigurationTarget {
const currentTarget = this.getCurrentConfigurationTarget();
return VS_CODE_CONFIGURATION_TARGETS[currentTarget];
}

static async updateConfigurationTarget(
target: ConfigurationTargetType
): Promise<void> {
try {
const config = vscode.workspace.getConfiguration(CONFIG_SECTION);
await config.update(
CONFIG_KEYS.CONFIGURATION_TARGET,
target,
vscode.ConfigurationTarget.Global // Configuration target setting itself should always be global
);

const targetMessage =
target === CONFIGURATION_TARGETS.GLOBAL
? "user settings (shared across all projects)"
: "workspace settings (project-specific)";

vscode.window.showInformationMessage(
`Configuration target changed to: ${targetMessage}`
);
} catch (error) {
console.error("Failed to update configuration target:", error);
vscode.window.showErrorMessage(
"Failed to update configuration target. Please try again."
);
}
}

static async updateButtonConfiguration(
buttons: ButtonConfig[]
): Promise<void> {
try {
const config = vscode.workspace.getConfiguration(CONFIG_SECTION);
const target = this.getVSCodeConfigurationTarget();

await config.update(CONFIG_KEYS.BUTTONS, buttons, target);

const currentTarget = this.getCurrentConfigurationTarget();
const targetMessage =
currentTarget === CONFIGURATION_TARGETS.GLOBAL
? "user settings"
: "workspace settings";

vscode.window.showInformationMessage(
`Configuration updated successfully in ${targetMessage}!`
);
} catch (error) {
console.error("Failed to update configuration:", error);
vscode.window.showErrorMessage(
"Failed to update configuration. Please try again."
);
}
}

static getConfigDataForWebview(configReader: {
getButtons(): ButtonConfig[];
}): {
buttons: ButtonConfig[];
configurationTarget: ConfigurationTargetType;
} {
return {
buttons: configReader.getButtons(),
configurationTarget: this.getCurrentConfigurationTarget(),
};
}
}
1 change: 1 addition & 0 deletions src/extension/src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ describe("main", () => {
refreshTreeCommand: "mockDisposable",
showAllCommandsCommand: "mockDisposable",
openConfigCommand: "mockDisposable",
toggleConfigurationTargetCommand: "mockDisposable",
});
});
});
Expand Down
16 changes: 16 additions & 0 deletions src/extension/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
createVSCodeStatusBarCreator,
createVSCodeQuickPickCreator,
} from "./adapters";
import { ConfigManager } from "./config-manager";
import { CONFIGURATION_TARGETS } from "./config-constants";

export const registerCommands = (
context: vscode.ExtensionContext,
Expand Down Expand Up @@ -67,13 +69,27 @@ export const registerCommands = (
)
);

const toggleConfigurationTargetCommand = vscode.commands.registerCommand(
"quickCommandButtons.toggleConfigurationTarget",
async () => {
const currentTarget = ConfigManager.getCurrentConfigurationTarget();
const newTarget =
currentTarget === CONFIGURATION_TARGETS.WORKSPACE
? CONFIGURATION_TARGETS.GLOBAL
: CONFIGURATION_TARGETS.WORKSPACE;

await ConfigManager.updateConfigurationTarget(newTarget);
}
);

return {
executeCommand,
executeFromTreeCommand,
refreshCommand,
refreshTreeCommand,
showAllCommandsCommand,
openConfigCommand,
toggleConfigurationTargetCommand,
};
};

Expand Down
Loading