Add NativeCommands Service

This commit is contained in:
Josh Johnson 2018-05-03 22:47:41 -04:00
parent a4366a5061
commit b9d6659a26
7 changed files with 31 additions and 22 deletions

View File

@ -1,3 +1,4 @@
export * from "./configuration";
export * from "./create-document-selector";
export * from "./extension-state";
export * from "./native-commands";

View File

@ -0,0 +1,18 @@
import { commands } from "vscode";
export class NativeCommands {
static async cursorMove(to: string, by: string): Promise<void> {
await commands.executeCommand("cursorMove", {
to: to,
by: by
});
}
static openGlobalSettings(): void {
commands.executeCommand("workbench.action.openGlobalSettings");
}
static setContext(key: string, value: any): void {
commands.executeCommand("setContext", key, value);
}
}

View File

@ -1,5 +1,3 @@
export const extensionPrefix = "xmlTools";
export namespace commands {
export const evaluateXPath = "xmlTools.evaluateXPath";
export const executeXQuery = "xmlTools.executeXQuery";
@ -22,10 +20,7 @@ export namespace languageIds {
}
export namespace nativeCommands {
export const cursorMove = "cursorMove";
export const openGlobalSettings = "workbench.action.openGlobalSettings";
export const revealLine = "revealLine";
export const setContext = "setContext";
}
export namespace stateKeys {

View File

@ -1,6 +1,7 @@
import { commands, workspace } from "vscode";
import { workspace } from "vscode";
import { ProviderResult, Range, TextEdit, TextEditor, TextEditorEdit } from "vscode";
import { NativeCommands } from "../../common";
import * as constants from "../../constants";
import { XmlFormatterFactory } from "../xml-formatter";
@ -38,14 +39,8 @@ export function formatAsXml(editor: TextEditor, edit: TextEditorEdit): void {
editBuilder.replace(textEdit.range, textEdit.newText);
// wiggle the cursor to deselect the formatted XML (is there a non-hacky way to go about this?)
await commands.executeCommand(constants.nativeCommands.cursorMove, {
to: "left",
by: "character"
});
await commands.executeCommand(constants.nativeCommands.cursorMove, {
to: "right",
by: "character"
});
await NativeCommands.cursorMove("left", "character");
await NativeCommands.cursorMove("right", "character");
});
}
}

View File

@ -1,4 +1,4 @@
import { commands, workspace } from "vscode";
import { workspace } from "vscode";
import { ProviderResult, Range, TextEdit, TextEditor, TextEditorEdit } from "vscode";
import * as constants from "../../constants";

View File

@ -1,4 +1,4 @@
import { commands, window, workspace } from "vscode";
import { window, workspace } from "vscode";
import {
Event, EventEmitter, ExtensionContext, Position, TextEditor, TreeDataProvider,
TreeItem, TreeItemCollapsibleState
@ -7,7 +7,7 @@ import {
import * as path from "path";
import { DOMParser } from "xmldom";
import { Configuration } from "../common";
import { Configuration, NativeCommands } from "../common";
import * as constants from "../constants";
export class XmlTreeDataProvider implements TreeDataProvider<any> {
@ -199,7 +199,7 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
private _refreshTree(): void {
if (!this.activeEditor || this.activeEditor.document.languageId !== constants.languageIds.xml) {
commands.executeCommand(constants.nativeCommands.setContext, constants.contextKeys.xmlTreeViewEnabled, false);
NativeCommands.setContext(constants.contextKeys.xmlTreeViewEnabled, false);
this._xmlDocument = null;
this._onDidChangeTreeData.fire();
@ -208,7 +208,7 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
const enableTreeView = Configuration.enableXmlTreeView;
commands.executeCommand(constants.nativeCommands.setContext, constants.contextKeys.xmlTreeViewEnabled, enableTreeView);
NativeCommands.setContext(constants.contextKeys.xmlTreeViewEnabled, enableTreeView);
const xml = this.activeEditor.document.getText();

View File

@ -1,10 +1,10 @@
import { commands, window, workspace } from "vscode";
import { window, workspace } from "vscode";
import { Disposable, Range, TextEditor, TextEditorEdit, Uri } from "vscode";
import * as constants from "../../constants";
import { ChildProcess } from "../child-process";
import { Configuration } from "../../common";
import { Configuration, NativeCommands } from "../../common";
export async function executeXQuery(editor: TextEditor, edit: TextEditorEdit): Promise<void> {
// this disposable will be used for creating status bar messages
@ -22,7 +22,7 @@ export async function executeXQuery(editor: TextEditor, edit: TextEditorEdit): P
const action = await window.showWarningMessage("An XQuery execution engine has not been defined.", "Define Now");
if (action === "Define Now") {
commands.executeCommand(constants.nativeCommands.openGlobalSettings);
NativeCommands.openGlobalSettings();
}
return;