Clean up for feature #6

This commit is contained in:
Rajko Winkler 2016-01-04 17:07:36 +01:00
parent b668ab49c3
commit 955c971856
2 changed files with 17 additions and 22 deletions

View File

@ -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",

View File

@ -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<boolean>('PersistXPathQuery') === true
let isPersistant = workspace.getConfiguration().has('xmlTools.persistXPathQuery') && workspace.getConfiguration('xmlTools').get<boolean>('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;
}
}