Add NativeCommands Service
This commit is contained in:
parent
a4366a5061
commit
b9d6659a26
@ -1,3 +1,4 @@
|
|||||||
export * from "./configuration";
|
export * from "./configuration";
|
||||||
export * from "./create-document-selector";
|
export * from "./create-document-selector";
|
||||||
export * from "./extension-state";
|
export * from "./extension-state";
|
||||||
|
export * from "./native-commands";
|
||||||
|
18
src/common/native-commands.ts
Normal file
18
src/common/native-commands.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,3 @@
|
|||||||
export const extensionPrefix = "xmlTools";
|
|
||||||
|
|
||||||
export namespace commands {
|
export namespace commands {
|
||||||
export const evaluateXPath = "xmlTools.evaluateXPath";
|
export const evaluateXPath = "xmlTools.evaluateXPath";
|
||||||
export const executeXQuery = "xmlTools.executeXQuery";
|
export const executeXQuery = "xmlTools.executeXQuery";
|
||||||
@ -22,10 +20,7 @@ export namespace languageIds {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export namespace nativeCommands {
|
export namespace nativeCommands {
|
||||||
export const cursorMove = "cursorMove";
|
|
||||||
export const openGlobalSettings = "workbench.action.openGlobalSettings";
|
|
||||||
export const revealLine = "revealLine";
|
export const revealLine = "revealLine";
|
||||||
export const setContext = "setContext";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace stateKeys {
|
export namespace stateKeys {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { commands, workspace } from "vscode";
|
import { workspace } from "vscode";
|
||||||
import { ProviderResult, Range, TextEdit, TextEditor, TextEditorEdit } from "vscode";
|
import { ProviderResult, Range, TextEdit, TextEditor, TextEditorEdit } from "vscode";
|
||||||
|
|
||||||
|
import { NativeCommands } from "../../common";
|
||||||
import * as constants from "../../constants";
|
import * as constants from "../../constants";
|
||||||
|
|
||||||
import { XmlFormatterFactory } from "../xml-formatter";
|
import { XmlFormatterFactory } from "../xml-formatter";
|
||||||
@ -38,14 +39,8 @@ export function formatAsXml(editor: TextEditor, edit: TextEditorEdit): void {
|
|||||||
editBuilder.replace(textEdit.range, textEdit.newText);
|
editBuilder.replace(textEdit.range, textEdit.newText);
|
||||||
|
|
||||||
// wiggle the cursor to deselect the formatted XML (is there a non-hacky way to go about this?)
|
// wiggle the cursor to deselect the formatted XML (is there a non-hacky way to go about this?)
|
||||||
await commands.executeCommand(constants.nativeCommands.cursorMove, {
|
await NativeCommands.cursorMove("left", "character");
|
||||||
to: "left",
|
await NativeCommands.cursorMove("right", "character");
|
||||||
by: "character"
|
|
||||||
});
|
|
||||||
await commands.executeCommand(constants.nativeCommands.cursorMove, {
|
|
||||||
to: "right",
|
|
||||||
by: "character"
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { commands, workspace } from "vscode";
|
import { workspace } from "vscode";
|
||||||
import { ProviderResult, Range, TextEdit, TextEditor, TextEditorEdit } from "vscode";
|
import { ProviderResult, Range, TextEdit, TextEditor, TextEditorEdit } from "vscode";
|
||||||
|
|
||||||
import * as constants from "../../constants";
|
import * as constants from "../../constants";
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { commands, window, workspace } from "vscode";
|
import { window, workspace } from "vscode";
|
||||||
import {
|
import {
|
||||||
Event, EventEmitter, ExtensionContext, Position, TextEditor, TreeDataProvider,
|
Event, EventEmitter, ExtensionContext, Position, TextEditor, TreeDataProvider,
|
||||||
TreeItem, TreeItemCollapsibleState
|
TreeItem, TreeItemCollapsibleState
|
||||||
@ -7,7 +7,7 @@ import {
|
|||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { DOMParser } from "xmldom";
|
import { DOMParser } from "xmldom";
|
||||||
|
|
||||||
import { Configuration } from "../common";
|
import { Configuration, NativeCommands } from "../common";
|
||||||
import * as constants from "../constants";
|
import * as constants from "../constants";
|
||||||
|
|
||||||
export class XmlTreeDataProvider implements TreeDataProvider<any> {
|
export class XmlTreeDataProvider implements TreeDataProvider<any> {
|
||||||
@ -199,7 +199,7 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
|
|||||||
|
|
||||||
private _refreshTree(): void {
|
private _refreshTree(): void {
|
||||||
if (!this.activeEditor || this.activeEditor.document.languageId !== constants.languageIds.xml) {
|
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._xmlDocument = null;
|
||||||
this._onDidChangeTreeData.fire();
|
this._onDidChangeTreeData.fire();
|
||||||
@ -208,7 +208,7 @@ export class XmlTreeDataProvider implements TreeDataProvider<any> {
|
|||||||
|
|
||||||
const enableTreeView = Configuration.enableXmlTreeView;
|
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();
|
const xml = this.activeEditor.document.getText();
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { commands, window, workspace } from "vscode";
|
import { window, workspace } from "vscode";
|
||||||
import { Disposable, Range, TextEditor, TextEditorEdit, Uri } from "vscode";
|
import { Disposable, Range, TextEditor, TextEditorEdit, Uri } from "vscode";
|
||||||
|
|
||||||
import * as constants from "../../constants";
|
import * as constants from "../../constants";
|
||||||
|
|
||||||
import { ChildProcess } from "../child-process";
|
import { ChildProcess } from "../child-process";
|
||||||
import { Configuration } from "../../common";
|
import { Configuration, NativeCommands } from "../../common";
|
||||||
|
|
||||||
export async function executeXQuery(editor: TextEditor, edit: TextEditorEdit): Promise<void> {
|
export async function executeXQuery(editor: TextEditor, edit: TextEditorEdit): Promise<void> {
|
||||||
// this disposable will be used for creating status bar messages
|
// 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");
|
const action = await window.showWarningMessage("An XQuery execution engine has not been defined.", "Define Now");
|
||||||
|
|
||||||
if (action === "Define Now") {
|
if (action === "Define Now") {
|
||||||
commands.executeCommand(constants.nativeCommands.openGlobalSettings);
|
NativeCommands.openGlobalSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user