diff --git a/src/extension/src/command-executor.ts b/src/extension/src/command-executor.ts index 1a3ffdc2..9ea7507a 100644 --- a/src/extension/src/command-executor.ts +++ b/src/extension/src/command-executor.ts @@ -1,4 +1,5 @@ import * as vscode from "vscode"; +import { MESSAGES } from "../../shared/constants"; import { TerminalExecutor, QuickPickCreator } from "./adapters"; import { findMatchingShortcut } from "./keyboard-layout-converter"; import { ButtonConfig } from "./types"; @@ -85,11 +86,7 @@ export const createQuickPickWithShortcuts = ( const duplicates = validateShortcuts(config.items); if (duplicates.length > 0) { - vscode.window.showErrorMessage( - `Duplicate shortcuts detected: ${duplicates.join( - ", " - )}. Please ensure each shortcut is unique.` - ); + vscode.window.showErrorMessage(MESSAGES.ERROR.duplicateShortcuts(duplicates)); return; } @@ -183,8 +180,8 @@ const showGroupQuickPick = ( createQuickPickWithShortcuts( { items: items, - placeholder: "Select a command to execute", - title: `${button.name} Commands`, + placeholder: MESSAGES.INFO.selectCommand, + title: MESSAGES.INFO.groupCommands(button.name), }, terminalExecutor, quickPickCreator diff --git a/src/extension/src/config-constants.ts b/src/extension/src/config-constants.ts index c4f4a5cc..e8024074 100644 --- a/src/extension/src/config-constants.ts +++ b/src/extension/src/config-constants.ts @@ -1,17 +1,9 @@ import * as vscode from "vscode"; +import { CONFIG, CONFIGURATION_TARGET } from "../../shared/constants"; -export const CONFIG_SECTION = "quickCommandButtons"; - -export const CONFIG_KEYS = { - BUTTONS: "buttons", - CONFIGURATION_TARGET: "configurationTarget", - REFRESH_BUTTON: "refreshButton", -} as const; - -export const CONFIGURATION_TARGETS = { - GLOBAL: "global", - WORKSPACE: "workspace", -} as const; +export const CONFIG_SECTION = CONFIG.SECTION; +export const CONFIG_KEYS = CONFIG.KEYS; +export const CONFIGURATION_TARGETS = CONFIGURATION_TARGET; export const VS_CODE_CONFIGURATION_TARGETS = { [CONFIGURATION_TARGETS.GLOBAL]: vscode.ConfigurationTarget.Global, @@ -19,5 +11,5 @@ export const VS_CODE_CONFIGURATION_TARGETS = { } as const; export type ConfigurationTargetType = - (typeof CONFIGURATION_TARGETS)[keyof typeof CONFIGURATION_TARGETS]; -export type ConfigKeyType = (typeof CONFIG_KEYS)[keyof typeof CONFIG_KEYS]; + (typeof CONFIGURATION_TARGET)[keyof typeof CONFIGURATION_TARGET]; +export type ConfigKeyType = (typeof CONFIG.KEYS)[keyof typeof CONFIG.KEYS]; diff --git a/src/extension/src/show-all-commands.ts b/src/extension/src/show-all-commands.ts index 3734614d..eee0ac21 100644 --- a/src/extension/src/show-all-commands.ts +++ b/src/extension/src/show-all-commands.ts @@ -1,4 +1,5 @@ import * as vscode from "vscode"; +import { MESSAGES } from "../../shared/constants"; import { ConfigReader, QuickPickCreator, TerminalExecutor } from "./adapters"; import { createQuickPickWithShortcuts, QuickPickItem } from "./command-executor"; import { ButtonConfig } from "./types"; @@ -6,7 +7,9 @@ import { ButtonConfig } from "./types"; export const createQuickPickItemsFromButtons = (buttons: ButtonConfig[]): QuickPickItem[] => { return buttons.map((button) => ({ command: button, - description: button.group ? `${button.group.length} commands` : button.command || "", + description: button.group + ? MESSAGES.INFO.commandsCount(button.group.length) + : button.command || "", label: button.shortcut ? `${button.name} (${button.shortcut})` : button.name, })); }; @@ -20,7 +23,7 @@ export const createShowAllCommandsCommand = ( const buttons = configReader.getButtons(); if (buttons.length === 0) { - vscode.window.showInformationMessage("No commands found"); + vscode.window.showInformationMessage(MESSAGES.ERROR.noCommands); return; } @@ -29,8 +32,8 @@ export const createShowAllCommandsCommand = ( createQuickPickWithShortcuts( { items: items, - placeholder: "Select a command/group to execute (or type shortcut key)", - title: "Quick Commands", + placeholder: MESSAGES.INFO.selectCommandOrGroup, + title: MESSAGES.INFO.quickCommands, }, terminalExecutor, quickPickCreator diff --git a/src/shared/constants.ts b/src/shared/constants.ts new file mode 100644 index 00000000..88db34e5 --- /dev/null +++ b/src/shared/constants.ts @@ -0,0 +1,38 @@ +export const CONFIG = { + SECTION: "quickCommandButtons", + KEYS: { + BUTTONS: "buttons", + CONFIGURATION_TARGET: "configurationTarget", + REFRESH_BUTTON: "refreshButton", + }, +} as const; + +export const CONFIGURATION_TARGET = { + GLOBAL: "global", + WORKSPACE: "workspace", +} as const; + +export const MESSAGE_TYPE = { + GET_CONFIG: "getConfig", + SET_CONFIG: "setConfig", + SET_CONFIGURATION_TARGET: "setConfigurationTarget", + CONFIG_DATA: "configData", + CONFIGURATION_TARGET_CHANGED: "configurationTargetChanged", +} as const; + +export const MESSAGES = { + ERROR: { + contextRequired: (hookName: string) => + `${hookName} must be used within a VscodeCommandProvider`, + duplicateShortcuts: (shortcuts: string[]) => + `Duplicate shortcuts detected: ${shortcuts.join(", ")}. Please ensure each shortcut is unique.`, + noCommands: "No commands found", + }, + INFO: { + selectCommand: "Select a command to execute", + selectCommandOrGroup: "Select a command/group to execute (or type shortcut key)", + quickCommands: "Quick Commands", + groupCommands: (buttonName: string) => `${buttonName} Commands`, + commandsCount: (count: number) => `${count} commands`, + }, +} as const; diff --git a/src/web-view/src/components/header.tsx b/src/web-view/src/components/header.tsx index 60aa7186..d8852e46 100644 --- a/src/web-view/src/components/header.tsx +++ b/src/web-view/src/components/header.tsx @@ -1,5 +1,6 @@ import { Button } from "~/core"; +import { CONFIGURATION_TARGET } from "../../../shared/constants"; import { useCommandForm } from "../context/command-form-context.tsx"; import { useVscodeCommand } from "../context/vscode-command-context.tsx"; import { useDarkMode } from "../hooks/use-dark-mode.tsx"; @@ -10,7 +11,10 @@ export const Header = () => { const { isDark, toggleTheme } = useDarkMode(); const toggleConfigurationTarget = () => { - const newTarget = configurationTarget === "workspace" ? "global" : "workspace"; + const newTarget = + configurationTarget === CONFIGURATION_TARGET.WORKSPACE + ? CONFIGURATION_TARGET.GLOBAL + : CONFIGURATION_TARGET.WORKSPACE; setConfigurationTarget(newTarget); }; @@ -36,12 +40,12 @@ export const Header = () => {