Allows to update indicator status by clicking.

This commit is contained in:
CismonX 2021-03-12 17:46:43 +08:00
parent 658b44fe50
commit 7b6bb43836
Signed by: cismonx
GPG Key ID: 3094873E29A482FB
3 changed files with 19 additions and 4 deletions

View File

@ -88,6 +88,10 @@
{ {
"command": "texinfo.preview.goto", "command": "texinfo.preview.goto",
"title": "Goto node in preview" "title": "Goto node in preview"
},
{
"command": "texinfo.indicator.click",
"title": "Refresh indicator status"
} }
], ],
"menus": { "menus": {
@ -101,6 +105,11 @@
"command": "texinfo.preview.goto", "command": "texinfo.preview.goto",
"when": "false", "when": "false",
"group": "navigation" "group": "navigation"
},
{
"command": "texinfo.indicator.click",
"when": "false",
"group": "navigation"
} }
], ],
"editor/title": [ "editor/title": [

View File

@ -27,6 +27,7 @@ export function activate(context: vscode.ExtensionContext) {
vscode.workspace.onDidChangeConfiguration(Options.clear), vscode.workspace.onDidChangeConfiguration(Options.clear),
vscode.commands.registerTextEditorCommand('texinfo.preview.show', PreviewContext.showPreview), vscode.commands.registerTextEditorCommand('texinfo.preview.show', PreviewContext.showPreview),
vscode.commands.registerCommand('texinfo.preview.goto', PreviewContext.gotoPreview), vscode.commands.registerCommand('texinfo.preview.goto', PreviewContext.gotoPreview),
vscode.commands.registerCommand('texinfo.indicator.click', Indicator.click),
vscode.languages.registerCodeLensProvider('texinfo', new CodeLensProvider()), vscode.languages.registerCodeLensProvider('texinfo', new CodeLensProvider()),
vscode.languages.registerCompletionItemProvider('texinfo', new CompletionItemProvider(), '@'), vscode.languages.registerCompletionItemProvider('texinfo', new CompletionItemProvider(), '@'),
vscode.languages.registerDocumentSymbolProvider('texinfo', new DocumentSymbolProvider()), vscode.languages.registerDocumentSymbolProvider('texinfo', new DocumentSymbolProvider()),

View File

@ -15,6 +15,11 @@ export default class Indicator implements vscode.Disposable {
private statusBarItem: vscode.StatusBarItem; private statusBarItem: vscode.StatusBarItem;
static async click() {
await Indicator.instance.updateStatus();
Indicator.instance.refresh(vscode.window.activeTextEditor);
}
private refresh(editor?: vscode.TextEditor) { private refresh(editor?: vscode.TextEditor) {
if (editor === undefined || editor.document.languageId != 'texinfo') { if (editor === undefined || editor.document.languageId != 'texinfo') {
this.statusBarItem.hide(); this.statusBarItem.hide();
@ -23,7 +28,7 @@ export default class Indicator implements vscode.Disposable {
} }
} }
public async updateStatus() { async updateStatus() {
const output = await exec(Options.makeinfo, ['--version'], Options.maxSize); const output = await exec(Options.makeinfo, ['--version'], Options.maxSize);
const result = output.data?.match(/\(GNU texinfo\) (.*)\n/); const result = output.data?.match(/\(GNU texinfo\) (.*)\n/);
let tooltip = '', icon: string, version = ''; let tooltip = '', icon: string, version = '';
@ -31,8 +36,7 @@ export default class Indicator implements vscode.Disposable {
version = result[1]; version = result[1];
if (!isNaN(+version) && +version < 6.7) { if (!isNaN(+version) && +version < 6.7) {
icon = '$(warning)'; icon = '$(warning)';
tooltip = `GNU Texinfo (${Options.makeinfo}) is outdated.\n` + tooltip = `GNU Texinfo (${Options.makeinfo}) is outdated (${version} < 6.7).`;
'Please upgrade to the latest version (6.7).';
} else { } else {
icon = '$(check)'; icon = '$(check)';
} }
@ -42,9 +46,10 @@ export default class Indicator implements vscode.Disposable {
} }
this.statusBarItem.text = `${icon} GNU Texinfo ${version}`; this.statusBarItem.text = `${icon} GNU Texinfo ${version}`;
this.statusBarItem.tooltip = tooltip; this.statusBarItem.tooltip = tooltip;
this.statusBarItem.command = 'texinfo.indicator.click';
} }
public static onTextEditorChange(editor?: vscode.TextEditor) { static onTextEditorChange(editor?: vscode.TextEditor) {
Indicator.instance.refresh(editor); Indicator.instance.refresh(editor);
} }