From f3ea33a522b45a73219ea01561510fef52a66c20 Mon Sep 17 00:00:00 2001 From: Rajko Winkler Date: Wed, 16 Dec 2015 15:54:48 +0100 Subject: [PATCH 1/3] The last XPath query is being persisted and can be reused with the next query. --- src/features/xmlXPathEngine.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/features/xmlXPathEngine.ts b/src/features/xmlXPathEngine.ts index 237ac5f..edaea0a 100644 --- a/src/features/xmlXPathEngine.ts +++ b/src/features/xmlXPathEngine.ts @@ -9,7 +9,8 @@ let resultChannel: OutputChannel = null; export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void { window.showInputBox({ placeHolder: 'XPath Query', - prompt: 'Please enter an XPath query to evaluate.' + prompt: 'Please enter an XPath query to evaluate.', + value: Singleton.getXPathValue() }).then((query) => { if (query === undefined) return; @@ -17,6 +18,8 @@ export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void { let xml = editor.document.getText(); let doc = new dom().parseFromString(xml); + Singleton.setXPathValue(query); + try { var nodes = xpath.select(query, doc); } @@ -42,4 +45,22 @@ export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void { resultChannel.show(ViewColumn.Three); }); +} + +namespace Singleton { + + class XPathContext + { + static _lastXPathValue:string = ''; + } + + export function getXPathValue():string + { + return XPathContext._lastXPathValue; + } + + export function setXPathValue(val:string):void + { + XPathContext._lastXPathValue = val; + } } \ No newline at end of file From b668ab49c3daa3ccbcab1124bffa449091343bc6 Mon Sep 17 00:00:00 2001 From: Rajko Winkler Date: Mon, 21 Dec 2015 14:40:43 +0100 Subject: [PATCH 2/3] Adding to #6 - user setting to persist the last query --- src/features/xmlXPathEngine.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/features/xmlXPathEngine.ts b/src/features/xmlXPathEngine.ts index edaea0a..16282e9 100644 --- a/src/features/xmlXPathEngine.ts +++ b/src/features/xmlXPathEngine.ts @@ -1,16 +1,18 @@ 'use strict'; -import { window, TextEditor, TextEditorEdit, OutputChannel, ViewColumn } from 'vscode'; +import { window, TextEditor, TextEditorEdit, OutputChannel, ViewColumn, workspace } from 'vscode'; let xpath = require('xpath'); let dom = require('xmldom').DOMParser; let resultChannel: OutputChannel = null; export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void { - window.showInputBox({ + let isPersistant = workspace.getConfiguration().has('xmlTools.PersistXPathQuery') && workspace.getConfiguration('xmlTools').get('PersistXPathQuery') === true + + window.showInputBox({ placeHolder: 'XPath Query', prompt: 'Please enter an XPath query to evaluate.', - value: Singleton.getXPathValue() + value: isPersistant ? Singleton.getXPathValue() : '' }).then((query) => { if (query === undefined) return; @@ -36,9 +38,7 @@ export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void { if (resultChannel === null) resultChannel = window.createOutputChannel('XPath Evaluation Results'); resultChannel.clear(); - - resultChannel.appendLine('Last query: ' + query + '\n'); - + nodes.forEach((node) => { resultChannel.appendLine(`${node.localName}: ${node.firstChild.data}`); }); From 955c9718566f5e1eadb96a27419cb5aba90da460 Mon Sep 17 00:00:00 2001 From: Rajko Winkler Date: Mon, 4 Jan 2016 17:07:36 +0100 Subject: [PATCH 3/3] Clean up for feature #6 --- package.json | 11 +++++++++++ src/features/xmlXPathEngine.ts | 28 ++++++---------------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 2363664..100a3c0 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,17 @@ "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": [ { "key": "ctrl+shift+alt+b", diff --git a/src/features/xmlXPathEngine.ts b/src/features/xmlXPathEngine.ts index 16282e9..a5acdd9 100644 --- a/src/features/xmlXPathEngine.ts +++ b/src/features/xmlXPathEngine.ts @@ -6,13 +6,15 @@ let xpath = require('xpath'); let dom = require('xmldom').DOMParser; let resultChannel: OutputChannel = null; +export var lastXPath: string; + export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void { - let isPersistant = workspace.getConfiguration().has('xmlTools.PersistXPathQuery') && workspace.getConfiguration('xmlTools').get('PersistXPathQuery') === true + let isPersistant = workspace.getConfiguration().has('xmlTools.persistXPathQuery') && workspace.getConfiguration('xmlTools').get('persistXPathQuery') === true window.showInputBox({ placeHolder: 'XPath Query', prompt: 'Please enter an XPath query to evaluate.', - value: isPersistant ? Singleton.getXPathValue() : '' + value: isPersistant ? lastXPath : '' }).then((query) => { if (query === undefined) return; @@ -20,8 +22,6 @@ export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void { let xml = editor.document.getText(); let doc = new dom().parseFromString(xml); - Singleton.setXPathValue(query); - try { var nodes = xpath.select(query, doc); } @@ -31,6 +31,8 @@ export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void { return; } + lastXPath = query; + if (nodes === null || nodes === undefined || nodes.length == 0) { window.showInformationMessage('Your XPath query returned no results.'); return; @@ -45,22 +47,4 @@ export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void { resultChannel.show(ViewColumn.Three); }); -} - -namespace Singleton { - - class XPathContext - { - static _lastXPathValue:string = ''; - } - - export function getXPathValue():string - { - return XPathContext._lastXPathValue; - } - - export function setXPathValue(val:string):void - { - XPathContext._lastXPathValue = val; - } } \ No newline at end of file