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

This commit is contained in:
Brandon Benvie 2013-10-01 13:17:20 -07:00
Родитель 0b6c80bbe8
Коммит 67ddb4fb9c
5 изменённых файлов: 46 добавлений и 22 удалений

Просмотреть файл

@ -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",

Просмотреть файл

@ -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 {

Просмотреть файл

@ -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;
}
};

Просмотреть файл

@ -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 };
},
};

Просмотреть файл

@ -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);
});
},
/**