Bug 500665 - Should be able to lock the mode and icon size of a toolbar. r=neil

This commit is contained in:
Dão Gottwald 2009-09-16 16:14:37 +02:00
parent fa35f26204
commit 72ac7fb392
2 changed files with 30 additions and 47 deletions

View File

@ -642,13 +642,8 @@ function restoreDefaultSet()
} }
// Restore the default icon size and mode. // Restore the default icon size and mode.
var defaultMode = gToolbox.getAttribute("defaultmode"); document.getElementById("smallicons").checked = (updateIconSize() == "small");
var defaultIconsSmall = gToolbox.getAttribute("defaulticonsize") == "small"; document.getElementById("modelist").value = updateToolbarMode();
updateIconSize(defaultIconsSmall, true);
document.getElementById("smallicons").checked = defaultIconsSmall;
updateToolbarMode(defaultMode, true);
document.getElementById("modelist").value = defaultMode;
// Now rebuild the palette. // Now rebuild the palette.
buildPalette(); buildPalette();
@ -659,52 +654,40 @@ function restoreDefaultSet()
toolboxChanged("reset"); toolboxChanged("reset");
} }
function updateIconSize(aUseSmallIcons, localDefault) function updateIconSize(aSize) {
{ return updateToolboxProperty("iconsize", aSize);
gToolboxIconSize = aUseSmallIcons ? "small" : "large";
setAttribute(gToolbox, "iconsize", gToolboxIconSize);
gToolboxDocument.persist(gToolbox.id, "iconsize");
for (var i = 0; i < gToolbox.childNodes.length; ++i) {
var toolbar = getToolbarAt(i);
if (isCustomizableToolbar(toolbar)) {
var toolbarIconSize = (localDefault && toolbar.hasAttribute("defaulticonsize")) ?
toolbar.getAttribute("defaulticonsize") :
gToolboxIconSize;
setAttribute(toolbar, "iconsize", toolbarIconSize);
gToolboxDocument.persist(toolbar.id, "iconsize");
}
}
} }
function updateToolbarMode(aModeValue, localDefault) function updateToolbarMode(aModeValue) {
{ var mode = updateToolboxProperty("mode", aModeValue);
setAttribute(gToolbox, "mode", aModeValue);
gToolboxDocument.persist(gToolbox.id, "mode");
for (var i = 0; i < gToolbox.childNodes.length; ++i) {
var toolbar = getToolbarAt(i);
if (isCustomizableToolbar(toolbar)) {
var toolbarMode = (localDefault && toolbar.hasAttribute("defaultmode")) ?
toolbar.getAttribute("defaultmode") :
aModeValue;
setAttribute(toolbar, "mode", toolbarMode);
gToolboxDocument.persist(toolbar.id, "mode");
}
}
var iconSizeCheckbox = document.getElementById("smallicons"); var iconSizeCheckbox = document.getElementById("smallicons");
iconSizeCheckbox.disabled = aModeValue == "text"; iconSizeCheckbox.disabled = mode == "text";
return mode;
} }
function updateToolboxProperty(aProp, aValue) {
var toolboxDefault = gToolbox.getAttribute("default" + aProp);
function setAttribute(aElt, aAttr, aVal) gToolbox.setAttribute(aProp, aValue || toolboxDefault);
{ gToolboxDocument.persist(gToolbox.id, aProp);
if (aVal)
aElt.setAttribute(aAttr, aVal); Array.forEach(gToolbox.childNodes, function (toolbar) {
else if (!isCustomizableToolbar(toolbar))
aElt.removeAttribute(aAttr); return;
var toolbarDefault = toolbar.getAttribute("default" + aProp) ||
toolboxDefault;
if (toolbar.getAttribute("lock" + aProp) == "true" &&
toolbar.getAttribute(aProp) == toolbarDefault)
return;
toolbar.setAttribute(aProp, aValue || toolbarDefault);
gToolboxDocument.persist(toolbar.id, aProp);
});
return aValue;
} }
function isCustomizableToolbar(aElt) function isCustomizableToolbar(aElt)

View File

@ -86,7 +86,7 @@
</menupopup> </menupopup>
</menulist> </menulist>
<checkbox id="smallicons" oncommand="updateIconSize(this.checked);" label="&useSmallIcons.label;"/> <checkbox id="smallicons" oncommand="updateIconSize(this.checked ? 'small' : 'large');" label="&useSmallIcons.label;"/>
<button label="&addNewToolbar.label;" oncommand="addNewToolbar();" icon="add"/> <button label="&addNewToolbar.label;" oncommand="addNewToolbar();" icon="add"/>
<button label="&restoreDefaultSet.label;" oncommand="restoreDefaultSet();" icon="revert"/> <button label="&restoreDefaultSet.label;" oncommand="restoreDefaultSet();" icon="revert"/>