Bug 1096763 - fix webide button issues with customize mode, r=Unfocused

This fixes the button to not call createWidget repeatedly when the button is in the palette.

It also fixes an edge case in CustomizableUI where, if you restore defaults, we don't re-add custom widgets to the list of seen widgets, meaning they'll be restored to their default position on next start, even if you move them after restoring to defaults.
This commit is contained in:
Gijs Kruitbosch 2014-11-11 14:51:21 +00:00
parent d94b8baa2b
commit 16d4bec6ab
4 changed files with 62 additions and 21 deletions

View File

@ -2056,25 +2056,23 @@ let CustomizableUIInternal = {
// If we're restoring the widget to it's old placement, fire off the
// onWidgetAdded event - our own handler will take care of adding it to
// any build areas.
if (widget.currentArea) {
this.notifyListeners("onWidgetAdded", widget.id, widget.currentArea,
widget.currentPosition);
} else if (widgetMightNeedAutoAdding) {
let autoAdd = true;
try {
autoAdd = Services.prefs.getBoolPref(kPrefCustomizationAutoAdd);
} catch (e) {}
// If the widget doesn't have an existing placement, and it hasn't been
// seen before, then add it to its default area so it can be used.
// If the widget is not removable, we *have* to add it to its default
// area here.
let canBeAutoAdded = autoAdd && !gSeenWidgets.has(widget.id);
if (!widget.currentArea && (!widget.removable || canBeAutoAdded)) {
this.beginBatchUpdate();
this.beginBatchUpdate();
try {
if (widget.currentArea) {
this.notifyListeners("onWidgetAdded", widget.id, widget.currentArea,
widget.currentPosition);
} else if (widgetMightNeedAutoAdding) {
let autoAdd = true;
try {
gSeenWidgets.add(widget.id);
autoAdd = Services.prefs.getBoolPref(kPrefCustomizationAutoAdd);
} catch (e) {}
// If the widget doesn't have an existing placement, and it hasn't been
// seen before, then add it to its default area so it can be used.
// If the widget is not removable, we *have* to add it to its default
// area here.
let canBeAutoAdded = autoAdd && !gSeenWidgets.has(widget.id);
if (!widget.currentArea && (!widget.removable || canBeAutoAdded)) {
if (widget.defaultArea) {
if (this.isAreaLazy(widget.defaultArea)) {
gFuturePlacements.get(widget.defaultArea).add(widget.id);
@ -2082,10 +2080,13 @@ let CustomizableUIInternal = {
this.addWidgetToArea(widget.id, widget.defaultArea);
}
}
} finally {
this.endBatchUpdate(true);
}
}
} finally {
// Ensure we always have this widget in gSeenWidgets, and save
// state in case this needs to be done here.
gSeenWidgets.add(widget.id);
this.endBatchUpdate(true);
}
this.notifyListeners("onWidgetAfterCreation", widget.id, widget.currentArea);
@ -2119,7 +2120,7 @@ let CustomizableUIInternal = {
normalizeWidget: function(aData, aSource) {
let widget = {
implementation: aData,
source: aSource || "addon",
source: aSource || CustomizableUI.SOURCE_EXTERNAL,
instances: new Map(),
currentArea: null,
removable: true,
@ -2323,6 +2324,15 @@ let CustomizableUIInternal = {
// was reset above.
this._rebuildRegisteredAreas();
for (let [widgetId, widget] of gPalette) {
if (widget.source == CustomizableUI.SOURCE_EXTERNAL) {
gSeenWidgets.add(widgetId);
}
}
if (gSeenWidgets.size) {
gDirty = true;
}
gResetting = false;
},

View File

@ -154,3 +154,4 @@ skip-if = os == "mac"
[browser_bootstrapped_custom_toolbar.js]
[browser_panel_toggle.js]
[browser_1089591_still_customizable_after_reset.js]
[browser_1096763_seen_widgets_post_reset.js]

View File

@ -0,0 +1,30 @@
"use strict";
const BUTTONID = "test-seenwidget-post-reset";
add_task(function*() {
let widget = CustomizableUI.createWidget({
id: BUTTONID,
label: "Test widget seen post reset",
defaultArea: CustomizableUI.AREA_NAVBAR
});
let bsPass = Cu.import("resource:///modules/CustomizableUI.jsm", {});
ok(bsPass.gSeenWidgets.has(BUTTONID), "Widget should be seen after createWidget is called.");
CustomizableUI.reset();
ok(bsPass.gSeenWidgets.has(BUTTONID), "Widget should still be seen after reset.");
ok(!Services.prefs.prefHasUserValue(bsPass.kPrefCustomizationState), "Pref shouldn't be set right now, because that'd break undo.");
CustomizableUI.addWidgetToArea(BUTTONID, CustomizableUI.AREA_NAVBAR);
gCustomizeMode.removeFromArea(document.getElementById(BUTTONID));
let hasUserValue = Services.prefs.prefHasUserValue(bsPass.kPrefCustomizationState);
ok(hasUserValue, "Pref should be set right now.");
if (hasUserValue) {
let seenArray = JSON.parse(Services.prefs.getCharPref(bsPass.kPrefCustomizationState)).seen;
isnot(seenArray.indexOf(BUTTONID), -1, "Widget should be in saved 'seen' list.");
}
});
registerCleanupFunction(function() {
CustomizableUI.destroyWidget(BUTTONID);
CustomizableUI.reset();
});

View File

@ -780,7 +780,7 @@ let gDevToolsBrowser = {
isWebIDEWidgetInstalled: function() {
let widgetWrapper = CustomizableUI.getWidget("webide-button");
return !!(widgetWrapper && widgetWrapper.instances.some(i => !!i.node));
return !!(widgetWrapper && widgetWrapper.provider == CustomizableUI.PROVIDER_API);
},
/**