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 237ac5f..a5acdd9 100644 --- a/src/features/xmlXPathEngine.ts +++ b/src/features/xmlXPathEngine.ts @@ -1,15 +1,20 @@ '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 var lastXPath: string; + 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.' + prompt: 'Please enter an XPath query to evaluate.', + value: isPersistant ? lastXPath : '' }).then((query) => { if (query === undefined) return; @@ -26,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; @@ -33,9 +40,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}`); });