From 4d60e3739a2117a6e33e04a23b3f85de587cbfd7 Mon Sep 17 00:00:00 2001 From: "mattwillis%gmail.com" Date: Fri, 21 Dec 2007 16:35:34 +0000 Subject: [PATCH] bug 325468 - Populates View > Toolbars menu dynamically to pick up user-created toolbars. r=jminta --- .../sunbird/base/content/applicationUtil.js | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/calendar/sunbird/base/content/applicationUtil.js b/calendar/sunbird/base/content/applicationUtil.js index bc1f914e0b2..8b285ca79dc 100644 --- a/calendar/sunbird/base/content/applicationUtil.js +++ b/calendar/sunbird/base/content/applicationUtil.js @@ -386,3 +386,55 @@ function hasPositiveIntegerValue(elementId) return false; } +/** + * We recreate the View > Toolbars menu each time it is opened to include any + * user-created toolbars. + */ +function sbOnViewToolbarsPopupShowing(aEvent) +{ + var popup = aEvent.target; + var i; + + // Empty the menu + for (i = popup.childNodes.length-1; i >= 0; i--) { + var deadItem = popup.childNodes[i]; + if (deadItem.hasAttribute("toolbarindex")) { + deadItem.removeEventListener("command", sbOnViewToolbarCommand, false); + popup.removeChild(deadItem); + } + } + + var firstMenuItem = popup.firstChild; + + var toolbox = document.getElementById("calendar-toolbox"); + for (i = 0; i < toolbox.childNodes.length; i++) { + var toolbar = toolbox.childNodes[i]; + var toolbarName = toolbar.getAttribute("toolbarname"); + var type = toolbar.getAttribute("type"); + if (toolbarName && type != "menubar") { + var menuItem = document.createElement("menuitem"); + menuItem.setAttribute("toolbarindex", i); + menuItem.setAttribute("type", "checkbox"); + menuItem.setAttribute("label", toolbarName); + menuItem.setAttribute("accesskey", toolbar.getAttribute("accesskey")); + menuItem.setAttribute("checked", toolbar.getAttribute("collapsed") != "true"); + popup.insertBefore(menuItem, firstMenuItem); + + menuItem.addEventListener("command", sbOnViewToolbarCommand, false); + } + } +} + +/** + * Toggles the visibility of the associated toolbar when fired. + */ +function sbOnViewToolbarCommand(aEvent) +{ + var toolbox = document.getElementById("calendar-toolbox"); + var index = aEvent.originalTarget.getAttribute("toolbarindex"); + var toolbar = toolbox.childNodes[index]; + + toolbar.collapsed = (aEvent.originalTarget.getAttribute("checked") != "true"); + document.persist(toolbar.id, "collapsed"); +} +