Bug 843019 - Add VariablesViewController#setSingleVariable. r=vp, r=msucan

This commit is contained in:
Brandon Benvie 2013-10-01 13:17:20 -07:00
parent 702ec29ee0
commit 7a78473ee8
5 changed files with 46 additions and 22 deletions

View File

@ -65,6 +65,7 @@ Cu.import("resource:///modules/devtools/sourceeditor/source-editor.jsm");
Cu.import("resource:///modules/devtools/shared/event-emitter.js");
Cu.import("resource:///modules/devtools/SideMenuWidget.jsm");
Cu.import("resource:///modules/devtools/VariablesView.jsm");
Cu.import("resource:///modules/devtools/VariablesViewController.jsm");
Cu.import("resource:///modules/devtools/ViewHelpers.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PluralForm",

View File

@ -1539,6 +1539,7 @@ NetworkDetailsView.prototype = {
Heritage.extend(GENERIC_VARIABLES_VIEW_SETTINGS, {
searchPlaceholder: L10N.getStr("jsonFilterText")
}));
VariablesViewController.attach(this._json);
this._paramsQueryString = L10N.getStr("paramsQueryString");
this._paramsFormData = L10N.getStr("paramsFormData");
@ -1889,9 +1890,10 @@ NetworkDetailsView.prototype = {
? L10N.getFormatStr("jsonpScopeName", callbackPadding[0].slice(0, -1))
: L10N.getStr("jsonScopeName");
let jsonScope = this._json.addScope(jsonScopeName);
jsonScope.addItem().populate(jsonObject, { expanded: true });
jsonScope.expanded = true;
this._json.controller.setSingleVariable({
label: jsonScopeName,
rawObject: jsonObject,
});
}
// Malformed JSON.
else {

View File

@ -1831,15 +1831,10 @@ ScratchpadSidebar.prototype = {
*/
_update: function SS__update(aObject)
{
let options = { objectActor: aObject };
let view = this.variablesView;
view.empty();
let scope = view.addScope();
scope.expanded = true;
scope.locked = true;
let container = scope.addItem();
return view.controller.expand(container, aObject);
return view.controller.setSingleVariable(options).expanded;
}
};

View File

@ -44,7 +44,7 @@ this.EXPORTED_SYMBOLS = ["VariablesViewController", "StackFrameUtils"];
*
* @param VariablesView aView
* The view to attach to.
* @param object aOptions
* @param object aOptions [optional]
* Options for configuring the controller. Supported options:
* - getObjectClient: callback for creating an object grip client
* - getLongStringClient: callback for creating a long string grip client
@ -54,7 +54,7 @@ this.EXPORTED_SYMBOLS = ["VariablesViewController", "StackFrameUtils"];
* - getterOrSetterEvalMacro: callback for creating a getter/setter eval macro
* - simpleValueEvalMacro: callback for creating a simple value eval macro
*/
function VariablesViewController(aView, aOptions) {
function VariablesViewController(aView, aOptions = {}) {
this.addExpander = this.addExpander.bind(this);
this._getObjectClient = aOptions.getObjectClient;
@ -442,6 +442,37 @@ VariablesViewController.prototype = {
}
}
},
/**
* Helper function for setting up a single Scope with a single Variable
* contained within it.
*
* @param object aOptions
* Options for the contents of the view:
* - objectActor: the grip of the new ObjectActor to show.
* - rawObject: the new raw object to show.
* - label: the new label for the inspected object.
* @return Object
* - variable: the created Variable.
* - expanded: the Promise that resolves when the variable expands.
*/
setSingleVariable: function(aOptions) {
let scope = this.view.addScope(aOptions.label);
scope.expanded = true;
scope.locked = true;
let variable = scope.addItem();
let expanded;
if (aOptions.objectActor) {
expanded = this.expand(variable, aOptions.objectActor);
} else if (aOptions.rawObject) {
variable.populate(aOptions.rawObject, { expanded: true });
expanded = promise.resolve();
}
return { variable: variable, expanded: expanded };
},
};

View File

@ -3485,20 +3485,13 @@ JSTerm.prototype = {
view.delete = null;
}
let scope = view.addScope(aOptions.label);
scope.expanded = true;
scope.locked = true;
let container = scope.addItem();
container.evaluationMacro = simpleValueEvalMacro;
let { variable, expanded } = view.controller.setSingleVariable(aOptions);
variable.evaluationMacro = simpleValueEvalMacro;
if (aOptions.objectActor) {
view.controller.expand(container, aOptions.objectActor);
view._consoleLastObjectActor = aOptions.objectActor.actor;
}
else if (aOptions.rawObject) {
container.populate(aOptions.rawObject);
view.commitHierarchy();
view._consoleLastObjectActor = null;
}
else {
@ -3506,7 +3499,9 @@ JSTerm.prototype = {
"display.");
}
this.emit("variablesview-updated", view, aOptions);
expanded.then(() => {
this.emit("variablesview-updated", view, aOptions);
});
},
/**