Skip to content

Commit

Permalink
Fix errors when a comment is selected. Also disable autocomplete when…
Browse files Browse the repository at this point in the history
… editing a comment
  • Loading branch information
samitbadle committed Sep 14, 2014
1 parent f8341b8 commit 9cff008
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 59 deletions.
12 changes: 7 additions & 5 deletions ide/main/src/content/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -1091,11 +1091,13 @@ Editor.prototype.reload = function () {
};

Editor.prototype.showReference = function (command) {
var def = command.getDefinition();
if (def) {
this.infoPanel.switchView(this.infoPanel.helpView);
this.log.debug("showReference: " + def.name);
this.reference.show(def, command);
if (command.type == 'command') {
var def = command.getDefinition();
if (def) {
this.infoPanel.switchView(this.infoPanel.helpView);
this.log.debug("showReference: " + def.name);
this.reference.show(def, command);
}
}
};

Expand Down
122 changes: 68 additions & 54 deletions ide/main/src/content/treeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ objectExtend(TreeView.prototype, {
onEvent : function(evt) {}
};
this.tree.controllers.appendController(controller);

// this.atomService = Components.classes["@mozilla.org/atom-service;1"].
// getService(Components.interfaces.nsIAtomService);

this._loadSeleniumCommands();
},

Expand Down Expand Up @@ -123,13 +119,22 @@ objectExtend(TreeView.prototype, {
return this.clipboard;
},

setTextBox: function(id,value,disabled) {
this.document.getElementById(id).value = value;
this.document.getElementById(id).disabled = disabled;
updateTextBox: function(id, value, disabled, autoComplete) {
var e = this.document.getElementById(id);
e.value = value;
e.disabled = disabled;
if (arguments.length == 4) {
e.disableAutoComplete = !autoComplete;
if (autoComplete) {
e.setAttribute("enablehistory", 'true');
} else {
e.removeAttribute("enablehistory");
}
}
},

updateTarget: function(value, disabled) {
this.setTextBox("commandTarget", value, disabled);
this.updateTextBox("commandTarget", value, disabled);
this.document.getElementById('selectElementButton').disabled = disabled;
this.document.getElementById('findElementButton').disabled = disabled;
},
Expand Down Expand Up @@ -202,21 +207,21 @@ objectExtend(TreeView.prototype, {
var command = this.currentCommand;
var candidates = [];
var targetBox = this.document.getElementById("commandTarget");
// various strategies for auto-populating the target field
if (command.isRollup() && Editor.rollupManager) {
candidates = Editor.rollupManager.getRollupRulesForDropdown();
}
else {
if (command.targetCandidates) {
candidates = candidates.concat(command.targetCandidates);
}
// if lastURL exists, load only those targets associated with it.
// Otherwise, show all possible targets.
if (Editor.uiMap) {
candidates = candidates
.concat(Editor.uiMap.getUISpecifierStringStubs());
}

if (command.type == 'command') {
// various strategies for auto-populating the target field
if (command.isRollup() && Editor.rollupManager) {
candidates = Editor.rollupManager.getRollupRulesForDropdown();
} else {
if (command.targetCandidates) {
candidates = candidates.concat(command.targetCandidates);
}
// if lastURL exists, load only those targets associated with it.
// Otherwise, show all possible targets.
if (Editor.uiMap) {
candidates = candidates.concat(Editor.uiMap.getUISpecifierStringStubs());
}
}
}

if (candidates.length > 0) {
Expand All @@ -233,7 +238,7 @@ objectExtend(TreeView.prototype, {
XulUtils.toXPCOMArray(types));
this.updateTarget(this.encodeText(command.target), false);
} else {
targetBox.setAttribute("enablehistory", "false");
targetBox.removeAttribute("enablehistory");
targetBox.disableAutoComplete = true;
this.updateTarget(this.encodeText(command.target), false);
}
Expand All @@ -257,8 +262,7 @@ objectExtend(TreeView.prototype, {
args[name] = "";
keys.push(name);
}
this.setTextBox('commandValue',
this.encodeText(to_kwargs(args, keys)), false);
this.updateTextBox('commandValue', this.encodeText(to_kwargs(args, keys)), false);
}
}
},
Expand All @@ -274,15 +278,21 @@ objectExtend(TreeView.prototype, {
},

encodeText: function(text) {
text = text.replace(/\\/g, "\\\\");
text = text.replace(/\n/g, "\\n");
return text;
if (text) {
text = text.replace(/\\/g, "\\\\");
text = text.replace(/\n/g, "\\n");
return text;
}
return '';
},

decodeText: function(text) {
text = text.replace(/\\n/g, "\n");
text = text.replace(/\\\\/g, "\\");
return text;
if (text) {
text = text.replace(/\\n/g, "\n");
text = text.replace(/\\\\/g, "\\");
return text;
}
return '';
},

/*
Expand Down Expand Up @@ -326,23 +336,25 @@ objectExtend(TreeView.prototype, {
var command = this.getCommand(this.tree.currentIndex);
this.currentCommand = command;
if (command.type == 'command') {
this.setTextBox("commandAction", command.command, false);
this.updateTextBox("commandAction", command.command, false, true);
this.updateSeleniumTargets();
this.setTextBox("commandValue", this.encodeText(command.value), false);
this.updateTextBox("commandValue", this.encodeText(command.value), false);
} else if (command.type == 'comment') {
this.setTextBox("commandAction", command.comment, false);
this.updateTextBox("commandAction", command.comment, false, false);
this.updateTarget('', true);
this.setTextBox("commandValue", '', true);
this.updateTextBox("commandValue", '', true);
}

this.selectRecordIndex(this.tree.currentIndex);
this.editor.showReference(command);
this.editor.showUIReference(command.target);
this.editor.showRollupReference(command);
if (command.type == 'command') {
this.editor.showReference(command);
this.editor.showUIReference(command.target);
this.editor.showRollupReference(command);
}
} else {
this.setTextBox("commandAction", '', true);
this.updateTextBox("commandAction", '', true);
this.updateTarget('', true);
this.setTextBox("commandValue", '', true);
this.updateTextBox("commandValue", '', true);
this.currentCommand = null;
}
window.updateCommands('select');
Expand All @@ -358,8 +370,10 @@ objectExtend(TreeView.prototype, {
if (this.currentCommand != null) {
this.executeAction(new TreeView.UpdateCommandAction(this, key, value));
if (key == 'command') {
this.updateSeleniumTargets();
this.editor.showReference(this.currentCommand);
if (this.currentCommand.type == 'command') {
this.updateSeleniumTargets();
this.editor.showReference(this.currentCommand);
}
}
else if (key == 'targetCandidates') {
this.updateSeleniumTargets();
Expand All @@ -379,9 +393,9 @@ objectExtend(TreeView.prototype, {
}
},
onHide: function() {
this.setTextBox("commandAction", '', true);
this.updateTextBox("commandAction", '', true);
this.updateTarget('', true);
this.setTextBox("commandValue", '', true);
this.updateTextBox("commandValue", '', true);
this.currentCommand = null;
},
getRecordIndex: function() {
Expand Down Expand Up @@ -646,7 +660,7 @@ TreeView.UpdateCommandAction = function(treeView, key, value) {
this.value = value;
this.index = this.treeView.tree.currentIndex;
this.wasNewCommand = this.command == treeView.newCommand;
}
};

TreeView.UpdateCommandAction.prototype = {
execute: function() {
Expand Down Expand Up @@ -689,12 +703,12 @@ TreeView.UpdateCommandAction.prototype = {
this.treeView.selectCommand();
}
}
}
};

TreeView.DeleteCommandAction = function(treeView, ranges) {
this.treeView = treeView;
this.ranges = ranges;
}
};

TreeView.DeleteCommandAction.prototype = {
execute: function() {
Expand Down Expand Up @@ -730,13 +744,13 @@ TreeView.DeleteCommandAction.prototype = {
}
this.treeView.selection.select(currentIndex);
}
}
};

TreeView.PasteCommandAction = function(treeView, index, commands) {
this.treeView = treeView;
this.index = index;
this.commands = commands;
}
};

TreeView.PasteCommandAction.prototype = {
execute: function() {
Expand Down Expand Up @@ -767,7 +781,7 @@ TreeView.PasteCommandAction.prototype = {
this.treeView.selection.select(currentIndex);
this.treeView.treebox.ensureRowIsVisible(currentIndex);
}
}
};

//D'n'D action for the undo/redo process
TreeView.dndCommandAction = function(treeView, sourceIndex, dropIndex, orientation){
Expand All @@ -786,7 +800,7 @@ TreeView.dndCommandAction = function(treeView, sourceIndex, dropIndex, orientati
this.sourceIndexU++;
}
this.orientationU = this.orientation == Ci.nsITreeView.DROP_BEFORE ? Ci.nsITreeView.DROP_AFTER : Ci.nsITreeView.DROP_BEFORE;
}
};

TreeView.dndCommandAction.prototype = {

Expand Down Expand Up @@ -834,4 +848,4 @@ TreeView.dndCommandAction.prototype = {
}

}
}
};

0 comments on commit 9cff008

Please sign in to comment.