From 4c302ddbb2eed7cf6ade912bea2d7d8be0c96ead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=91=98=E5=B0=8F=E5=A2=A8?= <2291200076@qq.com> Date: Mon, 29 Jul 2024 22:54:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=B3=E9=94=AE=E8=8F=9C=E5=8D=95=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=BF=87=E6=BB=A4=E7=94=A8=E6=88=B7=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E7=9A=84=E7=A6=81=E7=94=A8=E6=A0=BC=E5=BC=8F=20(disableFormat)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-comment.jsonc | 20 ++++ package.json | 20 ++++ src/extension.ts | 9 ++ src/type-definition/SupportCaseType.ts | 132 ++++++++++++++++++++----- 4 files changed, 155 insertions(+), 26 deletions(-) diff --git a/package-comment.jsonc b/package-comment.jsonc index bb8b9b5..f8d9de9 100644 --- a/package-comment.jsonc +++ b/package-comment.jsonc @@ -225,87 +225,107 @@ "variable-conversion.stringConversionMenu": [ // group-1-camel { + "when": "!_isHideSubMenuItem_camel_case", "command": "variable-conversion.toCamelCase", "group": "group-1-camel@1" }, { + "when": "!_isHideSubMenuItem_pascal_case", "command": "variable-conversion.toPascalCase", "group": "group-1-camel@2" }, // group-2-snake { + "when": "!_isHideSubMenuItem_snake_case", "command": "variable-conversion.toSnakeCase", "group": "group-2-snake@1" }, { + "when": "!_isHideSubMenuItem_snake_upper_case", "command": "variable-conversion.toSnakeUpperCase", "group": "group-2-snake@2" }, { + "when": "!_isHideSubMenuItem_snake_pascal_case", "command": "variable-conversion.toSnakePascalCase", "group": "group-2-snake@3" }, { + "when": "!_isHideSubMenuItem_snake_camel_case", "command": "variable-conversion.toSnakeCamelCase", "group": "group-2-snake@4" }, // group-3-kebab { + "when": "!_isHideSubMenuItem_kebab_case", "command": "variable-conversion.toKebabCase", "group": "group-3-kebab@1" }, { + "when": "!_isHideSubMenuItem_kebab_upper_case", "command": "variable-conversion.toKebabUpperCase", "group": "group-3-kebab@2" }, { + "when": "!_isHideSubMenuItem_kebab_pascal_case", "command": "variable-conversion.toKebabPascalCase", "group": "group-3-kebab@3" }, { + "when": "!_isHideSubMenuItem_kebab_camel_case", "command": "variable-conversion.toKebabCamelCase", "group": "group-3-kebab@4" }, // group-4-space { + "when": "!_isHideSubMenuItem_space_case", "command": "variable-conversion.toSpaceCase", "group": "group-4-space@1" }, { + "when": "!_isHideSubMenuItem_space_upper_case", "command": "variable-conversion.toSpaceUpperCase", "group": "group-4-space@2" }, { + "when": "!_isHideSubMenuItem_space_pascal_case", "command": "variable-conversion.toSpacePascalCase", "group": "group-4-space@3" }, { + "when": "!_isHideSubMenuItem_space_camel_case", "command": "variable-conversion.toSpaceCamelCase", "group": "group-4-space@4" }, // group-5-dot { + "when": "!_isHideSubMenuItem_dot_case", "command": "variable-conversion.toDotCase", "group": "group-5-dot@1" }, { + "when": "!_isHideSubMenuItem_dot_upper_case", "command": "variable-conversion.toDotUpperCase", "group": "group-5-dot@2" }, { + "when": "!_isHideSubMenuItem_dot_pascal_case", "command": "variable-conversion.toDotPascalCase", "group": "group-5-dot@3" }, { + "when": "!_isHideSubMenuItem_dot_camel_case", "command": "variable-conversion.toDotCamelCase", "group": "group-5-dot@4" }, // group-6-upper-lower { + "when": "!_isHideSubMenuItem_lower_case", "command": "variable-conversion.toLowerCase", "group": "group-6-upper-lower@1" }, { + "when": "!_isHideSubMenuItem_upper_case", "command": "variable-conversion.toUpperCase", "group": "group-6-upper-lower@2" } diff --git a/package.json b/package.json index 8b0aa8d..c08753e 100644 --- a/package.json +++ b/package.json @@ -155,82 +155,102 @@ ], "variable-conversion.stringConversionMenu": [ { + "when": "!_isHideSubMenuItem_camel_case", "command": "variable-conversion.toCamelCase", "group": "group-1-camel@1" }, { + "when": "!_isHideSubMenuItem_pascal_case", "command": "variable-conversion.toPascalCase", "group": "group-1-camel@2" }, { + "when": "!_isHideSubMenuItem_snake_case", "command": "variable-conversion.toSnakeCase", "group": "group-2-snake@1" }, { + "when": "!_isHideSubMenuItem_snake_upper_case", "command": "variable-conversion.toSnakeUpperCase", "group": "group-2-snake@2" }, { + "when": "!_isHideSubMenuItem_snake_pascal_case", "command": "variable-conversion.toSnakePascalCase", "group": "group-2-snake@3" }, { + "when": "!_isHideSubMenuItem_snake_camel_case", "command": "variable-conversion.toSnakeCamelCase", "group": "group-2-snake@4" }, { + "when": "!_isHideSubMenuItem_kebab_case", "command": "variable-conversion.toKebabCase", "group": "group-3-kebab@1" }, { + "when": "!_isHideSubMenuItem_kebab_upper_case", "command": "variable-conversion.toKebabUpperCase", "group": "group-3-kebab@2" }, { + "when": "!_isHideSubMenuItem_kebab_pascal_case", "command": "variable-conversion.toKebabPascalCase", "group": "group-3-kebab@3" }, { + "when": "!_isHideSubMenuItem_kebab_camel_case", "command": "variable-conversion.toKebabCamelCase", "group": "group-3-kebab@4" }, { + "when": "!_isHideSubMenuItem_space_case", "command": "variable-conversion.toSpaceCase", "group": "group-4-space@1" }, { + "when": "!_isHideSubMenuItem_space_upper_case", "command": "variable-conversion.toSpaceUpperCase", "group": "group-4-space@2" }, { + "when": "!_isHideSubMenuItem_space_pascal_case", "command": "variable-conversion.toSpacePascalCase", "group": "group-4-space@3" }, { + "when": "!_isHideSubMenuItem_space_camel_case", "command": "variable-conversion.toSpaceCamelCase", "group": "group-4-space@4" }, { + "when": "!_isHideSubMenuItem_dot_case", "command": "variable-conversion.toDotCase", "group": "group-5-dot@1" }, { + "when": "!_isHideSubMenuItem_dot_upper_case", "command": "variable-conversion.toDotUpperCase", "group": "group-5-dot@2" }, { + "when": "!_isHideSubMenuItem_dot_pascal_case", "command": "variable-conversion.toDotPascalCase", "group": "group-5-dot@3" }, { + "when": "!_isHideSubMenuItem_dot_camel_case", "command": "variable-conversion.toDotCamelCase", "group": "group-5-dot@4" }, { + "when": "!_isHideSubMenuItem_lower_case", "command": "variable-conversion.toLowerCase", "group": "group-6-upper-lower@1" }, { + "when": "!_isHideSubMenuItem_upper_case", "command": "variable-conversion.toUpperCase", "group": "group-6-upper-lower@2" } diff --git a/src/extension.ts b/src/extension.ts index f99605c..5e6464f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -7,6 +7,7 @@ import { commands } from './type-definition/SupportCaseType'; import { createStatusBarItem, updateStatusBarItemVisable } from './extension-handler/status-bar-handler'; import * as CyclicConversion from './main-code/cyclic-conversion'; import { EOL } from './type-definition/EOLType'; +import { getUserConfigurations } from './main-code/user-configuration'; // This method is called when your extension is activated // Your extension is activated the very first time the command is executed @@ -41,6 +42,14 @@ export function activate(context: vscode.ExtensionContext) { // 更新 _textSelectionLength (用于判断是否展示右键菜单) vscode.commands.executeCommand('setContext', '_textSelectionLength', selectTextLength); + // issue: #1 https://github.com/coder-xiaomo/variable-conversion-vscode-extension/issues/1 + // 获取用户配置 + const disableFormatList = getUserConfigurations('disableFormat'); + // 更新右键菜单每一项是否展示 + for (const { settingsKey } of commands) { + vscode.commands.executeCommand('setContext', '_isHideSubMenuItem_' + settingsKey, disableFormatList.includes(settingsKey)); + } + // 判断是否展示状态栏按钮 updateStatusBarItemVisable(selectTextLength); diff --git a/src/type-definition/SupportCaseType.ts b/src/type-definition/SupportCaseType.ts index 65bc12c..a6f0706 100644 --- a/src/type-definition/SupportCaseType.ts +++ b/src/type-definition/SupportCaseType.ts @@ -281,32 +281,112 @@ const keyword = { /** * 接管的变量转换命令 */ -export const commands: Array<{ command: string; targetCase: SupportCase }> = [ - { command: 'variable-conversion.toCamelCase', targetCase: SupportCase.CAMEL_CASE }, - { command: 'variable-conversion.toPascalCase', targetCase: SupportCase.PASCAL_CASE }, - - { command: 'variable-conversion.toSnakeCase', targetCase: SupportCase.SNAKE_CASE }, - { command: 'variable-conversion.toSnakeUpperCase', targetCase: SupportCase.SNAKE_UPPER_CASE }, - { command: 'variable-conversion.toSnakePascalCase', targetCase: SupportCase.SNAKE_PASCAL_CASE }, - { command: 'variable-conversion.toSnakeCamelCase', targetCase: SupportCase.SNAKE_CAMEL_CASE }, - - { command: 'variable-conversion.toKebabCase', targetCase: SupportCase.KEBAB_CASE }, - { command: 'variable-conversion.toKebabUpperCase', targetCase: SupportCase.KEBAB_UPPER_CASE }, - { command: 'variable-conversion.toKebabPascalCase', targetCase: SupportCase.KEBAB_PASCAL_CASE }, - { command: 'variable-conversion.toKebabCamelCase', targetCase: SupportCase.KEBAB_CAMEL_CASE }, - - { command: 'variable-conversion.toSpaceCase', targetCase: SupportCase.SPACE_CASE }, - { command: 'variable-conversion.toSpaceUpperCase', targetCase: SupportCase.SPACE_UPPER_CASE }, - { command: 'variable-conversion.toSpacePascalCase', targetCase: SupportCase.SPACE_PASCAL_CASE }, - { command: 'variable-conversion.toSpaceCamelCase', targetCase: SupportCase.SPACE_CAMEL_CASE }, - - { command: 'variable-conversion.toDotCase', targetCase: SupportCase.DOT_CASE }, - { command: 'variable-conversion.toDotUpperCase', targetCase: SupportCase.DOT_UPPER_CASE }, - { command: 'variable-conversion.toDotPascalCase', targetCase: SupportCase.DOT_PASCAL_CASE }, - { command: 'variable-conversion.toDotCamelCase', targetCase: SupportCase.DOT_CAMEL_CASE }, - - { command: 'variable-conversion.toLowerCase', targetCase: SupportCase.LOWER_CASE }, - { command: 'variable-conversion.toUpperCase', targetCase: SupportCase.UPPER_CASE }, +export const commands: Array<{ command: string; targetCase: SupportCase; settingsKey: string }> = [ + { + command: 'variable-conversion.toCamelCase', + targetCase: SupportCase.CAMEL_CASE, + settingsKey: 'camel_case' + }, + { + command: 'variable-conversion.toPascalCase', + targetCase: SupportCase.PASCAL_CASE, + settingsKey: 'pascal_case' + }, + // +++++++++++++++++++++++++++++++++++++++++++++++ + { + command: 'variable-conversion.toSnakeCase', + targetCase: SupportCase.SNAKE_CASE, + settingsKey: 'snake_case' + }, + { + command: 'variable-conversion.toSnakeUpperCase', + targetCase: SupportCase.SNAKE_UPPER_CASE, + settingsKey: 'snake_upper_case' + }, + { + command: 'variable-conversion.toSnakePascalCase', + targetCase: SupportCase.SNAKE_PASCAL_CASE, + settingsKey: 'snake_pascal_case' + }, + { + command: 'variable-conversion.toSnakeCamelCase', + targetCase: SupportCase.SNAKE_CAMEL_CASE, + settingsKey: 'snake_camel_case' + }, + // +++++++++++++++++++++++++++++++++++++++++++++++ + { + command: 'variable-conversion.toKebabCase', + targetCase: SupportCase.KEBAB_CASE, + settingsKey: 'kebab_case' + }, + { + command: 'variable-conversion.toKebabUpperCase', + targetCase: SupportCase.KEBAB_UPPER_CASE, + settingsKey: 'kebab_upper_case' + }, + { + command: 'variable-conversion.toKebabPascalCase', + targetCase: SupportCase.KEBAB_PASCAL_CASE, + settingsKey: 'kebab_pascal_case' + }, + { + command: 'variable-conversion.toKebabCamelCase', + targetCase: SupportCase.KEBAB_CAMEL_CASE, + settingsKey: 'kebab_camel_case' + }, + // +++++++++++++++++++++++++++++++++++++++++++++++ + { + command: 'variable-conversion.toSpaceCase', + targetCase: SupportCase.SPACE_CASE, + settingsKey: 'space_case' + }, + { + command: 'variable-conversion.toSpaceUpperCase', + targetCase: SupportCase.SPACE_UPPER_CASE, + settingsKey: 'space_upper_case' + }, + { + command: 'variable-conversion.toSpacePascalCase', + targetCase: SupportCase.SPACE_PASCAL_CASE, + settingsKey: 'space_pascal_case' + }, + { + command: 'variable-conversion.toSpaceCamelCase', + targetCase: SupportCase.SPACE_CAMEL_CASE, + settingsKey: 'space_camel_case' + }, + // +++++++++++++++++++++++++++++++++++++++++++++++ + { + command: 'variable-conversion.toDotCase', + targetCase: SupportCase.DOT_CASE, + settingsKey: 'dot_case' + }, + { + command: 'variable-conversion.toDotUpperCase', + targetCase: SupportCase.DOT_UPPER_CASE, + settingsKey: 'dot_upper_case' + }, + { + command: 'variable-conversion.toDotPascalCase', + targetCase: SupportCase.DOT_PASCAL_CASE, + settingsKey: 'dot_pascal_case' + }, + { + command: 'variable-conversion.toDotCamelCase', + targetCase: SupportCase.DOT_CAMEL_CASE, + settingsKey: 'dot_camel_case' + }, + // +++++++++++++++++++++++++++++++++++++++++++++++ + { + command: 'variable-conversion.toLowerCase', + targetCase: SupportCase.LOWER_CASE, + settingsKey: 'lower_case' + }, + { + command: 'variable-conversion.toUpperCase', + targetCase: SupportCase.UPPER_CASE, + settingsKey: 'upper_case' + }, ]; export interface QuickPickSupportCaseItem {