Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default XPath Input to Last Query #4 #6

Merged
merged 3 commits into from
Jan 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 11 additions & 6 deletions src/features/xmlXPathEngine.ts
Original file line number Diff line number Diff line change
@@ -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<boolean>('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;
Expand All @@ -26,16 +31,16 @@ 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;
}

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}`);
});
Expand Down