home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 2006-01-06 | 56.5 KB | 1,844 lines
const kRowMax = 2; const kWindowWidth = 805; const kWindowHeight = 415; const kAnimateIncrement = 50; const kAnimateSteps = kWindowHeight / kAnimateIncrement - 1; const kVSizeSlop = 5; var gToolboxDocument = null; var gToolbox = null; var gCurrentDragOverItem = null; var gToolboxChanged = false; var gToolboxIconSize = false; var gSelectedToolbar = null; var toolTree = null; var gRepopulating = false; var mObverver=null; function onLoad() { gToolbox = window.arguments[0]; gToolboxDocument = gToolbox.ownerDocument; gToolbox.addEventListener("draggesture", onToolbarDragGesture, false); gToolbox.addEventListener("dragover", onToolbarDragOver, false); gToolbox.addEventListener("dragexit", onToolbarDragExit, false); gToolbox.addEventListener("dragdrop", onToolbarDragDrop, false); var multibars = gToolbox.getElementsByTagName('multibar'); var multibar; for (var i =0; i < multibars.length; i++) { multibar = multibars.item(i); } repositionDialog(); initDialog(); gToolboxDocument.defaultView.reshuffleToolbars(true); } function onUnload(aEvent) { removeToolboxListeners(); unwrapToolbarItems(); persistCurrentSets(); notifyParentComplete(); window.close(); } function onAccept(aEvent) { document.getElementById("main-box").collapsed = true; // gToolboxDocument.moveMenubar(); window.close(); } /* var renameOnly = false; function renameBySetButton(newName) { renameOnly = true; renameToolbar(newName); } */ function renameToolbar(newName) { // dump("\n\nNew toolbar name is : " + newName + "\n"); if (!newName || (newName == '')) { var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(Components.interfaces.nsIPromptService); var stringBundle = document.getElementById("stringBundle"); var title = stringBundle.getString("toolbarMustHaveNameTitle"); var message = stringBundle.getString("toolbarMustHaveNameMessage"); promptService.alert(window, title, message); return; } if (gSelectedToolbar.localName == 'multibartray') { gSelectedToolbar.parentNode .renameTray(gSelectedToolbar.parentNode .getIndexOfTray(gSelectedToolbar), newName); // Reset the "Set" button flag // if(renameOnly) renameOnly = false; } else { // if(renameOnly) { // Don't change the id, as I only want to change the name // renameOnly = false; //gSelectedToolbar.setAttribute("toolbarname", newName); // } //else gSelectedToolbar.parentNode.renameToolbar(gSelectedToolbar, newName); } gToolboxChanged = true; populateTree(); updateToolbarSelected(); } function populateTree() { gRepopulating = true; var treeItems = document.getElementById("toolbarItemParent") .getElementsByTagNameNS('http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul', 'treeitem'); var thisChild = treeItems.item(0); while (thisChild) { dump("\n\nGonna remove " + thisChild.getAttribute("toolbarId") + "\n\n"); thisChild.parentNode.removeChild(thisChild); thisChild = treeItems.item(0); } var toolbarset = gToolboxDocument.getElementById("customToolbars"); var toolbarorder = toolbarset.getAttribute("toolbarorder"); dump("\nmultibar: The toolbar order is : " + toolbarorder + "\n"); var orderSplit = toolbarorder.split(","); for (var i=0; i < orderSplit.length; i++) { var node = gToolboxDocument.getElementById(orderSplit[i]); if (node && node.localName == 'toolbar') { addToolbarMenuItem(node); } else if (node && node.localName == 'multibar') { // JMC : Add parent tree node for multibar var multibarTreeItem = addToolbarMenuItem(node); multibarTreeItem.setAttribute('container', 'true'); multibarTreeItem.setAttribute('open', 'true'); var subtreeParent = document.createElement("treechildren"); multibarTreeItem.appendChild(subtreeParent); var innerSplit = node.currentSet.split(";"); for (var j=0; j < innerSplit.length; j++) { var trayCSet = innerSplit[j]; var trayName = trayCSet.split(":").shift(); var thisTray = node.getTrayByName(trayName); addToolbarMenuItem(thisTray, subtreeParent); } } } gRepopulating = false; // gSelectedToolbar = getToolbarAt(1); } function initDialog() { document.getElementById("main-box").collapsed = false; // var prefService = Components.classes["@mozilla.org/preferences-service;1"] // .getService(Components.interfaces.nsIPrefBranch); // document.getElementById("menuInTitlebar").setAttribute("checked",(prefService.getBoolPref('browser.menu_in_titlebar')) ? "true" : "false"); // Build an array of toolbars // Add menuitems to the menulist of toolbars // Select the first one // Pull the mode and icon size from it toolTree = document.getElementById("toolbartree"); populateTree(); toolTree.view.selection.select(0); // Build up the palette of other items. buildPalette(); // Wrap all the items on the toolbar in toolbarpaletteitems. wrapToolbarItems(); updateToolbarSelected(); } function repositionDialog() { // Position the dialog touching the bottom of the toolbox and centered with // it. We must resize the window smaller first so that it is positioned // properly. gToolboxDocument.defaultView.reshuffleToolbars(); var screenX = gToolbox.boxObject.screenX + ((gToolbox.boxObject.width - kWindowWidth) / 2); var screenY = gToolbox.boxObject.screenY + gToolbox.boxObject.height; var newHeight = kWindowHeight; if (newHeight >= screen.availHeight - screenY - kVSizeSlop) { newHeight = screen.availHeight - screenY - kVSizeSlop; } window.resizeTo(kWindowWidth, newHeight); window.moveTo(screenX, screenY); } function removeToolboxListeners() { gToolbox.removeEventListener("draggesture", onToolbarDragGesture, false); gToolbox.removeEventListener("dragover", onToolbarDragOver, false); gToolbox.removeEventListener("dragexit", onToolbarDragExit, false); gToolbox.removeEventListener("dragdrop", onToolbarDragDrop, false); var multibars = gToolbox.getElementsByTagName('multibar'); var multibar; for (var i =0; i < multibars.length; i++) { multibar = multibars.item(i); } } /** * Invoke a callback on the toolbox to notify it that the dialog is done * and going away. */ function notifyParentComplete() { if ("customizeDone" in gToolbox) gToolbox.customizeDone(gToolboxChanged); } // JMC: Extended to return toolbar with matching ordinal function getToolbarByOrdinal(ordinal) { for (var i = 0; i < gToolbox.childNodes.length; i++) { var toolbar = gToolbox.childNodes[i]; if (toolbar && toolbar.localName == "toolbar" && toolbar.getAttribute("ordinal") == ordinal) { return toolbar; } } } function getToolbarAt(i) { return gToolbox.childNodes[i]; } /** * Persist the current set of buttons in all customizable toolbars to * localstore. */ function persistCurrentSets() { dump("CUSTOMIZE: Persisting current sets\n"); // var prefService = Components.classes["@mozilla.org/preferences-service;1"] // .getService(Components.interfaces.nsIPrefBranch); // prefService.setBoolPref('browser.menu_in_titlebar', document.getElementById("menuInTitlebar").checked); // gToolboxDocument.moveMenubar(); if (!gToolboxChanged) { dump ("I don't think the sets have changed, exiting... \t"); return; } var customToolbarCount = 0; var customMultibarCount = 0; for (var i = 0; i < gToolbox.childNodes.length; ++i) { // Look for customizable toolbars that need to be persisted. var toolbar = getToolbarAt(i); if (isCustomizableToolbar(toolbar)) { // Calculate currentset and store it in the attribute. var currentSet = toolbar.currentSet; toolbar.setAttribute("currentset", currentSet); dump ("Persist Current Sets - about to reset currentset on toolbar " + toolbar.id + " to " + currentSet + "\t\t\t"); toolbar.currentSet = currentSet; // JMC - this will force a total redraw, expensive! var customIndex = toolbar.hasAttribute("customindex"); if (customIndex) { /* if (!toolbar.firstChild) { // Remove custom toolbars whose contents have been removed. gToolbox.removeToolbar(toolbar); --i; } else { */ // Persist custom toolbar info on the <toolbarset/> if (toolbar.localName == 'toolbar') { gToolbox.toolbarset.setAttribute("toolbar"+(++customToolbarCount), toolbar.toolbarName + ":" + currentSet); gToolboxDocument.persist(gToolbox.toolbarset.id, "toolbar"+customToolbarCount); gToolbox.toolbarset.setAttribute("toolbariconsize"+(customToolbarCount), toolbar.getAttribute('iconsize')); gToolboxDocument.persist(gToolbox.toolbarset.id, "toolbariconsize"+customToolbarCount); gToolbox.toolbarset.setAttribute("toolbarmode"+(customToolbarCount), toolbar.getAttribute('mode')); gToolboxDocument.persist(gToolbox.toolbarset.id, "toolbarmode"+customToolbarCount); } else if (toolbar.localName == 'multibar') { var setString = toolbar.getAttribute('toolbarname') + ":" ; for (var j = 0; j < toolbar.mTrays.length; j++) { setString += toolbar.mTrays[j].getAttribute('toolbarname') + ":" + toolbar.mTrays[j].currentSet; if (j != (toolbar.mTrays.length-1)) setString += ";"; } gToolbox.toolbarset.setAttribute("multibar"+(++customMultibarCount), setString); gToolboxDocument.persist(gToolbox.toolbarset.id, "multibar"+customMultibarCount); gToolbox.toolbarset.setAttribute("multibarselected"+(customMultibarCount), toolbar.currentTrayIndex); gToolboxDocument.persist(gToolbox.toolbarset.id, "multibarselected"+customMultibarCount); gToolbox.toolbarset.setAttribute("multibariconsize"+(customMultibarCount), toolbar.getAttribute('iconsize')); gToolboxDocument.persist(gToolbox.toolbarset.id, "multibariconsize"+customMultibarCount); gToolbox.toolbarset.setAttribute("multibarmode"+(customMultibarCount), toolbar.getAttribute('mode')); gToolboxDocument.persist(gToolbox.toolbarset.id, "multibarmode"+customMultibarCount); } // } } if (!customIndex) { // Persist the currentset attribute directly on hardcoded toolbars. dump ("This toolbar is not custom, persisting directly on it... \t"); gToolboxDocument.persist(toolbar.id, "currentset"); toolbar.setAttribute("currentIndex", toolbar.currentTrayIndex); } } } // Remove toolbarX attributes for removed toolbars. while (gToolbox.toolbarset.hasAttribute("toolbar"+(++customToolbarCount))) { gToolbox.toolbarset.removeAttribute("toolbar"+customToolbarCount); gToolboxDocument.persist(gToolbox.toolbarset.id, "toolbar"+customToolbarCount); } while (gToolbox.toolbarset.hasAttribute("multibar"+(++customMultibarCount))) { gToolbox.toolbarset.removeAttribute("multibar"+customMultibarCount); gToolboxDocument.persist(gToolbox.toolbarset.id, "multibar"+customMultibarCount); gToolbox.toolbarset.removeAttribute("multibarselected"+customMultibarCount); gToolboxDocument.persist(gToolbox.toolbarset.id, "multibarselected"+customMultibarCount); } } /** * Wraps all items in all customizable toolbars in a toolbox. */ function wrapToolbarItems() { for (var i = 0; i < gToolbox.childNodes.length; i++) { var toolbar = getToolbarAt(i); if (toolbar.localName == 'multibar') { for (var j = 0; j < toolbar.mTrays.length; j++) { var multibartray = toolbar.mTrays[j]; for (var k = 0; k < multibartray.childNodes.length; k++) { var item = multibartray.childNodes[k]; if (isToolbarItem(item)) { var nextSibling = item.nextSibling; var wrapper = wrapToolbarItem(item); if (nextSibling) { dump ("Inserting wrapper for " + item.id + " just before " + nextSibling.id + "\t"); multibartray.insertBefore(wrapper, nextSibling); } else { multibartray.appendChild(wrapper); } } } } } else { if (isCustomizableToolbar(toolbar)) { for (var k = 0; k < toolbar.childNodes.length; ++k) { var item = toolbar.childNodes[k]; if (isToolbarItem(item)) { var nextSibling = item.nextSibling; var wrapper = wrapToolbarItem(item); if (nextSibling) toolbar.insertBefore(wrapper, nextSibling); else toolbar.appendChild(wrapper); } } } } } } /** * Unwraps all items in all customizable toolbars in a toolbox. */ function unwrapToolbarItems() { // JMC: Must unwrap multibar toolbaritems here, too var paletteItems = gToolbox.getElementsByTagName("toolbarpaletteitem"); var paletteItem; while ((paletteItem = paletteItems.item(0)) != null) { var toolbarItem = paletteItem.firstChild; if (paletteItem.hasAttribute("itemdisabled")) toolbarItem.disabled = true; if (paletteItem.hasAttribute("itemcommand")) toolbarItem.setAttribute("command", paletteItem.getAttribute("itemcommand")); if (paletteItem.hasAttribute("itemstate")) toolbarItem.setAttribute("state", paletteItem.getAttribute("itemstate")); // We need the removeChild here because replaceChild and XBL no workee // together. See bug 193298. paletteItem.removeChild(toolbarItem); paletteItem.parentNode.replaceChild(toolbarItem, paletteItem); } var multibars = gToolbox.getElementsByTagName("multibar"); var multibar; for (var i =0; i < multibars.length; i++) { multibar = multibars.item(i); } } /** * Creates a wrapper that can be used to contain a toolbaritem and prevent * it from receiving UI events. */ function createWrapper(aId) { var wrapper = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "toolbarpaletteitem"); wrapper.id = "wrapper-"+aId; return wrapper; } /** * Wraps an item that has been cloned from a template and adds * it to the end of a row in the palette. */ function wrapPaletteItem(aPaletteItem, aCurrentRow, aSpacer) { var wrapper = createWrapper(aPaletteItem.id); wrapper.setAttribute("flex", 1); wrapper.setAttribute("align", "center"); wrapper.setAttribute("pack", "center"); wrapper.setAttribute("minheight", "0"); wrapper.setAttribute("minwidth", "0"); wrapper.appendChild(aPaletteItem); // XXX We need to call this AFTER the palette item has been appended // to the wrapper or else we crash dropping certain buttons on the // palette due to removal of the command and disabled attributes - JRH cleanUpItemForPalette(aPaletteItem, wrapper); if (aSpacer) aCurrentRow.insertBefore(wrapper, aSpacer); else aCurrentRow.appendChild(wrapper); } /** * Wraps an item that is currently on a toolbar and replaces the item * with the wrapper. This is not used when dropping items from the palette, * only when first starting the dialog and wrapping everything on the toolbars. */ function wrapToolbarItem(aToolbarItem) { var wrapper = createWrapper(aToolbarItem.id); cleanupItemForToolbar(aToolbarItem, wrapper); wrapper.flex = aToolbarItem.flex; if (aToolbarItem.parentNode) aToolbarItem.parentNode.removeChild(aToolbarItem); wrapper.appendChild(aToolbarItem); return wrapper; } /** * Get the list of ids for the current set of items on each toolbar. */ function getCurrentItemIds() { var currentItems = {}; // Never put on palette // currentItems['search-container'] = 1; var toolbar = gToolbox.firstChild; while (toolbar) { if (isCustomizableToolbar(toolbar)) { var child = toolbar.firstChild; while (child) { if (isToolbarItem(child)) currentItems[child.id] = 1; child = child.nextSibling; } } // JMC if (toolbar.localName == 'multibar') { toolbar = toolbar.firstChild; } else if (toolbar.localName == 'multibartray' && (!toolbar.nextSibling)) { toolbar = toolbar.parentNode.nextSibling; } else { toolbar = toolbar.nextSibling; } } return currentItems; } var rowLimits = new Array(4); /** * Builds the palette of draggable items that are not yet in a toolbar. */ function buildPalette() { // Empty the palette first. var paletteBoxes = new Array(4); paletteBoxes[0] = document.getElementById("palette-box-grid"); paletteBoxes[1] = document.getElementById("personal-palette-box-grid"); paletteBoxes[2] = document.getElementById("functional-palette-box-grid"); paletteBoxes[3] = document.getElementById("headline-palette-box-grid"); var currentRows = new Array(4); // Different grid layout for each tab rowLimits[0] = 4; rowLimits[1] = 2; rowLimits[2] = 4; rowLimits[3] = 2; var i =0; for (i = 0; i < 4; i++) { while (paletteBoxes[i].lastChild) paletteBoxes[i].removeChild(paletteBoxes[i].lastChild); currentRows[i] = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "row"); currentRows[i].setAttribute("class", "paletteRow"); } // Add the toolbar separator item. var templateNode = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "toolbarseparator"); templateNode.id = "separator"; wrapPaletteItem(templateNode, currentRows[0], null); // Add the toolbar spring item. templateNode = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "toolbarspring"); templateNode.id = "spring"; templateNode.flex = 1; wrapPaletteItem(templateNode, currentRows[0], null); // Add the toolbar spacer item. templateNode = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "toolbarspacer"); templateNode.id = "spacer"; templateNode.flex = 1; wrapPaletteItem(templateNode, currentRows[0], null); var rowSlots = new Array(4); rowSlots[0] = 3; for (i =1 ;i < 4; i++) { rowSlots[i] = 0; } // var rowSlot = 3; var currentItems = getCurrentItemIds(); templateNode = gToolbox.palette.firstChild; while (templateNode) { // Check if the item is already in a toolbar before adding it to the palette. // JMC - If it's duplicatable, add it anyways var bCanDuplicate = templateNode.getAttribute("allowDuplicate"); if (!(templateNode.id in currentItems) || bCanDuplicate) { var paletteItem = templateNode.cloneNode(true); var paletteIndex = 0; // JMC - pick a tab for this item switch (paletteItem.getAttribute("toolgroup")) { case "functional": paletteIndex = 2; break; case "personal": paletteIndex = 1; break; case "headline": paletteIndex = 3; break; case "navigation": default: paletteIndex = 0; } if (rowSlots[paletteIndex] == rowLimits[paletteIndex]) { // Append the old row. paletteBoxes[paletteIndex].appendChild(currentRows[paletteIndex]); // Make a new row. currentRows[paletteIndex] = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "row"); currentRows[paletteIndex].setAttribute("class", "paletteRow"); rowSlots[paletteIndex] = 0; } ++rowSlots[paletteIndex]; wrapPaletteItem(paletteItem, currentRows[paletteIndex], null); } templateNode = templateNode.nextSibling; } for (i = 0; i < 4; i++) { if (currentRows[i]) { // fillRowWithFlex(currentRows[i]); paletteBoxes[i].appendChild(currentRows[i]); } } } /** * Creates a new palette item for a cloned template node and * adds it to the last slot in the palette. */ function appendPaletteItem(aItem) { // JMC Changes to place item back on the right palette var paletteIndex = 0; switch (aItem.getAttribute("toolgroup")) { case "functional": paletteIndex = 2; break; case "personal": paletteIndex = 1; break; case "headline": paletteIndex = 3; break; case "navigation": default: paletteIndex = 0; } var paletteBoxes = new Array(4); paletteBoxes[0] = document.getElementById("palette-box-grid"); paletteBoxes[1] = document.getElementById("personal-palette-box-grid"); paletteBoxes[2] = document.getElementById("functional-palette-box-grid"); paletteBoxes[3] = document.getElementById("headline-palette-box-grid"); var paletteBox = paletteBoxes[paletteIndex]; var lastRow = paletteBox.lastChild; if (!lastRow || lastRow.childNodes.length == rowLimits[paletteIndex]) { lastRow = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "row"); lastRow.setAttribute("class", "paletteRow"); paletteBox.appendChild(lastRow); } wrapPaletteItem(aItem, lastRow, null); // fillRowWithFlex(lastRow); } function fillRowWithFlex(aRow) { var remainingFlex = kRowMax - aRow.childNodes.length; if (remainingFlex > 0) { var spacer = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "spacer"); spacer.setAttribute("flex", remainingFlex); aRow.appendChild(spacer); } } /** * Makes sure that an item that has been cloned from a template * is stripped of all properties that may adversely affect it's * appearance in the palette. */ function cleanUpItemForPalette(aItem, aWrapper) { aWrapper.setAttribute("place", "palette"); setWrapperType(aItem, aWrapper); if (aItem.hasAttribute("title")) aWrapper.setAttribute("title", aItem.getAttribute("title")); else if (isSpecialItem(aItem)) { var stringBundle = document.getElementById("stringBundle"); var title = stringBundle.getString(aItem.id + "Title"); aWrapper.setAttribute("title", title); } // Remove attributes that screw up our appearance. aItem.removeAttribute("command"); aItem.removeAttribute("observes"); aItem.removeAttribute("disabled"); aItem.removeAttribute("type"); if (aItem.localName == "toolbaritem" && aItem.firstChild) { aItem.firstChild.removeAttribute("observes"); // So the throbber doesn't throb in the dialog, // cute as that may be... aItem.firstChild.removeAttribute("busy"); } } /** * Makes sure that an item that has been cloned from a template * is stripped of all properties that may adversely affect it's * appearance in the toolbar. Store critical properties on the * wrapper so they can be put back on the item when we're done. */ function cleanupItemForToolbar(aItem, aWrapper) { setWrapperType(aItem, aWrapper); aWrapper.setAttribute("place", "toolbar"); if (aItem.hasAttribute("command")) { aWrapper.setAttribute("itemcommand", aItem.getAttribute("command")); aItem.removeAttribute("command"); } if (aItem.hasAttribute("state")) { aWrapper.setAttribute("itemstate", aItem.getAttribute("state")); aItem.removeAttribute("state"); } if (aItem.disabled) { aWrapper.setAttribute("itemdisabled", "true"); aItem.disabled = false; } } function setWrapperType(aItem, aWrapper) { if (aItem.localName == "toolbarseparator") { aWrapper.setAttribute("type", "separator"); } else if (aItem.localName == "toolbarspring") { aWrapper.setAttribute("type", "spring"); } else if (aItem.localName == "toolbarspacer") { aWrapper.setAttribute("type", "spacer"); } else if (aItem.localName == "toolbaritem" && aItem.firstChild) { aWrapper.setAttribute("type", aItem.firstChild.localName); } } function setDragActive(aItem, aValue) { var node = aItem; var value = "left"; if (aItem.localName == "toolbar" || aItem.localName == "multibartray" || aItem.localName == "multibar") { //JMC: Try this? node = aItem.lastChild; value = "right"; } if (!node) return; if (aValue) { if (!node.hasAttribute("dragover")) node.setAttribute("dragover", value); } else { node.removeAttribute("dragover"); } } function getPersonalBar() { for (var i = 0; i < gToolbox.childNodes.length; ++i) { var toolbar = getToolbarAt(i); if (isCustomizableToolbar(toolbar) && toolbar.id == "PersonalToolbar") { return toolbar; } } } function addNewTray() { dump ("\nCUSTOMIZE: AddnewTray() \n\n"); /* var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(Components.interfaces.nsIPromptService); var stringBundle = document.getElementById("stringBundle"); var message = stringBundle.getString("enterToolbarName"); var title = stringBundle.getString("enterToolbarTitle"); var name = {}; while (true) { if (!promptService.prompt(window, title, message, name, null, {})) return; var dupeFound = false; // Check for an existing tray with the same display name for (i = 0; i < gSelectedToolbar.childNodes.length; ++i) { var toolbar = gSelectedToolbar.childNodes[i]; var toolbarName = toolbar.getAttribute("toolbarname"); if (toolbarName == name.value && toolbar.getAttribute("type") != "menubar") { dupeFound = true; break; } } if (!dupeFound) break; message = stringBundle.getFormattedString("enterToolbarDup", [name.value]); } var toolbar; var treeItem; if (gSelectedToolbar.localName == 'multibartray') { toolbar = gSelectedToolbar.parentNode.addNewTray(name.value); } else { // JMC: multibar toolbar = gSelectedToolbar.addNewTray(name.value); } // toolbar.setAttribute("currentSet", "spring"); toolbar.parentNode.parentNode.reorderToolbars(); */ var multibar; if (gSelectedToolbar.localName == 'multibartray') { multibar = gSelectedToolbar.parentNode; } else { // JMC: multibar multibar = gSelectedToolbar; } var oldCount = multibar.mTrays.length; window.openDialog("chrome://global/content/addRenameTrayDialog.xul", "addRenameTrayDialog", "centerscreen,modal=yes", 'add', multibar); if (oldCount < multibar.mTrays.length) { gSelectedToolbar = multibar.currentTray; populateTree(); toolTree.view.selection.select(toolTree.contentView.getIndexOfItem(getTreeItem(gSelectedToolbar))); updateToolbarSelected(); repositionDialog(); gToolboxChanged = true; } } function addNewToolbar(bMultibar) { var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(Components.interfaces.nsIPromptService); var stringBundle = document.getElementById("stringBundle"); if (bMultibar) { var message = stringBundle.getString("enterMultibarName"); var title = stringBundle.getString("enterMultibarTitle"); } else { var message = stringBundle.getString("enterToolbarName"); var title = stringBundle.getString("enterToolbarTitle"); } var name = {}; while (true) { if (!promptService.prompt(window, title, message, name, null, {})) { return; } else if(!name.value) { continue; } else { var allSpace = true; for(var j = 0; j < name.value.length; j++) { if(name.value.charAt(j) != ' ') { allSpace = false; break; } } if(allSpace) { name.value = ''; continue; } } var dupeFound = false; for (i = 0; i < gToolbox.childNodes.length; ++i) { var toolbar = gToolbox.childNodes[i]; var toolbarName = toolbar.getAttribute("toolbarname"); if (toolbarName == name.value && toolbar.getAttribute("type") != "menubar") { dupeFound = true; break; } } if (!dupeFound) break; message = stringBundle.getFormattedString("enterToolbarDup", [name.value]); } var toolbar; if (bMultibar) { toolbar = gToolbox.appendCustomMultibar(name.value, "first:__empty"); toolbar.parentNode.reorderToolbars(); } else { toolbar = gToolbox.appendCustomToolbar(name.value, "__empty"); toolbar.parentNode.reorderToolbars(); } gSelectedToolbar = toolbar; copyPersonalModes(gSelectedToolbar); populateTree(); toolTree.view.selection.select(toolTree.contentView.getIndexOfItem(getTreeItem(gSelectedToolbar))); updateToolbarSelected(); repositionDialog(); gToolboxChanged = true; } function copyPersonalModes(modeTarget) { var personalbar = getPersonalBar(); if (modeTarget.localName == 'multibartray') { modeTarget = modeTarget.parentNode; } modeTarget.setAttribute("mode", personalbar.getAttribute("mode")); modeTarget.setAttribute("iconsize", personalbar.getAttribute("iconsize")); modeTarget.setAttribute("smallicons", personalbar.getAttribute("smallicons")); } function getTreeItem(aToolbar) { var treeItems = toolTree.getElementsByTagName('treeitem'); for (var i = 0; i < treeItems.length; i++) { var treeItem = treeItems.item(i); if (treeItem.getAttribute("toolbarId") == aToolbar.id) { return treeItem; } } return treeItems.item(0); // JMC: Kind of ugly } function addNewMulti() { addNewToolbar(true); } // return -1 if cannot remove function removeToolbar(bReentrant, bForce) { dump ("Removing current toolbar, id : " + gSelectedToolbar.id + "\n\n"); // Sanity checks - can't remove personal or navigation toolbars if (gSelectedToolbar.id == "nav-bar" || gSelectedToolbar.id == "PersonalToolbar") { return -1; } var bCanDelete = true; var toolbarChild = gSelectedToolbar.firstChild; /* while (toolbarChild) { dump ("Scanning toolbar children, this ones called : " + toolbarChild.id + "\n"); var itemId = toolbarChild.id.substring(8,toolbarChild.id.length); if (itemId == "search-container") { // Not allowed to delete searchbox if (!bForce) { bCanDelete = false; } break; } toolbarChild = toolbarChild.nextSibling; } */ if (!bCanDelete || (gSelectedToolbar.localName == 'multibartray' && !bForce && !gSelectedToolbar.parentNode.checkDelete(gSelectedToolbar.parentNode.getIndexOfTray(gSelectedToolbar)))) { if (!bCanDelete) { // Unable to remove because of the search bar var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService); var stringBundle = document.getElementById("stringBundle"); var title = stringBundle.getString("toolbarRemoveTitle"); var message = stringBundle.getString("toolbarRemoveMessage"); promptService.alert(window, title, message); } return -1; } // If it's a multibar, recurse through all the trays if (gSelectedToolbar.localName == 'multibar') { dump ("This is a multibar, gonna recurse for children...\n"); var oldSelected = gSelectedToolbar; toolbarChild = gSelectedToolbar.firstChild; while (toolbarChild) { if (toolbarChild.localName == 'multibartray') { gSelectedToolbar = toolbarChild; if(removeToolbar(true, bForce) == -1) { return -1; } gSelectedToolbar = oldSelected; } toolbarChild = gSelectedToolbar.firstChild;; } // Now sanity check again to make sure there's no trays left if (gSelectedToolbar.childNodes.length > 0) return; } toolbarChild = gSelectedToolbar.firstChild; while (toolbarChild) { dump ("Removing existing toolbar items : " + toolbarChild.id + "\n"); var itemId = toolbarChild.id.substring(8,toolbarChild.id.length); dump ("Item id is : " + itemId + "\n"); // var wrapper = gToolboxDocument.getElementById("wrapper-"+itemId); var wrapper = toolbarChild; toolbarChild = toolbarChild.nextSibling; if (wrapper) { // if (itemId == "search-container") continue; // Don't ever put this back on the palette // Don't allow static kids (e.g., the menubar) to move. if (wrapper.parentNode.firstPermanentChild && wrapper.parentNode.firstPermanentChild.id == wrapper.firstChild.id) continue; if (wrapper.parentNode.lastPermanentChild && wrapper.parentNode.lastPermanentChild.id == wrapper.firstChild.id) continue; // The item was dragged out of the toolbar. wrapper.parentNode.removeChild(wrapper); var wrapperType = wrapper.getAttribute("type"); if (wrapperType != "separator" && wrapperType != "spacer" && wrapperType != "spring") { // Find the template node in the toolbox palette var templateNode = gToolbox.palette.firstChild; while (templateNode) { if (templateNode.id == itemId) break; templateNode = templateNode.nextSibling; } if (!templateNode) continue; // Clone the template and add it to our palette. var paletteItem = templateNode.cloneNode(true); appendPaletteItem(paletteItem); } } } gToolboxChanged = true; var customCount = gSelectedToolbar.getAttribute('customindex'); dump ("CUSTOMIZE: deleteing toolbar with customindex of " + customCount + "\n"); if (gSelectedToolbar.localName == 'multibartray') { gSelectedToolbar.parentNode.deleteTrayByObj(gSelectedToolbar, true); // Force delete } else { if (gSelectedToolbar.localName == 'multibar') { gToolbox.toolbarset.removeAttribute("multibar"+customCount); gToolboxDocument.persist(gToolbox.toolbarset.id, "multibar"+customCount); gToolbox.toolbarset.removeAttribute("multibarselected"+customCount); gToolboxDocument.persist(gToolbox.toolbarset.id, "multibarselected"+customCount); gToolbox.toolbarset.removeAttribute("multibarshowtitle"+customCount); gToolboxDocument.persist(gToolbox.toolbarset.id, "multibarshowtitle"+customCount); } else { gToolbox.toolbarset.removeAttribute("toolbar"+customCount); gToolboxDocument.persist(gToolbox.toolbarset.id, "toolbar"+customCount); } gToolbox.removeToolbar(gSelectedToolbar); } var treeParent = document.getElementById("toolbarItemParent"); var toolChild = treeParent.firstChild; while (toolChild) { if (toolChild.getAttribute('toolbarId') == gSelectedToolbar.id) { treeParent.removeChild(toolChild); break; } toolChild = toolChild.nextSibling; } if (!bReentrant) { populateTree(); repositionDialog(); toolTree.view.selection.select(1); updateToolbarSelected(); } } function addToolbarMenuItem(aToolbar, attachPoint) { var toolbarName = aToolbar.getAttribute("toolbarname"); // Make a new menu item var newTreeItem = document.createElement("treeitem"); var newTreeRow = document.createElement("treerow"); var newTreeCell = document.createElement("treecell"); newTreeCell.setAttribute("label", toolbarName); newTreeItem.setAttribute("toolbarId", aToolbar.id); // Append the new item newTreeRow.appendChild(newTreeCell); newTreeItem.appendChild(newTreeRow); if (attachPoint) { attachPoint.appendChild(newTreeItem); } else { document.getElementById("toolbarItemParent").appendChild(newTreeItem); } return newTreeItem; } /** * Restore the default set of buttons to fixed toolbars, * remove all custom toolbars, and rebuild the palette. */ function restoreDefaultSet() { // Save disabled/command states, because we're // going to recreate the wrappers and lose this var savedAttributes = saveItemAttributes(["itemdisabled", "itemcommand"]); // Restore the defaultset for fixed toolbars. var toolbar = gToolbox.firstChild; while (toolbar) { if (isCustomizableToolbar(toolbar)) { if (!toolbar.hasAttribute("customindex")) { var defaultSet = toolbar.getAttribute("defaultset"); if (defaultSet) { toolbar.currentSet = defaultSet; if (toolbar.localName == 'multibar') { gToolbox.toolbarset.removeAttribute('showsearch'); gToolboxDocument.persist(gToolbox.toolbarset.id, 'showsearch'); toolbar.showTray(0); // gToolboxDocument.defaultView.resizeSearchBar(); } else { toolbar.setAttribute('currentset', defaultSet); gToolboxDocument.persist(toolbar.id, 'currentset'); } setAttribute(toolbar, "mode", toolbar.getAttribute('default_mode')); gToolboxDocument.persist(toolbar.id, "mode"); setAttribute(toolbar, "iconsize", toolbar.getAttribute('default_iconsize')); gToolboxDocument.persist(toolbar.id, "iconsize"); setAttribute(toolbar, "iconsize", toolbar.getAttribute('default_iconsize')); gToolboxDocument.persist(toolbar.id, "iconsize"); setAttribute(toolbar, "toolbarname", toolbar.getAttribute('default_toolbarname')); gToolboxDocument.persist(toolbar.id, "toolbarname"); toolbar.removeAttribute("collapsed"); gToolboxDocument.persist(toolbar.id, "collapsed"); } } } toolbar = toolbar.nextSibling; } /* // Restore the default icon size (large) and mode (icons only). updateIconSize(false); document.getElementById("smallicons").checked = false; updateToolbarMode("icons"); document.getElementById("modelist").value = "icons"; */ // JMC : Todo - reset default mode and icon sizes on all toolbars // Remove all of the customized toolbars. var child = gToolbox.lastChild; while (child) { if (child.hasAttribute("customindex")) { var thisChild = child; child = child.previousSibling; gSelectedToolbar = thisChild; removeToolbar(false, true); // force removal of search container } else { child = child.previousSibling; } } // Reset toolbarorder to default gToolbox.toolbarset.setAttribute("toolbarorder", gToolbox.toolbarset.getAttribute("defaulttoolbarorder")); // And reorder toolbars gToolbox.reorderToolbars(); // Now rebuild the palette. buildPalette(); // Now re-wrap the items on the toolbar. wrapToolbarItems(); // Restore the disabled and command states restoreItemAttributes(["itemdisabled", "itemcommand"], savedAttributes); populateTree(); repositionDialog(); gToolboxChanged = true; toolTree.view.selection.select(1); updateToolbarSelected(); } function saveItemAttributes(aAttributeList) { var items = []; var paletteItems = gToolbox.getElementsByTagName("toolbarpaletteitem"); for (var i = 0; i < paletteItems.length; i++) { var paletteItem = paletteItems.item(i); for (var j = 0; j < aAttributeList.length; j++) { var attr = aAttributeList[j]; if (paletteItem.hasAttribute(attr)) { items.push([paletteItem.id, attr, paletteItem.getAttribute(attr)]); } } } return items; } function restoreItemAttributes(aAttributeList, aSavedAttrList) { var paletteItems = gToolbox.getElementsByTagName("toolbarpaletteitem"); for (var i = 0; i < paletteItems.length; i++) { var paletteItem = paletteItems.item(i); // if the item is supposed to have this, it'll get // restored from the saved list for (var j = 0; j < aAttributeList.length; j++) paletteItem.removeAttribute(aAttributeList[j]); for (var j = 0; j < aSavedAttrList.length; j++) { var savedAttr = aSavedAttrList[j]; if (paletteItem.id == savedAttr[0]) { paletteItem.setAttribute(savedAttr[1], savedAttr[2]); } } } } function updateToolbarSelected() { var toolbarIndex = toolTree.currentIndex; if ((toolbarIndex > -1) && (!gRepopulating)) { var selectedTreeItem = toolTree.contentView.getItemAtIndex(toolbarIndex); dump("The selected tree Item is " + selectedTreeItem.getAttribute('toolbarId') + "\n"); gSelectedToolbar = gToolboxDocument.getElementById(selectedTreeItem.getAttribute('toolbarId')); document.getElementById("toolbarname").value = gSelectedToolbar.getAttribute('toolbarname'); document.getElementById("settingsBoxCaption").label = gSelectedToolbar.getAttribute('toolbarname') + " Settings"; // var smallIconsCheckbox = document.getElementById("smallicons"); var iconSize = "small"; // if it's multibartray, can't change mode values // But show them for the parent multibar anyway if (gSelectedToolbar.localName == 'multibartray') { var mode = gSelectedToolbar.parentNode.getAttribute("mode"); gToolboxIconSize = gSelectedToolbar.parentNode.getAttribute("iconsize"); if (gToolboxIconSize != "small") { iconSize = "large"; } // smallIconsCheckbox.checked = gToolboxIconSize == "small"; // smallIconsCheckbox.disabled = true; document.getElementById("modelist").disabled = true; // document.getElementById("smallicons").disabled = true; // document.getElementById("newMultiButton").label = "New Tray"; // document.getElementById("newMultiButton").setAttribute('oncommand','addNewTray()'); document.getElementById('newTrayButton').disabled = false; gSelectedToolbar.parentNode.showTrayByObj(gSelectedToolbar); if (gSelectedToolbar.parentNode.childNodes.length < 2) { document.getElementById("removeButton").disabled = true; } else { document.getElementById("removeButton").disabled = false; } } else { var mode = gSelectedToolbar.getAttribute("mode"); gToolboxIconSize = gSelectedToolbar.getAttribute("iconsize"); document.getElementById("modelist").disabled = false; /* smallIconsCheckbox.disabled = false; if (mode == "text") { smallIconsCheckbox.disabled = true; } else { smallIconsCheckbox.checked = gToolboxIconSize == "small"; } */ if (gToolboxIconSize != "small") { iconSize = "large"; } if (gSelectedToolbar.localName == 'multibar') { // Change new button to make new tray document.getElementById('newTrayButton').disabled = false; if (gSelectedToolbar.id == 'PersonalToolbar') { document.getElementById("removeButton").disabled = true; } else { document.getElementById("removeButton").disabled = false; } } else { document.getElementById('newTrayButton').disabled = true; if (gSelectedToolbar.id == 'nav-bar') { document.getElementById("removeButton").disabled = true; } else { document.getElementById("removeButton").disabled = false; } } } document.getElementById("modelist").value = mode + "-" + iconSize; } else if (!gRepopulating) { toolTree.view.selection.select(0); } else { // disable everything? } } function updateIconSize(aUseSmallIcons) { // gToolboxIconSize = aUseSmallIcons ? "small" : "large"; dump("useSmallIcons is " + aUseSmallIcons + "\n\n"); gToolboxIconSize = aUseSmallIcons; if (isCustomizableToolbar(gSelectedToolbar)) { if (gSelectedToolbar.localName == 'multibartray') { setAttribute(gSelectedToolbar.parentNode, "iconsize", gToolboxIconSize); gToolboxDocument.persist(gSelectedToolbar.parentNode.id, "iconsize"); } else { setAttribute(gSelectedToolbar, "iconsize", gToolboxIconSize); gToolboxDocument.persist(gSelectedToolbar.id, "iconsize"); } } gToolboxChanged = true; repositionDialog(); } function updateToolbarMode(aModeValue) { if (isCustomizableToolbar(gSelectedToolbar)) { if (gSelectedToolbar.localName == 'multibartray') { setAttribute(gSelectedToolbar.parentNode, "mode", aModeValue); gToolboxDocument.persist(gSelectedToolbar.parentNode.id, "mode"); } else { setAttribute(gSelectedToolbar, "mode", aModeValue); gToolboxDocument.persist(gSelectedToolbar.id, "mode"); } } gToolboxChanged = true; updateToolbarSelected(); repositionDialog(); } function setAttribute(aElt, aAttr, aVal) { if (aVal) aElt.setAttribute(aAttr, aVal); else aElt.removeAttribute(aAttr); } function isCustomizableToolbar(aElt) { return aElt && (aElt.localName == "toolbar" || aElt.localName == "multibar" || aElt.localName == "multibartray") && aElt.getAttribute("customizable") == "true"; } function isSpecialItem(aElt) { return aElt.localName == "toolbarseparator" || aElt.localName == "toolbarspring" || aElt.localName == "toolbarspacer"; } function isToolbarItem(aElt) { return aElt.localName == "toolbarbutton" || aElt.localName == "toolbaritem" || aElt.localName == "toolbarseparator" || aElt.localName == "toolbarspring" || aElt.localName == "toolbarspacer"; } /////////////////////////////////////////////////////////////////////////// //// Drag and Drop observers function onToolbarDragGesture(aEvent) { nsDragAndDrop.startDrag(aEvent, dragStartObserver); } function onToolbarDragOver(aEvent) { nsDragAndDrop.dragOver(aEvent, toolbarDNDObserver); } function onToolbarDragDrop(aEvent) { nsDragAndDrop.drop(aEvent, toolbarDNDObserver); } function onToolbarDragExit(aEvent) { if (gCurrentDragOverItem) setDragActive(gCurrentDragOverItem, false); } var dragStartObserver = { onDragStart : function (aEvent, aXferData, aDragAction) { dump("CUSTOMIZE: In drag Start\n"); var documentId = gToolboxDocument.documentElement.id; var item = aEvent.target; while (item && item.localName != "toolbarpaletteitem"){ dump("Looking at item : " + item.id + "\n"); item = item.parentNode; } item.setAttribute("dragactive", "true"); dump("CUSTOMIZE: item is : " + item + "\n"); aXferData.data = new TransferDataSet(); var data = new TransferData(); data.addDataForFlavour("text/toolbarwrapper-id/"+documentId, item.firstChild.id); aXferData.data.push(data); aDragAction.action = Components.interfaces.nsIDragService.DRAGDROP_ACTION_MOVE; } } var toolbarDNDObserver = { onDragOver: function (aEvent, aFlavour, aDragSession) { var toolbar = aEvent.target; var dropTarget = aEvent.target; while (toolbar && (toolbar.localName != "toolbar" && toolbar.localName != "multibartray")) { dropTarget = toolbar; toolbar = toolbar.parentNode; } var previousDragItem = gCurrentDragOverItem; // Make sure we are dragging over a customizable toolbar. if (!isCustomizableToolbar(toolbar)) { gCurrentDragOverItem = null; return; } if (dropTarget.localName == "toolbar" || dropTarget.localName == "multibartray") { gCurrentDragOverItem = dropTarget; } else { var dropTargetWidth = dropTarget.boxObject.width; var dropTargetX = dropTarget.boxObject.x; gCurrentDragOverItem = null; if (aEvent.clientX > (dropTargetX + (dropTargetWidth / 2))) { gCurrentDragOverItem = dropTarget.nextSibling; if (!gCurrentDragOverItem) gCurrentDragOverItem = toolbar; } else gCurrentDragOverItem = dropTarget; } if (previousDragItem && gCurrentDragOverItem != previousDragItem) { setDragActive(previousDragItem, false); } setDragActive(gCurrentDragOverItem, true); aDragSession.canDrop = true; }, onDrop: function (aEvent, aXferData, aDragSession) { if (!gCurrentDragOverItem) return; setDragActive(gCurrentDragOverItem, false); var draggedItemId = aXferData.data; if (gCurrentDragOverItem.id == draggedItemId) return; var toolbar = aEvent.target; while (toolbar && toolbar.localName != "toolbar" && toolbar.localName != "multibartray") toolbar = toolbar.parentNode; var draggedPaletteWrapper = document.getElementById("wrapper-"+draggedItemId); if (!draggedPaletteWrapper) { // The wrapper has been dragged from the toolbar. // Get the wrapper from the toolbar document and make sure that // it isn't being dropped on itself. var wrapper = gToolboxDocument.getElementById("wrapper-"+draggedItemId); if (wrapper == gCurrentDragOverItem) return; // Don't allow static kids (e.g., the menubar) to move. if (wrapper.parentNode.firstPermanentChild && wrapper.parentNode.firstPermanentChild.id == wrapper.firstChild.id) return; if (wrapper.parentNode.lastPermanentChild && wrapper.parentNode.lastPermanentChild.id == wrapper.firstChild.id) return; // Remove the item from it's place in the toolbar. var oldToolbar = wrapper.parentNode; wrapper.parentNode.removeChild(wrapper); // Determine which toolbar we are dropping on. var dropToolbar = null; dump ("CUSTOMIZE: currentDragOverItem is : " + gCurrentDragOverItem.id + "\n"); if (gCurrentDragOverItem.localName == 'multibar') { dropToolbar = gCurrentDragOverItem.firstChild; // JMC - BORK! This will always drop to the first tray, not quite right I think } else { dropToolbar = gCurrentDragOverItem; } while (dropToolbar && dropToolbar.localName != "toolbar" && dropToolbar.localName != "multibartray") { dropToolbar = dropToolbar.parentNode; } if (!dropToolbar) return; dump ("dropping === Compare dropToolbar (" + dropToolbar.id + ") with toolbar (" + toolbar.id + ")\t\t"); // JMC: Searchbar container dropped onto multibar = dump ("Dropping onto a : " + dropToolbar.localName + " called " + dropToolbar.getAttribute('toolbarname') + "\n"); // Insert the item into the toolbar. if (gCurrentDragOverItem != dropToolbar) { dump ("Finally! Inserting the wrapper " + wrapper.id + " before " + gCurrentDragOverItem.id + "\t\t\t"); dropToolbar.insertBefore(wrapper, gCurrentDragOverItem); gToolboxDocument.defaultView.XULBrowserWindow.init(); } else { dropToolbar.appendChild(wrapper); } } else { // The item has been dragged from the palette // Create a new wrapper for the item. We don't know the id yet. var wrapper = createWrapper(""); // Ask the toolbar to clone the item's template, place it inside the wrapper, and insert it in the toolbar. dump("\n\n ++++++++ Inserting new item to toolbar from palette, item is " + draggedPaletteWrapper.id + ", inserting before " + gCurrentDragOverItem.id); var newItem = toolbar.insertItem(draggedItemId, gCurrentDragOverItem == toolbar ? null : gCurrentDragOverItem, wrapper); //CC MERC bug # 173797 //Nedd to notify webmail before inserting an item //of the type wrappper-webmail-toolbaritem-accountname (where accountname could be hotmail,gmail and ...) //So we can the turn on the dispaly separately pref in the email manager var mObserver = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService); mObserver.notifyObservers(null, "webmail-toolbaritem-add", draggedPaletteWrapper.id ); // Prepare the item and wrapper to look good on the toolbar. cleanupItemForToolbar(newItem, wrapper); wrapper.id = "wrapper-"+newItem.id; wrapper.flex = newItem.flex; // Remove the wrapper from the palette. // JMC, *IF* it's non-duplicateable var bCanDuplicate = newItem.getAttribute('allowDuplicate'); var currentRow = draggedPaletteWrapper.parentNode; if (draggedItemId != "separator" && draggedItemId != "spring" && draggedItemId != "spacer" && !bCanDuplicate) { currentRow.removeChild(draggedPaletteWrapper); while (currentRow) { // Pull the first child of the next row up // into this row. var nextRow = currentRow.nextSibling; if (!nextRow) { var last = currentRow.lastChild; var first = currentRow.firstChild; if (!first) { // Kill the row. currentRow.parentNode.removeChild(currentRow); // currentRow = null; break; } /* if (last.localName == "spacer") { var flex = last.getAttribute("flex"); last.setAttribute("flex", ++flex); // Reflow doesn't happen for some reason. Trigger it with a hide/show. ICK! -dwh last.hidden = true; last.hidden = false; break; } else { // Make a spacer and give it a flex of 1. var spacer = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul", "spacer"); spacer.setAttribute("flex", "1"); currentRow.appendChild(spacer); } */ } else if (!nextRow.firstChild) { currentRow.parentNode.removeChild(nextRow); break; } if (nextRow) { currentRow.appendChild(nextRow.firstChild); } currentRow = currentRow.nextSibling; } } } gCurrentDragOverItem = null; repositionDialog(); gToolboxChanged = true; }, _flavourSet: null, getSupportedFlavours: function () { if (!this._flavourSet) { this._flavourSet = new FlavourSet(); var documentId = gToolboxDocument.documentElement.id; this._flavourSet.appendFlavour("text/toolbarwrapper-id/"+documentId); } return this._flavourSet; } } var paletteDNDObserver = { onDragOver: function (aEvent, aFlavour, aDragSession) { aDragSession.canDrop = true; }, onDrop: function(aEvent, aXferData, aDragSession) { var itemId = aXferData.data; //CC MERC bug # 173797 //Nedd to notify webmail before removing an item //of the type wrappper-webmail-toolbaritem-accountname (where accountname could be hotmail,gmail and ...) //So we can the turn on the dispaly separately pref in the email manager var mObserver = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService); mObserver.notifyObservers(null, "webmail-toolbaritem-drop", itemId); dump("\n TOOLBAR: Dropping a : " + itemId + "\n"); var wrapper = gToolboxDocument.getElementById("wrapper-"+itemId); if (wrapper) { // Don't allow static kids (e.g., the menubar) to move. if (wrapper.parentNode.firstPermanentChild && wrapper.parentNode.firstPermanentChild.id == wrapper.firstChild.id) return; if (wrapper.parentNode.lastPermanentChild && wrapper.parentNode.lastPermanentChild.id == wrapper.firstChild.id) return; // Never remove searchbox // if (itemId == 'search-container') // return; // The item was dragged out of the toolbar. wrapper.parentNode.removeChild(wrapper); var wrapperType = wrapper.getAttribute("type"); if (wrapperType != "separator" && wrapperType != "spacer" && wrapperType != "spring") { // Find the template node in the toolbox palette var templateNode = gToolbox.palette.firstChild; while (templateNode) { if (templateNode.id == itemId) break; templateNode = templateNode.nextSibling; } if (templateNode) { // Clone the template and add it to our palette. var paletteItem = templateNode.cloneNode(true); appendPaletteItem(paletteItem); var panelIndex = 0; switch (templateNode.getAttribute("toolgroup")) { case "functional": panelIndex = 3; break; case "headline": panelIndex = 1; break; case "personal": panelIndex = 0; break; case "navigation": default: panelIndex = 2; break; } } else { // MERC (DP): SPUI items being dropped // we only want the wrapper ID tmpArry = wrapper.id.split('|'); var wrapperID = tmpArry[0]; if(tmpArry.length > 1 && !isNaN(tmpArry[tmpArry.length-1]) && parseInt(tmpArry[tmpArry.length-1]) > 100000) { var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService); prefService.getBranch("spui.").deleteBranch(tmpArry[tmpArry.length-1] + "."); } var panelID = document.getElementById(wrapperID).parentNode.parentNode.parentNode.parentNode.id; var panelIndex = 0; switch(panelID) { case 'headlinetab': panelIndex = 1; break; case 'navigationaltab': panelIndex = 2; break; case 'functionaltab': panelIndex = 3; break; case 'personaltab': default: panelIndex = 0; break; } } // MERC (DP): focus the tab panel that the toolbar item belongs to document.getElementById("palette-tab-box").selectedIndex = panelIndex; } else { // MERC (DP): if we are in this segment it means we have dragged one of the // following items off the toolbar: separator, spacer, spring // focus the navigational panel document.getElementById("palette-tab-box").selectedIndex = 2; } } repositionDialog(); gToolboxChanged = true; }, _flavourSet: null, getSupportedFlavours: function () { if (!this._flavourSet) { this._flavourSet = new FlavourSet(); var documentId = gToolboxDocument.documentElement.id; this._flavourSet.appendFlavour("text/toolbarwrapper-id/"+documentId); } return this._flavourSet; } } // Operates on currently selected Toolbar function moveToolbarUp() { gToolbox.moveToolbarUp(gSelectedToolbar); gToolboxChanged = true; populateTree(); toolTree.view.selection.select(toolTree.contentView.getIndexOfItem(getTreeItem(gSelectedToolbar))); // toolTree.view.selection.select(1); // updateToolbarSelected(); } function moveToolbarDown() { gToolbox.moveToolbarDown(gSelectedToolbar); gToolboxChanged = true; populateTree(); toolTree.view.selection.select(toolTree.contentView.getIndexOfItem(getTreeItem(gSelectedToolbar))); // toolTree.view.selection.select(1); // updateToolbarSelected(); } var treeDragObserver = { onDragStart: function (evt, transferData, action){ var txt=evt.target.getAttribute("toolbarId"); transferData.data=new TransferData(); transferData.data.addDataForFlavour("text/unicode",txt); }, getSupportedFlavours : function () { var flavours = new FlavourSet(); flavours.appendFlavour("text/unicode"); return flavours; }, onDrop : function (evt, transferData, session) { event.target.setAttribute("value",transferData.data); }, onDragOver: function (evt, transferData, session) {} } // MERC (DP): confirm dialog for reset all button function confirmRestoreDefaultSet() { var prefService = Components.classes["@mozilla.org/preferences-service;1"] .getService(Components.interfaces.nsIPrefBranch); if (!prefService.getBoolPref("custoolbar.restoredefault.suppressdialog")) { var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] .getService(Components.interfaces.nsIPromptService); var checkResult = {}; var result = promptService.confirmCheck(window, "Confirm Reset All", "Are you sure you wish to restore default toolbar settings?", "Don't show this message again", checkResult); if(checkResult.value) prefService.setBoolPref("custoolbar.restoredefault.suppressdialog", true); return result; } return true; }