1
0
Code Issues Pull Requests Packages Projects Releases Wiki Activity GitHub Gitee

添加底栏按钮,支持通过底栏按钮触发字符串转换;更新 README.md;release version 1.0.6

This commit is contained in:
程序员小墨 2024-04-07 03:50:00 +08:00
parent 6a4c6588c8
commit eedf861ea7
8 changed files with 66 additions and 4 deletions

View File

@ -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 ## 1.0.5
### Fixed ### Fixed

View File

@ -19,7 +19,18 @@ A powerful variable naming conversion extension. You can use it through the edit
![Step2. Press Shift + Alt + T](image/step2-press-shift-alt-t.gif) ![Step2. Press Shift + Alt + T](image/step2-press-shift-alt-t.gif)
或者右键 -> 将字符串转换为... <br>Or right-click on the selected text -> Convert string to... 或者点击状态栏的 `字符串转换` 按钮<br>
Or click the `String Conversion` button in the status bar
![Step2. Press Status Bar Button](image/step2-press-status-bar-button.png)
或者右键 -> `字符串转换`<br>
Or right-click -> `String Conversion`
![Step2. Variable conversion on the context menu](image/step2-variable-conversion-on-context-menu.png)
或者右键 -> 将字符串转换为... <br>
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) ![Step2. Right-click on the selected text](image/step2-right-click-on-the-selected-text.gif)

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

View File

@ -4,7 +4,7 @@
"displayName": "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.", "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 // logo
"icon": "image/logo.png", "icon": "image/logo.png",
"publisher": "coder-xiaomo", "publisher": "coder-xiaomo",

View File

@ -2,7 +2,7 @@
"name": "variable-conversion", "name": "variable-conversion",
"displayName": "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.", "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", "icon": "image/logo.png",
"publisher": "coder-xiaomo", "publisher": "coder-xiaomo",
"engines": { "engines": {

View File

@ -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();
}

View File

@ -4,6 +4,7 @@ import * as vscode from 'vscode';
import handleEditorReplace from './extension-handler/editor-submenu-handler'; import handleEditorReplace from './extension-handler/editor-submenu-handler';
import { handleQuickPick } from './extension-handler/quick-pick-handler'; import { handleQuickPick } from './extension-handler/quick-pick-handler';
import { SupportCase } from './type-definition/SupportCaseType'; import { SupportCase } from './type-definition/SupportCaseType';
import { createStatusBarItem, updateStatusBarItemVisable } from './extension-handler/status-bar-handler';
// This method is called when your extension is activated // This method is called when your extension is activated
// Your extension is activated the very first time the command is executed // 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!'); // vscode.window.showInformationMessage('Hello World from variable-conversion!');
// }); // });
let selectTextLength = 0;
createStatusBarItem();
vscode.window.onDidChangeActiveTextEditor(event => {
updateStatusBarItemVisable(selectTextLength);
});
// 用于判断是否展示右键菜单 // 用于判断是否展示右键菜单
vscode.window.onDidChangeTextEditorSelection(event => { vscode.window.onDidChangeTextEditorSelection(event => {
const text = event.textEditor.document.getText(event.selections[0]); const text = event.textEditor.document.getText(event.selections[0]);
// console.log('text.length', text.length); // console.log('text.length', text.length);
vscode.commands.executeCommand('setContext', '_textSelectionLength', text.length); vscode.commands.executeCommand('setContext', '_textSelectionLength', text.length);
selectTextLength = text.length;
updateStatusBarItemVisable(selectTextLength);
}); });
// 初始(VSCode 插件初始化)时也判断一次 (考虑上次关闭 VSCode 有选区,重新打开后 VSCode 回复选区但用户未重新切换选区的场景) // 初始(VSCode 插件初始化)时也判断一次 (考虑上次关闭 VSCode 有选区,重新打开后 VSCode 回复选区但用户未重新切换选区的场景)
@ -37,6 +47,9 @@ export function activate(context: vscode.ExtensionContext) {
// 获取选中的文本 // 获取选中的文本
let text = document.getText(selection); let text = document.getText(selection);
vscode.commands.executeCommand('setContext', '_textSelectionLength', text.length); vscode.commands.executeCommand('setContext', '_textSelectionLength', text.length);
selectTextLength = text.length;
updateStatusBarItemVisable(selectTextLength);
} else { } else {
// vscode.window.showInformationMessage('editor is undefined'); // vscode.window.showInformationMessage('editor is undefined');
console.log('editor is undefined'); console.log('editor is undefined');