diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cab0cb..65570a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 --> +## 1.0.6 + +### Added + +- Add a status bar button to trigger string conversion (添加底栏按钮,支持通过底栏按钮触发字符串转换) + ## 1.0.5 ### Fixed diff --git a/README.md b/README.md index ce150b6..274c4f5 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,22 @@ A powerful variable naming conversion extension. You can use it through the edit > 可以通过 `Ctrl + D` 快捷键选中光标所在的单词
> You can press `Ctrl + D` to select the word near the cursor -#### 2. 按 `Shift + Alt + T`
Press `Shift + Alt + T` +#### 2. 按 `Shift + Alt + T`
Press `Shift + Alt + T` ![Step2. Press Shift + Alt + T](image/step2-press-shift-alt-t.gif) -或者右键 -> 将字符串转换为...
Or right-click on the selected text -> Convert string to... +或者点击状态栏的 `字符串转换` 按钮
+Or click the `String Conversion` button in the status bar + +![Step2. Press Status Bar Button](image/step2-press-status-bar-button.png) + +或者右键 -> `字符串转换`
+Or right-click -> `String Conversion` + +![Step2. Variable conversion on the context menu](image/step2-variable-conversion-on-context-menu.png) + +或者右键 -> 将字符串转换为...
+Or right-click on the selected text -> Convert string to... ![Step2. Right-click on the selected text](image/step2-right-click-on-the-selected-text.gif) diff --git a/image/step2-press-status-bar-button.png b/image/step2-press-status-bar-button.png new file mode 100644 index 0000000..79652ea Binary files /dev/null and b/image/step2-press-status-bar-button.png differ diff --git a/image/step2-variable-conversion-on-context-menu.png b/image/step2-variable-conversion-on-context-menu.png new file mode 100644 index 0000000..1a69de1 Binary files /dev/null and b/image/step2-variable-conversion-on-context-menu.png differ diff --git a/package-comment.jsonc b/package-comment.jsonc index eb830e1..a5ef665 100644 --- a/package-comment.jsonc +++ b/package-comment.jsonc @@ -4,7 +4,7 @@ "displayName": "Variable Conversion", "description": "一个强大的变量名转换插件,支持右键菜单、快捷键、底栏等多种方式使用,支持小驼峰、大驼峰(帕斯卡)、下划线(蛇形)、连字符(脊柱式)、全小写、全大写等常用命名方式(及组合)转换。 \nA powerful variable naming conversion extension. You can use it through the editer menu, shortcut keys and bottom bar. Support camel, pascal, snake, kebab(spinal), lower, upper case, and more.", // 版本号 - "version": "0.0.5", + "version": "0.0.6", // logo "icon": "image/logo.png", "publisher": "coder-xiaomo", diff --git a/package.json b/package.json index c483ea5..8c0ac22 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "variable-conversion", "displayName": "Variable Conversion", "description": "一个强大的变量名转换插件,支持右键菜单、快捷键、底栏等多种方式使用,支持小驼峰、大驼峰(帕斯卡)、下划线(蛇形)、连字符(脊柱式)、全小写、全大写等常用命名方式(及组合)转换。 \nA powerful variable naming conversion extension. You can use it through the editer menu, shortcut keys and bottom bar. Support camel, pascal, snake, kebab(spinal), lower, upper case, and more.", - "version": "0.0.5", + "version": "0.0.6", "icon": "image/logo.png", "publisher": "coder-xiaomo", "engines": { diff --git a/src/extension-handler/status-bar-handler.ts b/src/extension-handler/status-bar-handler.ts new file mode 100644 index 0000000..45c4405 --- /dev/null +++ b/src/extension-handler/status-bar-handler.ts @@ -0,0 +1,32 @@ +import * as vscode from 'vscode'; + +// docs: https://code.visualstudio.com/api/references/vscode-api#StatusBarItem + +let statusBar: vscode.StatusBarItem; + +/** + * @since 2024-04-07 + */ +export function createStatusBarItem() { + statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); + statusBar.text = '$(find-replace)字符串转换'; + statusBar.command = 'variable-conversion.convertCase'; + // statusBar.color = 'red'; + // statusBar.show(); +} + +/** + * @since 2024-04-07 + */ +export function updateStatusBarItemVisable(selectTextLength: number) { + if (!statusBar) { + return; + } + + let editor = vscode.window.activeTextEditor; + if (editor && selectTextLength > 0) { + statusBar.show(); + return; + } + statusBar.hide(); +} \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index a20b894..4f72623 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -4,6 +4,7 @@ import * as vscode from 'vscode'; import handleEditorReplace from './extension-handler/editor-submenu-handler'; import { handleQuickPick } from './extension-handler/quick-pick-handler'; import { SupportCase } from './type-definition/SupportCaseType'; +import { createStatusBarItem, updateStatusBarItemVisable } from './extension-handler/status-bar-handler'; // This method is called when your extension is activated // Your extension is activated the very first time the command is executed @@ -22,11 +23,20 @@ export function activate(context: vscode.ExtensionContext) { // vscode.window.showInformationMessage('Hello World from variable-conversion!'); // }); + let selectTextLength = 0; + createStatusBarItem(); + vscode.window.onDidChangeActiveTextEditor(event => { + updateStatusBarItemVisable(selectTextLength); + }); + // 用于判断是否展示右键菜单 vscode.window.onDidChangeTextEditorSelection(event => { const text = event.textEditor.document.getText(event.selections[0]); // console.log('text.length', text.length); vscode.commands.executeCommand('setContext', '_textSelectionLength', text.length); + + selectTextLength = text.length; + updateStatusBarItemVisable(selectTextLength); }); // 初始(VSCode 插件初始化)时也判断一次 (考虑上次关闭 VSCode 有选区,重新打开后 VSCode 回复选区但用户未重新切换选区的场景) @@ -37,6 +47,9 @@ export function activate(context: vscode.ExtensionContext) { // 获取选中的文本 let text = document.getText(selection); vscode.commands.executeCommand('setContext', '_textSelectionLength', text.length); + + selectTextLength = text.length; + updateStatusBarItemVisable(selectTextLength); } else { // vscode.window.showInformationMessage('editor is undefined'); console.log('editor is undefined');