Skip to content

Commit

Permalink
Adding to DotJoshJohnson#6 - user setting to persist the last query
Browse files Browse the repository at this point in the history
  • Loading branch information
rdoubleui committed Dec 21, 2015
1 parent f3ea33a commit b668ab4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/features/xmlXPathEngine.ts
Original file line number Diff line number Diff line change
@@ -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<boolean>('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;
Expand All @@ -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}`);
});
Expand Down

4 comments on commit b668ab4

@rdoubleui
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads an user setting xmlTools.PersistXPathQuery to determine whether to save the XPath query. However, the setting needs to be set by the user explicitely, they suggest using the ExtensionContext instead. Any thought on which way to approach?

@rdoubleui
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to DotJoshJohnson#4

@DotJoshJohnson
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the workspace.getConfiguration() API as you did here to get the setting should be just fine. We will, however, need to define the setting in the contributes property of package.json. This will add the setting upon installation of the extension (along with a default value), which eliminates the need for users to manually specify the setting in their override file. For example:

// ...
"contributes": {
    "configuration": {
        "type": "object",
        "title": "XML Tools Configuration",
        "properties": {
            "xmlTools.persistXPathQuery": {
                "type": "boolean",
                "default": true,
                "description": "Remember the last XPath query used."
            }
        }
    }
}

@rdoubleui
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the link, fixed this one as well.

Please sign in to comment.