Merge pull request #6 from rdoubleui/persist_last_query

Default XPath Input to Last Query #4
This commit is contained in:
Josh Johnson 2016-01-04 20:41:09 -05:00
commit ae5b9f1e36
2 changed files with 22 additions and 6 deletions

View File

@ -44,6 +44,17 @@
"title": "XML Tools: Evaluate XPath" "title": "XML Tools: Evaluate XPath"
} }
], ],
"configuration": {
"title": "XML Tools Configuration",
"type": "object",
"properties": {
"xmlTools.persistXPathQuery": {
"type": "boolean",
"default": true,
"description": "Remember the last XPath query used."
}
}
},
"keybindings": [ "keybindings": [
{ {
"key": "ctrl+shift+alt+b", "key": "ctrl+shift+alt+b",

View File

@ -1,15 +1,20 @@
'use strict'; 'use strict';
import { window, TextEditor, TextEditorEdit, OutputChannel, ViewColumn } from 'vscode'; import { window, TextEditor, TextEditorEdit, OutputChannel, ViewColumn, workspace } from 'vscode';
let xpath = require('xpath'); let xpath = require('xpath');
let dom = require('xmldom').DOMParser; let dom = require('xmldom').DOMParser;
let resultChannel: OutputChannel = null; let resultChannel: OutputChannel = null;
export var lastXPath: string;
export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void { export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void {
window.showInputBox({ let isPersistant = workspace.getConfiguration().has('xmlTools.persistXPathQuery') && workspace.getConfiguration('xmlTools').get<boolean>('persistXPathQuery') === true
window.showInputBox({
placeHolder: 'XPath Query', placeHolder: 'XPath Query',
prompt: 'Please enter an XPath query to evaluate.' prompt: 'Please enter an XPath query to evaluate.',
value: isPersistant ? lastXPath : ''
}).then((query) => { }).then((query) => {
if (query === undefined) return; if (query === undefined) return;
@ -26,6 +31,8 @@ export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void {
return; return;
} }
lastXPath = query;
if (nodes === null || nodes === undefined || nodes.length == 0) { if (nodes === null || nodes === undefined || nodes.length == 0) {
window.showInformationMessage('Your XPath query returned no results.'); window.showInformationMessage('Your XPath query returned no results.');
return; return;
@ -34,8 +41,6 @@ export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void {
if (resultChannel === null) resultChannel = window.createOutputChannel('XPath Evaluation Results'); if (resultChannel === null) resultChannel = window.createOutputChannel('XPath Evaluation Results');
resultChannel.clear(); resultChannel.clear();
resultChannel.appendLine('Last query: ' + query + '\n');
nodes.forEach((node) => { nodes.forEach((node) => {
resultChannel.appendLine(`${node.localName}: ${node.firstChild.data}`); resultChannel.appendLine(`${node.localName}: ${node.firstChild.data}`);
}); });