From 0f0d2cc226f952581f7ca5e608b8352cc8f6cc2f Mon Sep 17 00:00:00 2001 From: Philipp Arndt <2f.mail@gmx.de> Date: Wed, 30 Jan 2019 17:45:18 +0100 Subject: [PATCH 1/2] Ability to toggle the table mode using the status item --- src/context.ts | 9 +++++++++ src/extension.ts | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/context.ts b/src/context.ts index 1b6376c..519c55a 100644 --- a/src/context.ts +++ b/src/context.ts @@ -33,6 +33,15 @@ export function exitContext(editor: vscode.TextEditor, type: ContextType) { } } +export function toggleContext(editor: vscode.TextEditor, type: ContextType) { + const editorState = state.get(editor.document.fileName) || []; + if (editorState.indexOf(ContextType.TableMode) >= 0) { + exitContext(editor, type); + } else { + enterContext(editor, type); + } +} + export function restoreContext(editor: vscode.TextEditor) { let toEnter: ContextType[] = []; // @ts-ignore diff --git a/src/extension.ts b/src/extension.ts index fd718cd..16a1512 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -7,7 +7,7 @@ import { OrgLocator, OrgParser, OrgStringifier } from './ttOrg'; import { Locator, Parser, Stringifier, Table } from './ttTable'; import { MarkdownLocator, MarkdownParser, MarkdownStringifier } from './ttMarkdown'; import { isUndefined } from 'util'; -import { registerContext, ContextType, enterContext, exitContext, restoreContext } from './context'; +import { registerContext, ContextType, enterContext, exitContext, restoreContext, toggleContext } from './context'; import * as cfg from './configuration'; let locator: Locator; @@ -34,6 +34,7 @@ export function activate(ctx: vscode.ExtensionContext) { const statusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); registerContext(ContextType.TableMode, '$(book) Table Mode', statusItem); + statusItem.command = 'text-tables.tableModeToggle'; if (configuration.showStatus) { statusItem.show(); @@ -63,7 +64,9 @@ export function activate(ctx: vscode.ExtensionContext) { (e) => enterContext(e, ContextType.TableMode))); ctx.subscriptions.push(vscode.commands.registerTextEditorCommand('text-tables.tableModeOff', (e) => exitContext(e, ContextType.TableMode))); - + ctx.subscriptions.push(vscode.commands.registerTextEditorCommand('text-tables.tableModeToggle', + (e) => toggleContext(e, ContextType.TableMode))); + ctx.subscriptions.push(registerTableCommand('text-tables.moveRowDown', cmd.moveRowDown, {format: true})); ctx.subscriptions.push(registerTableCommand('text-tables.moveRowUp', cmd.moveRowUp, {format: true})); ctx.subscriptions.push(registerTableCommand('text-tables.moveColRight', async (editor, range, table) => { From a2e8fd8009d9f2c74d5c899a12e9c76640e6a2c4 Mon Sep 17 00:00:00 2001 From: Philipp Arndt <2f.mail@gmx.de> Date: Wed, 30 Jan 2019 20:34:38 +0100 Subject: [PATCH 2/2] Improved status item text and icon --- src/context.ts | 4 ++-- src/extension.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/context.ts b/src/context.ts index 519c55a..a022081 100644 --- a/src/context.ts +++ b/src/context.ts @@ -64,8 +64,8 @@ class Context { setState(isEnabled: boolean) { vscode.commands.executeCommand('setContext', this.type, isEnabled); if (this.statusItem) { - const stateText = isEnabled ? 'On' : 'Off'; - this.statusItem.text = `${this.title}: ${stateText}`; + const stateText = isEnabled ? '$(check)' : '$(x)'; + this.statusItem.text = `${this.title} ${stateText}`; } } } diff --git a/src/extension.ts b/src/extension.ts index 16a1512..f57fbaf 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -33,7 +33,7 @@ export function activate(ctx: vscode.ExtensionContext) { loadConfiguration(); const statusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); - registerContext(ContextType.TableMode, '$(book) Table Mode', statusItem); + registerContext(ContextType.TableMode, 'Table', statusItem); statusItem.command = 'text-tables.tableModeToggle'; if (configuration.showStatus) {