diff options
author | Curtis Windatt <cwindatt@ca.ibm.com> | 2015-12-15 17:36:01 -0500 |
---|---|---|
committer | Curtis Windatt <cwindatt@ca.ibm.com> | 2015-12-15 17:36:01 -0500 |
commit | dbb039658ace937dbbe699163efe395f235e098c (patch) | |
tree | 850f12bee447370d0f2acd3967a595e63ffa1eb4 | |
parent | 3cfb0c2d2eae3bd446c1d67fe3a035c340504049 (diff) | |
download | org.eclipse.orion.client-origin/stable_20151214.zip org.eclipse.orion.client-origin/stable_20151214.tar.gz org.eclipse.orion.client-origin/stable_20151214.tar.bz2 |
Bug 475852 - [Quickfix] Allow quick fixes to be applied to all matching problems in a fileorigin/stable_20151214
8 files changed, 112 insertions, 81 deletions
diff --git a/bundles/org.eclipse.orion.client.editor/web/orion/editor/tooltip.css b/bundles/org.eclipse.orion.client.editor/web/orion/editor/tooltip.css index 382b838..146a710 100644 --- a/bundles/org.eclipse.orion.client.editor/web/orion/editor/tooltip.css +++ b/bundles/org.eclipse.orion.client.editor/web/orion/editor/tooltip.css @@ -83,10 +83,15 @@ .textviewTooltip .commandButton:not(.dropdownTrigger){ /* In certain themes command buttons are set to all caps */ text-transform: initial; } - .textviewTooltip .commandList > li { margin: 0; } +/* Reuse font from command buttons but no border */ +.textviewTooltip .quickfixAllParameter { + vertical-align: middle; + font-weight: normal; + font-family: "HelveticaNeue", "Helvetica Neue", "HelveticaNeueRoman", "HelveticaNeue-Roman", "Helvetica Neue Roman", 'TeXGyreHerosRegular', "Helvetica", "Tahoma", "Geneva", "Arial", sans-serif; +} /* Styles for custom behaviour */ .textViewTooltipOnFocus { diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/nls/root/messages.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/nls/root/messages.js index de2ea26..8b75d0d 100644 --- a/bundles/org.eclipse.orion.client.javascript/web/javascript/nls/root/messages.js +++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/nls/root/messages.js @@ -88,7 +88,6 @@ define({//Default message bundle 'javascriptValidation': 'Javascript Validation', 'jsHover': 'JavaScript Hover Provider', 'removeExtraSemiFixName': 'Remove extra semicolon', - 'removeExtraSemiFixAllName': 'Remove all extra semicolons (${0} in file)', 'addFallthroughCommentFixName': 'Add $FALLTHROUGH$ comment', 'addEmptyCommentFixName': 'Comment empty block', 'addESLintEnvFixName': 'Add to eslint-env directive', @@ -96,7 +95,6 @@ define({//Default message bundle 'removeUnusedParamsFixName': 'Remove parameter', 'commentCallbackFixName': 'Add @callback to function', 'eqeqeqFixName': 'Update operator', - 'eqeqeqFixAllName': 'Update all operators (${0} in file)', 'unreachableFixName': 'Remove unreachable code', 'sparseArrayFixName': 'Convert to normal array', 'semiFixName': 'Add missing \';\'', diff --git a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js index bd9cac1..510713b 100644 --- a/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js +++ b/bundles/org.eclipse.orion.client.javascript/web/javascript/plugins/javascriptPlugin.js @@ -501,6 +501,7 @@ define([ quickFixComputer, { name: javascriptMessages["removeExtraSemiFixName"], + fixAllEnabled: true, scopeId: "orion.edit.quickfix", //$NON-NLS-1$ id : "rm.extra.semi.fix", //$NON-NLS-1$ contentType: ['application/javascript', 'text/html'], //$NON-NLS-1$ //$NON-NLS-2$ @@ -509,18 +510,6 @@ define([ ] } ); - provider.registerServiceProvider("orion.edit.command", //$NON-NLS-1$ - quickFixComputer, - { - name: javascriptMessages["removeExtraSemiFixAllName"], - scopeId: "orion.edit.quickfixAll", //$NON-NLS-1$ - id : "rm.extra.semi.fixAll", //$NON-NLS-1$ - contentType: ['application/javascript', 'text/html'], //$NON-NLS-1$ //$NON-NLS-2$ - validationProperties: [ - {source: "annotation:id", match: "^(?:no-extra-semi)$"} //$NON-NLS-1$ //$NON-NLS-2$ - ] - } - ); provider.registerServiceProvider("orion.edit.command", //$NON-NLS-1$ quickFixComputer, @@ -658,6 +647,7 @@ define([ quickFixComputer, { name: javascriptMessages["eqeqeqFixName"], + fixAllEnabled: true, scopeId: "orion.edit.quickfix", //$NON-NLS-1$ id : "eqeqeq.fix", //$NON-NLS-1$ contentType: ['application/javascript', 'text/html'], //$NON-NLS-1$ //$NON-NLS-2$ @@ -666,19 +656,6 @@ define([ ] } ); - provider.registerServiceProvider("orion.edit.command", //$NON-NLS-1$ - quickFixComputer, - { - name: javascriptMessages["eqeqeqFixAllName"], - scopeId: "orion.edit.quickfixAll", //$NON-NLS-1$ - id : "eqeqeq.fixAll", //$NON-NLS-1$ - contentType: ['application/javascript', 'text/html'], //$NON-NLS-1$ //$NON-NLS-2$ - validationProperties: [ - {source: "annotation:id", match: "^(?:eqeqeq)$"} //$NON-NLS-1$ //$NON-NLS-2$ - ] - } - ); - provider.registerServiceProvider("orion.edit.command", //$NON-NLS-1$ quickFixComputer, diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/commandRegistry.js b/bundles/org.eclipse.orion.client.ui/web/orion/commandRegistry.js index ab972c8..14b1073 100644 --- a/bundles/org.eclipse.orion.client.ui/web/orion/commandRegistry.js +++ b/bundles/org.eclipse.orion.client.ui/web/orion/commandRegistry.js @@ -1230,13 +1230,7 @@ define([ id = renderType + command.id + index; // using the index ensures unique ids within the DOM when a command repeats for each item var commandDiv = document.createElement("div"); //$NON-NLS-0$ parent.appendChild(commandDiv); - element = Commands.createCommandItem(commandDiv, command, invocation, id, null, renderType === "button", onClick); - } else if (renderType === "quickfixAll") { - id = renderType + command.id + index + 'All'; // using the index ensures unique ids within the DOM when a command repeats for each item - commandDiv = document.createElement("div"); //$NON-NLS-0$ - parent.appendChild(commandDiv); - command.name = i18nUtil.formatMessage(command.name, userData.annotations.length); - element = Commands.createCommandItem(commandDiv, command, invocation, id, null, renderType === "button", onClick); + element = Commands.createQuickfixItem(commandDiv, command, invocation, onClick); } else { id = renderType + command.id + index; // // using the index ensures unique ids within the DOM when a command repeats for each item element = Commands.createCommandItem(parent, command, invocation, id, null, renderType === "tool", onClick); diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/commands.js b/bundles/org.eclipse.orion.client.ui/web/orion/commands.js index 9275bb0..f82d99a 100644 --- a/bundles/org.eclipse.orion.client.ui/web/orion/commands.js +++ b/bundles/org.eclipse.orion.client.ui/web/orion/commands.js @@ -225,6 +225,79 @@ define([ return checkbox; } + function createQuickfixItem(parent, command, commandInvocation, callback) { + var element; + var button; + var clickTarget; + var fixAllCheckbox; + var fixAllLabel; + + element = document.createElement("div"); //$NON-NLS-1$ + + button = clickTarget = document.createElement("button"); //$NON-NLS-1$ + button.className = "orionButton"; //$NON-NLS-1$ + if (command.extraClass) { + button.classList.add(command.extraClass); + } + button.classList.add("commandButton"); //$NON-NLS-1$ + var text = document.createTextNode(command.name); + button.appendChild(text); + + var onClick = callback || command.callback; + if (onClick) { + var done = function() { + if (fixAllCheckbox && fixAllCheckbox.checked){ + commandInvocation.userData.doFixAll = true; + } + onClick.call(commandInvocation.handler, commandInvocation); + }; + command.onClick = onClick; + clickTarget.addEventListener("click", function(e) { + var onClickThen; + onClickThen = function (doIt) { if(doIt) { + done(); + } + }; + if(command.preCallback) { + command.preCallback(commandInvocation).then( function(doIt) { + onClickThen(doIt); + }); + } else { + onClickThen(true); + } + e.stopPropagation(); + }, false); + } + if (parent.nodeName.toLowerCase() === "ul") { + var li = document.createElement("li"); //$NON-NLS-0$ + parent.appendChild(li); + parent = li; + } else { + button.classList.add("commandMargins"); //$NON-NLS-0$ + } + element.appendChild(button); + + // TODO We check that the internal access to annotation model exists so if it breaks we don't show the checkbox at all + if (command.fixAllEnabled && commandInvocation.userData._annotationModel){ + var id = command.name + 'fixAll'; //$NON-NLS-1$ + fixAllCheckbox = document.createElement('input'); //$NON-NLS-1$ + fixAllCheckbox.type = 'checkbox'; //$NON-NLS-1$ + fixAllCheckbox.className = "quickfixAllParameter"; //$NON-NLS-1$ + fixAllCheckbox.id = id; + + fixAllLabel = document.createElement('label'); //$NON-NLS-1$ + fixAllLabel.htmlFor = id; + fixAllLabel.className = "quickfixAllParameter"; //$NON-NLS-1$ + fixAllLabel.appendChild(document.createTextNode('Fix all in file')); // TODO NLS this string + + element.appendChild(fixAllCheckbox); + element.appendChild(fixAllLabel); + } + + parent.appendChild(element); + return element; + } + function createCommandItem(parent, command, commandInvocation, id, keyBinding, useImage, callback) { var element; var clickTarget; @@ -453,7 +526,6 @@ define([ return element; } - /** * CommandInvocation is a data structure that carries all relevant information about a command invocation. @@ -587,6 +659,7 @@ define([ this.id = options.id; // unique id this.name = options.name; this.tooltip = options.tooltip; + this.fixAllEnabled = options.fixAllEnabled; // optional toggle for quickfix command to apply to all annotations this.callback = options.callback; // optional callback that should be called when command is activated (clicked) this.preCallback = options.preCallback; // optional callback that should be called when command is activated (clicked) this.hrefCallback = options.hrefCallback; // optional callback that returns an href for a command link @@ -701,6 +774,7 @@ define([ CommandInvocation: CommandInvocation, createDropdownMenu: createDropdownMenu, createCheckedMenuItem: createCheckedMenuItem, + createQuickfixItem: createQuickfixItem, createCommandItem: createCommandItem, createCommandMenuItem: createCommandMenuItem, executeBinding: executeBinding, diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/editorCommands.js b/bundles/org.eclipse.orion.client.ui/web/orion/editorCommands.js index 8eead8a..fbd32c9 100644 --- a/bundles/org.eclipse.orion.client.ui/web/orion/editorCommands.js +++ b/bundles/org.eclipse.orion.client.ui/web/orion/editorCommands.js @@ -974,7 +974,7 @@ define([ offset: editor.getCaretOffset() }; - // TODO: Make this more generic + // Provide the quick fix command with the selected annotation if (info.scopeId === "orion.edit.quickfix") { context.annotation = { start: data.userData.start, @@ -983,25 +983,26 @@ define([ id: data.userData.id, data: data.userData.data }; - } else if (info.scopeId === "orion.edit.quickfixAll"){ - context.annotations = []; - for (var i=0; i<data.userData.annotations.length; i++) { - context.annotations.push( - { - start: data.userData.annotations[i].start, - end: data.userData.annotations[i].end, - title: data.userData.annotations[i].title, - id: data.userData.annotations[i].id, - data: data.userData.annotations[i].data + // Also include other annotations with the same id + // TODO: We are using the internals of the annotation model here + // TODO We also check the model existence in commands.js + if (data.userData.doFixAll && data.userData._annotationModel){ + context.doFixAll = true; + context.annotations = []; + var allAnnotations = data.userData._annotationModel._annotations; + for (var i=0; i<allAnnotations.length; i++) { + if (allAnnotations[i].id === data.userData.id){ + context.annotations.push( + { + start: allAnnotations[i].start, + end: allAnnotations[i].end, + title: allAnnotations[i].title, + id: allAnnotations[i].id, + data: allAnnotations[i].data + } + ); + } } - ); - } - context.annotation = { - start: data.userData.annotation.start, - end: data.userData.annotation.end, - title: data.userData.annotation.title, - id: data.userData.annotation.id, - data: data.userData.annotation.data } } var editorContext = editor.getEditorContext(); diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/extensionCommands.js b/bundles/org.eclipse.orion.client.ui/web/orion/extensionCommands.js index b4f3fc4..0ead84e 100644 --- a/bundles/org.eclipse.orion.client.ui/web/orion/extensionCommands.js +++ b/bundles/org.eclipse.orion.client.ui/web/orion/extensionCommands.js @@ -485,8 +485,11 @@ define(["orion/Deferred", "orion/commands", "orion/contentTypes", "orion/URITemp isEditor: info.isEditor, showGlobally: info.showGlobally }; + // Quickfixes for annotations are handled via commands, this option enable quickfixes to apply to all annotations + if (info.fixAllEnabled){ + commandOptions.fixAllEnabled = true; + } enhanceCommandOptions(commandOptions, deferred); - return deferred; }; diff --git a/bundles/org.eclipse.orion.client.ui/web/orion/hover.js b/bundles/org.eclipse.orion.client.ui/web/orion/hover.js index 40af439..10cabad 100644 --- a/bundles/org.eclipse.orion.client.ui/web/orion/hover.js +++ b/bundles/org.eclipse.orion.client.ui/web/orion/hover.js @@ -51,8 +51,9 @@ define ([ });
this._qfToolbars = [];
},
-
- renderQuickFixes: function(annotation, annotationIterator, parentDiv) {
+
+ // TODO The allAnnotations iterator was collected using editor API, currently unused as we instead just get the annotation model from the annotation itself (not official API)
+ renderQuickFixes: function(annotation, allAnnotations, parentDiv) {
if (!annotation || !parentDiv){
return;
}
@@ -61,32 +62,10 @@ define ([ actionsDiv.className = "commandList"; //$NON-NLS-0$
parentDiv.appendChild(actionsDiv);
- // TODO If there are multiple quickfixes, the quickfix all commands will always be at the bottom
var nodeList = [];
var metadata = this.inputManager.getFileMetadata();
metadata.annotation = annotation;
- this.commandRegistry.renderCommands("orion.edit.quickfix", actionsDiv, metadata, this.editor, 'quickfix', annotation, nodeList); //$NON-NLS-1$ //$NON-NLS-0$ //$NON-NLS-2$
- var annotations = [];
- if (annotationIterator){
- while (annotationIterator.hasNext()){
- var current = annotationIterator.next();
- if (current.id === annotation.id){
- annotations.push(current);
- }
- }
- // TODO The annotation model iterator is not guaranteed to be in order (though it is currently), sort them to make sure
- annotations = annotations.sort(function(a, b){
- return a.start - b.start;
- });
-
-
- if (annotations.length > 1){
- actionsDiv = document.createElement("div"); //$NON-NLS-0$
- actionsDiv.className = "commandList"; //$NON-NLS-0$
- this.commandRegistry.renderCommands("orion.edit.quickfixAll", actionsDiv, metadata, this.editor, 'quickfixAll', {annotation: annotation, annotations: annotations}, nodeList); //$NON-NLS-1$ //$NON-NLS-0$ //$NON-NLS-2$
- parentDiv.appendChild(actionsDiv);
- }
- }
+ this.commandRegistry.renderCommands("orion.edit.quickfix", actionsDiv, metadata, this.editor, 'quickfix', annotation, nodeList); //$NON-NLS-1$ //$NON-NLS-2$
delete metadata.annotation;
}
|