Clean up for feature #6
This commit is contained in:
		
							parent
							
								
									b668ab49c3
								
							
						
					
					
						commit
						955c971856
					
				
					 2 changed files with 17 additions and 22 deletions
				
			
		
							
								
								
									
										11
									
								
								package.json
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								package.json
									
										
									
									
									
								
							| 
						 | 
					@ -44,6 +44,17 @@
 | 
				
			||||||
				"title": "XML Tools: Evaluate XPath"
 | 
									"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": [
 | 
							"keybindings": [
 | 
				
			||||||
			{
 | 
								{
 | 
				
			||||||
				"key": "ctrl+shift+alt+b",
 | 
									"key": "ctrl+shift+alt+b",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,13 +6,15 @@ let xpath = require('xpath');
 | 
				
			||||||
let dom = require('xmldom').DOMParser;
 | 
					let dom = require('xmldom').DOMParser;
 | 
				
			||||||
let resultChannel: OutputChannel = null;
 | 
					let resultChannel: OutputChannel = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export var lastXPath: string;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void {
 | 
					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({
 | 
					    window.showInputBox({
 | 
				
			||||||
		placeHolder: 'XPath Query',
 | 
							placeHolder: 'XPath Query',
 | 
				
			||||||
		prompt: 'Please enter an XPath query to evaluate.',
 | 
							prompt: 'Please enter an XPath query to evaluate.',
 | 
				
			||||||
		value: isPersistant ? Singleton.getXPathValue() : ''
 | 
							value: isPersistant ? lastXPath : ''
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
	}).then((query) => {
 | 
						}).then((query) => {
 | 
				
			||||||
		if (query === undefined) return;
 | 
							if (query === undefined) return;
 | 
				
			||||||
| 
						 | 
					@ -20,8 +22,6 @@ export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void {
 | 
				
			||||||
		let xml = editor.document.getText();
 | 
							let xml = editor.document.getText();
 | 
				
			||||||
		let doc = new dom().parseFromString(xml);
 | 
							let doc = new dom().parseFromString(xml);
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		Singleton.setXPathValue(query);
 | 
					 | 
				
			||||||
		
 | 
					 | 
				
			||||||
		try {
 | 
							try {
 | 
				
			||||||
			var nodes = xpath.select(query, doc);
 | 
								var nodes = xpath.select(query, doc);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
| 
						 | 
					@ -31,6 +31,8 @@ export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void {
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
 | 
							lastXPath = query;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
		if (nodes === null || nodes === undefined || nodes.length == 0) {
 | 
							if (nodes === null || nodes === undefined || nodes.length == 0) {
 | 
				
			||||||
			window.showInformationMessage('Your XPath query returned no results.');
 | 
								window.showInformationMessage('Your XPath query returned no results.');
 | 
				
			||||||
			return;
 | 
								return;
 | 
				
			||||||
| 
						 | 
					@ -45,22 +47,4 @@ export function evaluateXPath(editor: TextEditor, edit: TextEditorEdit): void {
 | 
				
			||||||
		
 | 
							
 | 
				
			||||||
		resultChannel.show(ViewColumn.Three);
 | 
							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
		
		Reference in a new issue