2005-02-01 17:07:35 +00:00
|
|
|
# ***** BEGIN LICENSE BLOCK *****
|
|
|
|
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
# 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
# http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
# for the specific language governing rights and limitations under the
|
|
|
|
# License.
|
|
|
|
#
|
2002-10-11 01:27:28 +00:00
|
|
|
# The Original Code is Mozilla Communicator client code, released
|
|
|
|
# March 31, 1998.
|
2005-02-01 17:07:35 +00:00
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is
|
|
|
|
# David Hyatt.
|
|
|
|
# Portions created by the Initial Developer are Copyright (C) 2002
|
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
2002-10-11 01:27:28 +00:00
|
|
|
# David Hyatt (hyatt@apple.com)
|
|
|
|
# Blake Ross (blaker@netscape.com)
|
|
|
|
# Joe Hewitt (hewitt@netscape.com)
|
2005-02-01 17:07:35 +00:00
|
|
|
#
|
|
|
|
# Alternatively, the contents of this file may be used under the terms of
|
|
|
|
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
# in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
# of those above. If you wish to allow use of your version of this file only
|
|
|
|
# under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
# use your version of this file under the terms of the MPL, indicate your
|
|
|
|
# decision by deleting the provisions above and replace them with the notice
|
|
|
|
# and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
# the provisions above, a recipient may use your version of this file under
|
|
|
|
# the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
#
|
|
|
|
# ***** END LICENSE BLOCK *****
|
2002-09-27 04:06:56 +00:00
|
|
|
|
|
|
|
const kRowMax = 4;
|
|
|
|
|
|
|
|
var gToolboxDocument = null;
|
|
|
|
var gToolbox = null;
|
|
|
|
var gCurrentDragOverItem = null;
|
|
|
|
var gToolboxChanged = false;
|
2004-06-20 10:07:43 +00:00
|
|
|
var gToolboxIconSize = false;
|
2009-02-16 15:27:20 +00:00
|
|
|
var gToolboxSheet = false;
|
2002-09-27 04:06:56 +00:00
|
|
|
|
|
|
|
function onLoad()
|
|
|
|
{
|
2009-02-16 15:27:20 +00:00
|
|
|
if ("arguments" in window && window.arguments[0]) {
|
|
|
|
InitWithToolbox(window.arguments[0]);
|
|
|
|
repositionDialog();
|
|
|
|
}
|
|
|
|
else if (window.frameElement &&
|
|
|
|
"toolbox" in window.frameElement) {
|
|
|
|
gToolboxSheet = true;
|
|
|
|
InitWithToolbox(window.frameElement.toolbox);
|
|
|
|
}
|
2006-08-26 07:27:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function InitWithToolbox(aToolbox)
|
|
|
|
{
|
|
|
|
gToolbox = aToolbox;
|
2002-09-29 01:23:02 +00:00
|
|
|
gToolboxDocument = gToolbox.ownerDocument;
|
2008-10-18 09:57:46 +00:00
|
|
|
gToolbox.customizing = true;
|
|
|
|
|
2008-10-17 20:04:55 +00:00
|
|
|
gToolbox.addEventListener("dragstart", onToolbarDragStart, false);
|
2002-09-27 04:06:56 +00:00
|
|
|
gToolbox.addEventListener("dragover", onToolbarDragOver, false);
|
2008-10-17 20:04:55 +00:00
|
|
|
gToolbox.addEventListener("dragleave", onToolbarDragLeave, false);
|
|
|
|
gToolbox.addEventListener("drop", onToolbarDrop, false);
|
2002-09-27 04:06:56 +00:00
|
|
|
|
2004-09-29 07:08:24 +00:00
|
|
|
initDialog();
|
2009-01-16 19:19:30 +00:00
|
|
|
|
|
|
|
notifyParentInitialized();
|
2002-09-28 15:11:50 +00:00
|
|
|
}
|
|
|
|
|
2009-02-16 15:27:20 +00:00
|
|
|
function onClose()
|
|
|
|
{
|
|
|
|
if (!gToolboxSheet)
|
|
|
|
window.close();
|
|
|
|
else
|
|
|
|
finishToolbarCustomization();
|
|
|
|
}
|
|
|
|
|
|
|
|
function onUnload()
|
|
|
|
{
|
|
|
|
if (!gToolboxSheet)
|
|
|
|
finishToolbarCustomization();
|
|
|
|
}
|
|
|
|
|
2006-08-26 07:27:54 +00:00
|
|
|
function finishToolbarCustomization()
|
2002-10-01 23:10:54 +00:00
|
|
|
{
|
|
|
|
removeToolboxListeners();
|
|
|
|
unwrapToolbarItems();
|
|
|
|
persistCurrentSets();
|
2009-06-13 06:03:02 +00:00
|
|
|
gToolbox.customizing = false;
|
2002-10-01 23:10:54 +00:00
|
|
|
|
|
|
|
notifyParentComplete();
|
|
|
|
}
|
|
|
|
|
2002-09-28 15:11:50 +00:00
|
|
|
function initDialog()
|
|
|
|
{
|
2002-09-27 04:06:56 +00:00
|
|
|
var mode = gToolbox.getAttribute("mode");
|
|
|
|
document.getElementById("modelist").value = mode;
|
2004-06-20 10:07:43 +00:00
|
|
|
gToolboxIconSize = gToolbox.getAttribute("iconsize");
|
2002-09-29 18:25:42 +00:00
|
|
|
var smallIconsCheckbox = document.getElementById("smallicons");
|
2006-12-09 03:32:36 +00:00
|
|
|
smallIconsCheckbox.checked = gToolboxIconSize == "small";
|
2002-09-29 18:25:42 +00:00
|
|
|
if (mode == "text")
|
|
|
|
smallIconsCheckbox.disabled = true;
|
2002-09-27 04:06:56 +00:00
|
|
|
|
|
|
|
// Build up the palette of other items.
|
|
|
|
buildPalette();
|
|
|
|
|
|
|
|
// Wrap all the items on the toolbar in toolbarpaletteitems.
|
|
|
|
wrapToolbarItems();
|
|
|
|
}
|
|
|
|
|
2002-09-28 15:11:50 +00:00
|
|
|
function repositionDialog()
|
|
|
|
{
|
2004-09-29 07:08:24 +00:00
|
|
|
// Position the dialog touching the bottom of the toolbox and centered with
|
2006-05-26 12:20:51 +00:00
|
|
|
// it.
|
2006-05-29 16:18:45 +00:00
|
|
|
var width;
|
|
|
|
if (document.documentElement.hasAttribute("width"))
|
|
|
|
width = document.documentElement.getAttribute("width");
|
|
|
|
else
|
|
|
|
width = parseInt(document.documentElement.style.width);
|
2006-05-26 12:20:51 +00:00
|
|
|
var screenX = gToolbox.boxObject.screenX
|
2006-05-29 16:18:45 +00:00
|
|
|
+ ((gToolbox.boxObject.width - width) / 2);
|
2002-09-29 05:37:48 +00:00
|
|
|
var screenY = gToolbox.boxObject.screenY + gToolbox.boxObject.height;
|
2004-09-29 07:08:24 +00:00
|
|
|
|
2002-09-29 05:37:48 +00:00
|
|
|
window.moveTo(screenX, screenY);
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function removeToolboxListeners()
|
|
|
|
{
|
2008-10-17 20:04:55 +00:00
|
|
|
gToolbox.removeEventListener("dragstart", onToolbarDragStart, false);
|
2002-09-27 04:06:56 +00:00
|
|
|
gToolbox.removeEventListener("dragover", onToolbarDragOver, false);
|
2008-10-17 20:04:55 +00:00
|
|
|
gToolbox.removeEventListener("dragleave", onToolbarDragLeave, false);
|
|
|
|
gToolbox.removeEventListener("drop", onToolbarDrop, false);
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2002-09-29 01:23:02 +00:00
|
|
|
* Invoke a callback on the toolbox to notify it that the dialog is done
|
|
|
|
* and going away.
|
2002-09-27 04:06:56 +00:00
|
|
|
*/
|
|
|
|
function notifyParentComplete()
|
|
|
|
{
|
2002-09-29 01:23:02 +00:00
|
|
|
if ("customizeDone" in gToolbox)
|
|
|
|
gToolbox.customizeDone(gToolboxChanged);
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
|
|
|
|
2009-01-16 19:19:30 +00:00
|
|
|
/**
|
|
|
|
* Invoke a callback on the toolbox to notify it that the dialog is fully
|
|
|
|
* initialized.
|
|
|
|
*/
|
|
|
|
function notifyParentInitialized()
|
|
|
|
{
|
|
|
|
if ("customizeInitialized" in gToolbox)
|
|
|
|
gToolbox.customizeInitialized();
|
|
|
|
}
|
|
|
|
|
2009-01-30 22:05:44 +00:00
|
|
|
function toolboxChanged(aEvent)
|
2008-01-30 23:16:52 +00:00
|
|
|
{
|
|
|
|
gToolboxChanged = true;
|
|
|
|
if ("customizeChange" in gToolbox)
|
2009-01-30 22:05:44 +00:00
|
|
|
gToolbox.customizeChange(aEvent);
|
2008-01-30 23:16:52 +00:00
|
|
|
}
|
|
|
|
|
2002-10-20 08:03:51 +00:00
|
|
|
function getToolbarAt(i)
|
|
|
|
{
|
|
|
|
return gToolbox.childNodes[i];
|
|
|
|
}
|
|
|
|
|
2002-09-27 04:06:56 +00:00
|
|
|
/**
|
|
|
|
* Persist the current set of buttons in all customizable toolbars to
|
|
|
|
* localstore.
|
|
|
|
*/
|
|
|
|
function persistCurrentSets()
|
|
|
|
{
|
2008-04-05 00:20:38 +00:00
|
|
|
if (!gToolboxChanged || gToolboxDocument.defaultView.closed)
|
2002-09-27 04:06:56 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
var customCount = 0;
|
|
|
|
for (var i = 0; i < gToolbox.childNodes.length; ++i) {
|
|
|
|
// Look for customizable toolbars that need to be persisted.
|
2002-10-20 08:03:51 +00:00
|
|
|
var toolbar = getToolbarAt(i);
|
2002-09-27 04:06:56 +00:00
|
|
|
if (isCustomizableToolbar(toolbar)) {
|
|
|
|
// Calculate currentset and store it in the attribute.
|
|
|
|
var currentSet = toolbar.currentSet;
|
|
|
|
toolbar.setAttribute("currentset", currentSet);
|
|
|
|
|
|
|
|
var customIndex = toolbar.hasAttribute("customindex");
|
|
|
|
if (customIndex) {
|
|
|
|
if (!toolbar.firstChild) {
|
|
|
|
// Remove custom toolbars whose contents have been removed.
|
|
|
|
gToolbox.removeChild(toolbar);
|
|
|
|
--i;
|
|
|
|
} else {
|
|
|
|
// Persist custom toolbar info on the <toolbarset/>
|
|
|
|
gToolbox.toolbarset.setAttribute("toolbar"+(++customCount),
|
|
|
|
toolbar.toolbarName + ":" + currentSet);
|
|
|
|
gToolboxDocument.persist(gToolbox.toolbarset.id, "toolbar"+customCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!customIndex) {
|
|
|
|
// Persist the currentset attribute directly on hardcoded toolbars.
|
|
|
|
gToolboxDocument.persist(toolbar.id, "currentset");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove toolbarX attributes for removed toolbars.
|
|
|
|
while (gToolbox.toolbarset.hasAttribute("toolbar"+(++customCount))) {
|
|
|
|
gToolbox.toolbarset.removeAttribute("toolbar"+customCount);
|
|
|
|
gToolboxDocument.persist(gToolbox.toolbarset.id, "toolbar"+customCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wraps all items in all customizable toolbars in a toolbox.
|
|
|
|
*/
|
|
|
|
function wrapToolbarItems()
|
|
|
|
{
|
|
|
|
for (var i = 0; i < gToolbox.childNodes.length; ++i) {
|
2002-10-20 08:03:51 +00:00
|
|
|
var toolbar = getToolbarAt(i);
|
2002-09-27 04:06:56 +00:00
|
|
|
if (isCustomizableToolbar(toolbar)) {
|
|
|
|
for (var k = 0; k < toolbar.childNodes.length; ++k) {
|
|
|
|
var item = toolbar.childNodes[k];
|
2008-04-29 19:07:14 +00:00
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
if (item.firstChild && item.firstChild.localName == "menubar")
|
|
|
|
continue;
|
|
|
|
#endif
|
|
|
|
|
2002-09-27 04:06:56 +00:00
|
|
|
if (isToolbarItem(item)) {
|
|
|
|
var wrapper = wrapToolbarItem(item);
|
2007-01-31 16:13:13 +00:00
|
|
|
cleanupItemForToolbar(item, wrapper);
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unwraps all items in all customizable toolbars in a toolbox.
|
|
|
|
*/
|
|
|
|
function unwrapToolbarItems()
|
|
|
|
{
|
|
|
|
var paletteItems = gToolbox.getElementsByTagName("toolbarpaletteitem");
|
2003-02-20 02:09:27 +00:00
|
|
|
var paletteItem;
|
|
|
|
while ((paletteItem = paletteItems.item(0)) != null) {
|
2002-09-27 04:06:56 +00:00
|
|
|
var toolbarItem = paletteItem.firstChild;
|
|
|
|
|
|
|
|
if (paletteItem.hasAttribute("itemdisabled"))
|
|
|
|
toolbarItem.disabled = true;
|
|
|
|
|
2009-01-17 20:20:31 +00:00
|
|
|
if (paletteItem.hasAttribute("itemcommand")) {
|
|
|
|
let commandID = paletteItem.getAttribute("itemcommand");
|
|
|
|
toolbarItem.setAttribute("command", commandID);
|
2009-01-18 15:03:14 +00:00
|
|
|
|
|
|
|
//XXX Bug 309953 - toolbarbuttons aren't in sync with their commands after customizing
|
2009-01-17 20:20:31 +00:00
|
|
|
toolbarItem.disabled = gToolboxDocument.getElementById(commandID).disabled;
|
|
|
|
}
|
2002-09-27 04:06:56 +00:00
|
|
|
|
|
|
|
paletteItem.parentNode.replaceChild(toolbarItem, paletteItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a wrapper that can be used to contain a toolbaritem and prevent
|
|
|
|
* it from receiving UI events.
|
|
|
|
*/
|
2008-12-03 12:35:34 +00:00
|
|
|
function createWrapper(aId, aDocument)
|
2002-09-27 04:06:56 +00:00
|
|
|
{
|
2008-12-03 12:35:34 +00:00
|
|
|
var wrapper = aDocument.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
2002-09-27 04:06:56 +00:00
|
|
|
"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)
|
|
|
|
{
|
2008-12-03 12:35:34 +00:00
|
|
|
var wrapper = createWrapper(aPaletteItem.id, document);
|
2002-09-28 15:11:50 +00:00
|
|
|
|
2002-09-27 04:06:56 +00:00
|
|
|
wrapper.setAttribute("flex", 1);
|
2002-09-28 15:11:50 +00:00
|
|
|
wrapper.setAttribute("align", "center");
|
2002-09-27 04:06:56 +00:00
|
|
|
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
|
2002-09-28 15:11:50 +00:00
|
|
|
* 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.
|
2002-09-27 04:06:56 +00:00
|
|
|
*/
|
|
|
|
function wrapToolbarItem(aToolbarItem)
|
|
|
|
{
|
2008-12-03 12:35:34 +00:00
|
|
|
var wrapper = createWrapper(aToolbarItem.id, gToolboxDocument);
|
2006-11-24 23:22:47 +00:00
|
|
|
|
2002-09-27 04:06:56 +00:00
|
|
|
wrapper.flex = aToolbarItem.flex;
|
|
|
|
|
2008-12-03 12:35:34 +00:00
|
|
|
aToolbarItem.parentNode.replaceChild(wrapper, aToolbarItem);
|
2002-09-27 04:06:56 +00:00
|
|
|
|
|
|
|
wrapper.appendChild(aToolbarItem);
|
|
|
|
|
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the list of ids for the current set of items on each toolbar.
|
|
|
|
*/
|
|
|
|
function getCurrentItemIds()
|
|
|
|
{
|
|
|
|
var currentItems = {};
|
|
|
|
for (var i = 0; i < gToolbox.childNodes.length; ++i) {
|
2002-10-20 08:03:51 +00:00
|
|
|
var toolbar = getToolbarAt(i);
|
2002-09-27 04:06:56 +00:00
|
|
|
if (isCustomizableToolbar(toolbar)) {
|
2002-10-01 19:31:58 +00:00
|
|
|
var child = toolbar.firstChild;
|
|
|
|
while (child) {
|
|
|
|
if (isToolbarItem(child))
|
|
|
|
currentItems[child.id] = 1;
|
|
|
|
child = child.nextSibling;
|
|
|
|
}
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return currentItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds the palette of draggable items that are not yet in a toolbar.
|
|
|
|
*/
|
|
|
|
function buildPalette()
|
|
|
|
{
|
|
|
|
// Empty the palette first.
|
|
|
|
var paletteBox = document.getElementById("palette-box");
|
2002-10-01 19:31:58 +00:00
|
|
|
while (paletteBox.lastChild)
|
|
|
|
paletteBox.removeChild(paletteBox.lastChild);
|
2002-09-27 04:06:56 +00:00
|
|
|
|
|
|
|
var currentRow = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
|
|
|
"hbox");
|
|
|
|
currentRow.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, currentRow, null);
|
|
|
|
|
2002-09-28 15:11:50 +00:00
|
|
|
// 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, currentRow, null);
|
|
|
|
|
2002-09-27 04:06:56 +00:00
|
|
|
// Add the toolbar spacer item.
|
|
|
|
templateNode = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
2002-09-28 15:11:50 +00:00
|
|
|
"toolbarspacer");
|
2002-09-27 04:06:56 +00:00
|
|
|
templateNode.id = "spacer";
|
|
|
|
templateNode.flex = 1;
|
|
|
|
wrapPaletteItem(templateNode, currentRow, null);
|
|
|
|
|
2002-09-28 15:11:50 +00:00
|
|
|
var rowSlot = 3;
|
2002-09-27 04:06:56 +00:00
|
|
|
|
|
|
|
var currentItems = getCurrentItemIds();
|
|
|
|
templateNode = gToolbox.palette.firstChild;
|
|
|
|
while (templateNode) {
|
|
|
|
// Check if the item is already in a toolbar before adding it to the palette.
|
|
|
|
if (!(templateNode.id in currentItems)) {
|
2008-12-03 12:35:34 +00:00
|
|
|
var paletteItem = document.importNode(templateNode, true);
|
2002-09-27 04:06:56 +00:00
|
|
|
|
|
|
|
if (rowSlot == kRowMax) {
|
|
|
|
// Append the old row.
|
|
|
|
paletteBox.appendChild(currentRow);
|
|
|
|
|
|
|
|
// Make a new row.
|
|
|
|
currentRow = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
|
|
|
"hbox");
|
|
|
|
currentRow.setAttribute("class", "paletteRow");
|
|
|
|
rowSlot = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
++rowSlot;
|
|
|
|
wrapPaletteItem(paletteItem, currentRow, null);
|
|
|
|
}
|
|
|
|
|
|
|
|
templateNode = templateNode.nextSibling;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentRow) {
|
|
|
|
fillRowWithFlex(currentRow);
|
|
|
|
paletteBox.appendChild(currentRow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new palette item for a cloned template node and
|
|
|
|
* adds it to the last slot in the palette.
|
|
|
|
*/
|
|
|
|
function appendPaletteItem(aItem)
|
|
|
|
{
|
|
|
|
var paletteBox = document.getElementById("palette-box");
|
|
|
|
var lastRow = paletteBox.lastChild;
|
|
|
|
var lastSpacer = lastRow.lastChild;
|
|
|
|
|
|
|
|
if (lastSpacer.localName != "spacer") {
|
|
|
|
// The current row is full, so we have to create a new row.
|
|
|
|
lastRow = document.createElementNS("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul",
|
|
|
|
"hbox");
|
|
|
|
lastRow.setAttribute("class", "paletteRow");
|
|
|
|
paletteBox.appendChild(lastRow);
|
|
|
|
|
|
|
|
wrapPaletteItem(aItem, lastRow, null);
|
|
|
|
|
|
|
|
fillRowWithFlex(lastRow);
|
|
|
|
} else {
|
|
|
|
// Decrement the flex of the last spacer or remove it entirely.
|
|
|
|
var flex = lastSpacer.getAttribute("flex");
|
|
|
|
if (flex == 1) {
|
|
|
|
lastRow.removeChild(lastSpacer);
|
|
|
|
lastSpacer = null;
|
|
|
|
} else
|
|
|
|
lastSpacer.setAttribute("flex", --flex);
|
|
|
|
|
|
|
|
// Insert the wrapper where the last spacer was.
|
|
|
|
wrapPaletteItem(aItem, lastRow, lastSpacer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2008-10-02 06:49:45 +00:00
|
|
|
* is stripped of all properties that may adversely affect its
|
2002-09-27 04:06:56 +00:00
|
|
|
* appearance in the palette.
|
|
|
|
*/
|
|
|
|
function cleanUpItemForPalette(aItem, aWrapper)
|
|
|
|
{
|
2002-09-28 15:11:50 +00:00
|
|
|
aWrapper.setAttribute("place", "palette");
|
|
|
|
setWrapperType(aItem, aWrapper);
|
2002-09-27 04:06:56 +00:00
|
|
|
|
2002-09-28 15:11:50 +00:00
|
|
|
if (aItem.hasAttribute("title"))
|
|
|
|
aWrapper.setAttribute("title", aItem.getAttribute("title"));
|
|
|
|
else if (isSpecialItem(aItem)) {
|
|
|
|
var stringBundle = document.getElementById("stringBundle");
|
2008-12-03 12:35:34 +00:00
|
|
|
// Remove the common "toolbar" prefix to generate the string name.
|
|
|
|
var title = stringBundle.getString(aItem.localName.slice(7) + "Title");
|
2002-09-28 15:11:50 +00:00
|
|
|
aWrapper.setAttribute("title", title);
|
|
|
|
}
|
|
|
|
|
2002-09-27 04:06:56 +00:00
|
|
|
// Remove attributes that screw up our appearance.
|
|
|
|
aItem.removeAttribute("command");
|
|
|
|
aItem.removeAttribute("observes");
|
|
|
|
aItem.removeAttribute("disabled");
|
|
|
|
aItem.removeAttribute("type");
|
2008-06-16 01:30:16 +00:00
|
|
|
aItem.removeAttribute("width");
|
2002-09-27 04:06:56 +00:00
|
|
|
|
|
|
|
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
|
2008-10-02 06:49:45 +00:00
|
|
|
* is stripped of all properties that may adversely affect its
|
2002-09-27 04:06:56 +00:00
|
|
|
* 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)
|
|
|
|
{
|
2002-09-28 15:11:50 +00:00
|
|
|
setWrapperType(aItem, aWrapper);
|
|
|
|
aWrapper.setAttribute("place", "toolbar");
|
2002-09-27 04:06:56 +00:00
|
|
|
|
|
|
|
if (aItem.hasAttribute("command")) {
|
|
|
|
aWrapper.setAttribute("itemcommand", aItem.getAttribute("command"));
|
|
|
|
aItem.removeAttribute("command");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aItem.disabled) {
|
|
|
|
aWrapper.setAttribute("itemdisabled", "true");
|
|
|
|
aItem.disabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-28 15:11:50 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-27 04:06:56 +00:00
|
|
|
function setDragActive(aItem, aValue)
|
|
|
|
{
|
|
|
|
var node = aItem;
|
2005-03-04 18:39:12 +00:00
|
|
|
var direction = window.getComputedStyle(aItem, null).direction;
|
|
|
|
var value = direction == "ltr"? "left" : "right";
|
2002-09-27 04:06:56 +00:00
|
|
|
if (aItem.localName == "toolbar") {
|
|
|
|
node = aItem.lastChild;
|
2005-03-04 18:39:12 +00:00
|
|
|
value = direction == "ltr"? "right" : "left";
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (aValue) {
|
|
|
|
if (!node.hasAttribute("dragover"))
|
|
|
|
node.setAttribute("dragover", value);
|
|
|
|
} else {
|
|
|
|
node.removeAttribute("dragover");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function addNewToolbar()
|
|
|
|
{
|
|
|
|
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");
|
2005-03-05 01:22:30 +00:00
|
|
|
|
2002-09-27 04:06:56 +00:00
|
|
|
var name = {};
|
2005-03-05 01:22:30 +00:00
|
|
|
|
2008-02-06 06:45:48 +00:00
|
|
|
// Quitting from the toolbar dialog while the new toolbar prompt is up
|
|
|
|
// can cause things to become unresponsive on the Mac. Until dialog modality
|
|
|
|
// is fixed (395465), disable the "Done" button explicitly.
|
|
|
|
var doneButton = document.getElementById("donebutton");
|
|
|
|
doneButton.disabled = true;
|
|
|
|
|
2004-12-01 00:21:43 +00:00
|
|
|
while (true) {
|
2005-03-05 01:22:30 +00:00
|
|
|
|
2008-02-06 06:45:48 +00:00
|
|
|
if (!promptService.prompt(window, title, message, name, null, {})) {
|
|
|
|
doneButton.disabled = false;
|
2002-09-27 04:06:56 +00:00
|
|
|
return;
|
2008-02-06 06:45:48 +00:00
|
|
|
}
|
2005-03-05 01:22:30 +00:00
|
|
|
|
|
|
|
if (!name.value) {
|
|
|
|
message = stringBundle.getFormattedString("enterToolbarBlank", [name.value]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-12-01 00:21:43 +00:00
|
|
|
var dupeFound = false;
|
2005-03-05 01:22:30 +00:00
|
|
|
|
2004-12-01 00:21:43 +00:00
|
|
|
// Check for an existing toolbar with the same display name
|
|
|
|
for (i = 0; i < gToolbox.childNodes.length; ++i) {
|
|
|
|
var toolbar = gToolbox.childNodes[i];
|
|
|
|
var toolbarName = toolbar.getAttribute("toolbarname");
|
2005-03-05 01:22:30 +00:00
|
|
|
|
|
|
|
if (toolbarName == name.value &&
|
|
|
|
toolbar.getAttribute("type") != "menubar" &&
|
|
|
|
toolbar.nodeName == 'toolbar') {
|
2004-12-01 00:21:43 +00:00
|
|
|
dupeFound = true;
|
2002-09-27 04:06:56 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-03-05 01:22:30 +00:00
|
|
|
}
|
2004-12-01 00:21:43 +00:00
|
|
|
|
|
|
|
if (!dupeFound)
|
|
|
|
break;
|
2005-03-05 01:22:30 +00:00
|
|
|
|
|
|
|
message = stringBundle.getFormattedString("enterToolbarDup", [name.value]);
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gToolbox.appendCustomToolbar(name.value, "");
|
2002-09-28 15:11:50 +00:00
|
|
|
|
2008-01-30 23:16:52 +00:00
|
|
|
toolboxChanged();
|
2008-02-06 06:45:48 +00:00
|
|
|
|
|
|
|
doneButton.disabled = false;
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restore the default set of buttons to fixed toolbars,
|
|
|
|
* remove all custom toolbars, and rebuild the palette.
|
|
|
|
*/
|
|
|
|
function restoreDefaultSet()
|
|
|
|
{
|
2008-12-03 12:35:34 +00:00
|
|
|
// Unwrap the items on the toolbar.
|
|
|
|
unwrapToolbarItems();
|
2004-12-01 00:21:43 +00:00
|
|
|
|
2008-02-06 21:52:29 +00:00
|
|
|
// Remove all of the customized toolbars.
|
|
|
|
var child = gToolbox.lastChild;
|
|
|
|
while (child) {
|
|
|
|
if (child.hasAttribute("customindex")) {
|
|
|
|
var thisChild = child;
|
|
|
|
child = child.previousSibling;
|
2008-12-03 12:35:34 +00:00
|
|
|
thisChild.currentSet = "__empty";
|
2008-02-06 21:52:29 +00:00
|
|
|
gToolbox.removeChild(thisChild);
|
|
|
|
} else {
|
|
|
|
child = child.previousSibling;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-27 04:06:56 +00:00
|
|
|
// Restore the defaultset for fixed toolbars.
|
|
|
|
var toolbar = gToolbox.firstChild;
|
|
|
|
while (toolbar) {
|
|
|
|
if (isCustomizableToolbar(toolbar)) {
|
2008-02-06 21:52:29 +00:00
|
|
|
var defaultSet = toolbar.getAttribute("defaultset");
|
|
|
|
if (defaultSet)
|
|
|
|
toolbar.currentSet = defaultSet;
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
|
|
|
toolbar = toolbar.nextSibling;
|
|
|
|
}
|
|
|
|
|
2006-12-09 03:32:36 +00:00
|
|
|
// Restore the default icon size and mode.
|
|
|
|
var defaultMode = gToolbox.getAttribute("defaultmode");
|
|
|
|
var defaultIconsSmall = gToolbox.getAttribute("defaulticonsize") == "small";
|
|
|
|
|
2008-02-06 21:52:29 +00:00
|
|
|
updateIconSize(defaultIconsSmall, true);
|
2006-12-09 03:32:36 +00:00
|
|
|
document.getElementById("smallicons").checked = defaultIconsSmall;
|
2008-02-06 21:52:29 +00:00
|
|
|
updateToolbarMode(defaultMode, true);
|
2006-12-09 03:32:36 +00:00
|
|
|
document.getElementById("modelist").value = defaultMode;
|
2008-02-06 21:52:29 +00:00
|
|
|
|
2002-09-27 04:06:56 +00:00
|
|
|
// Now rebuild the palette.
|
|
|
|
buildPalette();
|
2002-10-01 19:31:58 +00:00
|
|
|
|
|
|
|
// Now re-wrap the items on the toolbar.
|
|
|
|
wrapToolbarItems();
|
|
|
|
|
2009-01-30 22:05:44 +00:00
|
|
|
toolboxChanged("reset");
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
|
|
|
|
2008-02-06 21:52:29 +00:00
|
|
|
function updateIconSize(aUseSmallIcons, localDefault)
|
2002-09-27 04:06:56 +00:00
|
|
|
{
|
2004-07-24 00:53:29 +00:00
|
|
|
gToolboxIconSize = aUseSmallIcons ? "small" : "large";
|
2002-09-27 04:06:56 +00:00
|
|
|
|
2004-06-20 10:07:43 +00:00
|
|
|
setAttribute(gToolbox, "iconsize", gToolboxIconSize);
|
2002-09-27 04:06:56 +00:00
|
|
|
gToolboxDocument.persist(gToolbox.id, "iconsize");
|
|
|
|
|
|
|
|
for (var i = 0; i < gToolbox.childNodes.length; ++i) {
|
2002-10-20 08:03:51 +00:00
|
|
|
var toolbar = getToolbarAt(i);
|
2002-09-27 04:06:56 +00:00
|
|
|
if (isCustomizableToolbar(toolbar)) {
|
2008-02-06 21:52:29 +00:00
|
|
|
var toolbarIconSize = (localDefault && toolbar.hasAttribute("defaulticonsize")) ?
|
|
|
|
toolbar.getAttribute("defaulticonsize") :
|
|
|
|
gToolboxIconSize;
|
|
|
|
setAttribute(toolbar, "iconsize", toolbarIconSize);
|
2002-09-27 04:06:56 +00:00
|
|
|
gToolboxDocument.persist(toolbar.id, "iconsize");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-06 21:52:29 +00:00
|
|
|
function updateToolbarMode(aModeValue, localDefault)
|
2002-09-27 04:06:56 +00:00
|
|
|
{
|
|
|
|
setAttribute(gToolbox, "mode", aModeValue);
|
|
|
|
gToolboxDocument.persist(gToolbox.id, "mode");
|
|
|
|
|
|
|
|
for (var i = 0; i < gToolbox.childNodes.length; ++i) {
|
2002-10-20 08:03:51 +00:00
|
|
|
var toolbar = getToolbarAt(i);
|
2002-09-27 04:06:56 +00:00
|
|
|
if (isCustomizableToolbar(toolbar)) {
|
2008-02-06 21:52:29 +00:00
|
|
|
var toolbarMode = (localDefault && toolbar.hasAttribute("defaultmode")) ?
|
|
|
|
toolbar.getAttribute("defaultmode") :
|
|
|
|
aModeValue;
|
|
|
|
setAttribute(toolbar, "mode", toolbarMode);
|
2002-09-27 04:06:56 +00:00
|
|
|
gToolboxDocument.persist(toolbar.id, "mode");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var iconSizeCheckbox = document.getElementById("smallicons");
|
2004-10-05 10:45:58 +00:00
|
|
|
iconSizeCheckbox.disabled = aModeValue == "text";
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function setAttribute(aElt, aAttr, aVal)
|
|
|
|
{
|
|
|
|
if (aVal)
|
|
|
|
aElt.setAttribute(aAttr, aVal);
|
|
|
|
else
|
|
|
|
aElt.removeAttribute(aAttr);
|
|
|
|
}
|
|
|
|
|
|
|
|
function isCustomizableToolbar(aElt)
|
|
|
|
{
|
2002-10-20 08:05:30 +00:00
|
|
|
return aElt.localName == "toolbar" &&
|
2002-09-27 04:06:56 +00:00
|
|
|
aElt.getAttribute("customizable") == "true";
|
|
|
|
}
|
|
|
|
|
2002-09-28 15:11:50 +00:00
|
|
|
function isSpecialItem(aElt)
|
|
|
|
{
|
|
|
|
return aElt.localName == "toolbarseparator" ||
|
|
|
|
aElt.localName == "toolbarspring" ||
|
2007-11-15 03:38:16 +00:00
|
|
|
aElt.localName == "toolbarspacer";
|
2002-09-28 15:11:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function isToolbarItem(aElt)
|
|
|
|
{
|
2002-09-27 04:06:56 +00:00
|
|
|
return aElt.localName == "toolbarbutton" ||
|
|
|
|
aElt.localName == "toolbaritem" ||
|
|
|
|
aElt.localName == "toolbarseparator" ||
|
2002-09-28 15:11:50 +00:00
|
|
|
aElt.localName == "toolbarspring" ||
|
2007-11-15 03:38:16 +00:00
|
|
|
aElt.localName == "toolbarspacer";
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////
|
|
|
|
//// Drag and Drop observers
|
|
|
|
|
2008-10-17 20:04:55 +00:00
|
|
|
function onToolbarDragStart(aEvent)
|
2002-09-27 04:06:56 +00:00
|
|
|
{
|
|
|
|
nsDragAndDrop.startDrag(aEvent, dragStartObserver);
|
|
|
|
}
|
|
|
|
|
|
|
|
function onToolbarDragOver(aEvent)
|
|
|
|
{
|
|
|
|
nsDragAndDrop.dragOver(aEvent, toolbarDNDObserver);
|
|
|
|
}
|
|
|
|
|
2008-10-17 20:04:55 +00:00
|
|
|
function onToolbarDrop(aEvent)
|
2002-09-27 04:06:56 +00:00
|
|
|
{
|
|
|
|
nsDragAndDrop.drop(aEvent, toolbarDNDObserver);
|
|
|
|
}
|
|
|
|
|
2008-10-17 20:04:55 +00:00
|
|
|
function onToolbarDragLeave(aEvent)
|
2002-09-27 04:06:56 +00:00
|
|
|
{
|
|
|
|
if (gCurrentDragOverItem)
|
|
|
|
setDragActive(gCurrentDragOverItem, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
var dragStartObserver =
|
|
|
|
{
|
|
|
|
onDragStart: function (aEvent, aXferData, aDragAction) {
|
|
|
|
var documentId = gToolboxDocument.documentElement.id;
|
|
|
|
|
|
|
|
var item = aEvent.target;
|
|
|
|
while (item && item.localName != "toolbarpaletteitem")
|
|
|
|
item = item.parentNode;
|
|
|
|
|
|
|
|
item.setAttribute("dragactive", "true");
|
|
|
|
|
|
|
|
aXferData.data = new TransferDataSet();
|
|
|
|
var data = new TransferData();
|
|
|
|
data.addDataForFlavour("text/toolbarwrapper-id/"+documentId, item.firstChild.id);
|
|
|
|
aXferData.data.push(data);
|
2004-07-06 06:13:57 +00:00
|
|
|
aDragAction.action = Components.interfaces.nsIDragService.DRAGDROP_ACTION_MOVE;
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var toolbarDNDObserver =
|
|
|
|
{
|
|
|
|
onDragOver: function (aEvent, aFlavour, aDragSession)
|
|
|
|
{
|
|
|
|
var toolbar = aEvent.target;
|
2002-09-29 01:23:02 +00:00
|
|
|
var dropTarget = aEvent.target;
|
|
|
|
while (toolbar && toolbar.localName != "toolbar") {
|
|
|
|
dropTarget = toolbar;
|
2002-09-27 04:06:56 +00:00
|
|
|
toolbar = toolbar.parentNode;
|
2002-09-29 01:23:02 +00:00
|
|
|
}
|
|
|
|
|
2002-09-27 04:06:56 +00:00
|
|
|
var previousDragItem = gCurrentDragOverItem;
|
|
|
|
|
|
|
|
// Make sure we are dragging over a customizable toolbar.
|
|
|
|
if (!isCustomizableToolbar(toolbar)) {
|
|
|
|
gCurrentDragOverItem = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-09-29 01:23:02 +00:00
|
|
|
if (dropTarget.localName == "toolbar") {
|
|
|
|
gCurrentDragOverItem = dropTarget;
|
2002-09-27 04:06:56 +00:00
|
|
|
} else {
|
|
|
|
gCurrentDragOverItem = null;
|
2005-03-04 18:39:12 +00:00
|
|
|
|
|
|
|
var direction = window.getComputedStyle(dropTarget.parentNode, null).direction;
|
|
|
|
var dropTargetCenter = dropTarget.boxObject.x + (dropTarget.boxObject.width / 2);
|
2009-03-28 07:50:36 +00:00
|
|
|
var dragAfter;
|
2005-03-04 18:39:12 +00:00
|
|
|
if (direction == "ltr")
|
|
|
|
dragAfter = aEvent.clientX > dropTargetCenter;
|
|
|
|
else
|
|
|
|
dragAfter = aEvent.clientX < dropTargetCenter;
|
|
|
|
|
|
|
|
if (dragAfter) {
|
2002-09-29 01:23:02 +00:00
|
|
|
gCurrentDragOverItem = dropTarget.nextSibling;
|
2002-09-27 04:06:56 +00:00
|
|
|
if (!gCurrentDragOverItem)
|
|
|
|
gCurrentDragOverItem = toolbar;
|
|
|
|
} else
|
2002-09-29 01:23:02 +00:00
|
|
|
gCurrentDragOverItem = dropTarget;
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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.localName != "toolbar")
|
|
|
|
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;
|
|
|
|
|
2002-10-29 00:23:42 +00:00
|
|
|
// 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;
|
|
|
|
|
2008-10-02 06:49:45 +00:00
|
|
|
// Remove the item from its place in the toolbar.
|
2002-09-27 04:06:56 +00:00
|
|
|
wrapper.parentNode.removeChild(wrapper);
|
|
|
|
|
|
|
|
// Determine which toolbar we are dropping on.
|
|
|
|
var dropToolbar = null;
|
|
|
|
if (gCurrentDragOverItem.localName == "toolbar")
|
|
|
|
dropToolbar = gCurrentDragOverItem;
|
|
|
|
else
|
|
|
|
dropToolbar = gCurrentDragOverItem.parentNode;
|
|
|
|
|
|
|
|
// Insert the item into the toolbar.
|
|
|
|
if (gCurrentDragOverItem != dropToolbar)
|
|
|
|
dropToolbar.insertBefore(wrapper, gCurrentDragOverItem);
|
|
|
|
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.
|
2008-12-03 12:35:34 +00:00
|
|
|
var wrapper = createWrapper("", gToolboxDocument);
|
2002-09-27 04:06:56 +00:00
|
|
|
|
|
|
|
// Ask the toolbar to clone the item's template, place it inside the wrapper, and insert it in the toolbar.
|
|
|
|
var newItem = toolbar.insertItem(draggedItemId, gCurrentDragOverItem == toolbar ? null : gCurrentDragOverItem, wrapper);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
var currentRow = draggedPaletteWrapper.parentNode;
|
|
|
|
if (draggedItemId != "separator" &&
|
2002-09-28 15:11:50 +00:00
|
|
|
draggedItemId != "spring" &&
|
2007-11-15 03:38:16 +00:00
|
|
|
draggedItemId != "spacer")
|
2002-09-27 04:06:56 +00:00
|
|
|
{
|
|
|
|
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 == last) {
|
|
|
|
// Kill the row.
|
|
|
|
currentRow.parentNode.removeChild(currentRow);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
currentRow.appendChild(nextRow.firstChild);
|
|
|
|
currentRow = currentRow.nextSibling;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gCurrentDragOverItem = null;
|
2002-09-28 15:11:50 +00:00
|
|
|
|
2008-01-30 23:16:52 +00:00
|
|
|
toolboxChanged();
|
2002-09-27 04:06:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_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;
|
|
|
|
|
|
|
|
var wrapper = gToolboxDocument.getElementById("wrapper-"+itemId);
|
|
|
|
if (wrapper) {
|
2002-10-29 00:23:42 +00:00
|
|
|
// 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;
|
|
|
|
|
2002-09-27 04:06:56 +00:00
|
|
|
var wrapperType = wrapper.getAttribute("type");
|
2007-08-06 15:57:40 +00:00
|
|
|
if (wrapperType != "separator" &&
|
|
|
|
wrapperType != "spacer" &&
|
2007-11-15 03:38:16 +00:00
|
|
|
wrapperType != "spring") {
|
2008-12-03 12:35:34 +00:00
|
|
|
appendPaletteItem(document.importNode(wrapper.firstChild, true));
|
|
|
|
gToolbox.palette.appendChild(wrapper.firstChild);
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
2008-12-03 12:35:34 +00:00
|
|
|
|
|
|
|
// The item was dragged out of the toolbar.
|
|
|
|
wrapper.parentNode.removeChild(wrapper);
|
2002-09-27 04:06:56 +00:00
|
|
|
}
|
|
|
|
|
2008-01-30 23:16:52 +00:00
|
|
|
toolboxChanged();
|
2002-09-27 04:06:56 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|