Clean up for feature #6
This commit is contained in:
parent
b668ab49c3
commit
955c971856
2 changed files with 17 additions and 22 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue