OSDN Git Service

import source-tree based svn r84.
[bluegriffon/BlueGriffon.git] / base / content / bluegriffon / js / customize.js
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
3  *
4  * The contents of this file are subject to the Mozilla Public License Version
5  * 1.1 (the "License"); you may not use this file except in compliance with
6  * the License. You may obtain a copy of the License at
7  * http://www.mozilla.org/MPL/
8  *
9  * Software distributed under the License is distributed on an "AS IS" basis,
10  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11  * for the specific language governing rights and limitations under the
12  * License.
13  *
14  * The Original Code is Mozilla Communicator client code, released
15  * March 31, 1998.
16  *
17  * The Initial Developer of the Original Code is
18  * Netscape Communications Corporation.
19  * Portions created by the Initial Developer are Copyright (C) 2001
20  * the Initial Developer. All Rights Reserved.
21  *
22  * Contributor(s):
23  *   Daniel Glazman <daniel.glazman@disruptive-innovations.com>
24  *
25  * Alternatively, the contents of this file may be used under the terms of
26  * either the GNU General Public License Version 2 or later (the "GPL"), or
27  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28  * in which case the provisions of the GPL or the LGPL are applicable instead
29  * of those above. If you wish to allow use of your version of this file only
30  * under the terms of either the GPL or the LGPL, and not to allow others to
31  * use your version of this file under the terms of the MPL, indicate your
32  * decision by deleting the provisions above and replace them with the notice
33  * and other provisions required by the GPL or the LGPL. If you do not delete
34  * the provisions above, a recipient may use your version of this file under
35  * the terms of any one of the MPL, the GPL or the LGPL.
36  *
37  * ***** END LICENSE BLOCK ***** */
38
39
40 function CustomizeToolbar(id)
41 {
42   // Disable the toolbar context menu items
43   var menubar = document.getElementById("composer-main-menubar");
44   for (var i = 0; i < menubar.childNodes.length; ++i)
45     menubar.childNodes[i].setAttribute("disabled", true);
46
47   var customizePopup = document.getElementById("CustomizeMainToolbar");
48   if (customizePopup)
49     customizePopup.setAttribute("disabled", "true");
50   customizePopup = document.getElementById("CustomizeFormatToolbar");
51   if (customizePopup)
52     customizePopup.setAttribute("disabled", "true");
53
54   var customizeURL = "chrome://global/content/customizeToolbar.xul";
55 #ifdef TOOLBAR_CUSTOMIZATION_SHEET
56   var sheetFrame = document.getElementById("customizeToolbarSheetIFrame");
57   sheetFrame.hidden = false;
58
59   // The document might not have been loaded yet, if this is the first time.
60   // If it is already loaded, reload it so that the onload initialization code
61   // re-runs.
62   if (sheetFrame.getAttribute("src") == customizeURL)
63     sheetFrame.contentWindow.location.reload()
64   else
65     sheetFrame.setAttribute("src", customizeURL);
66
67   // XXXmano: there's apparently no better way to get this when the iframe is
68   // hidden
69   var sheetWidth = sheetFrame.style.width.match(/([0-9]+)px/)[1];
70   var popup = document.getElementById("customizeToolbarSheetPopup");
71   popup.setAttribute("refid", id);
72   popup.openPopup(document.getElementById(id), "after_start", (window.innerWidth - sheetWidth) / 2, 0);
73 #else
74   window.openDialog(customizeURL,
75                     "CustomizeToolbar",
76                     "chrome,titlebar,toolbar,resizable,dependent",
77                     document.getElementById(id));
78 #endif
79 }
80
81 function ToolboxCustomizeDone(aToolboxChanged)
82 {
83 #ifdef TOOLBAR_CUSTOMIZATION_SHEET
84   document.getElementById("customizeToolbarSheetIFrame").hidden = true;
85   document.getElementById("customizeToolbarSheetPopup").hidePopup();
86 #endif
87
88   // Re-enable parts of the UI we disabled during the dialog
89   var menubar = document.getElementById("composer-main-menubar");
90   for (var i = 0; i < menubar.childNodes.length; ++i)
91     menubar.childNodes[i].removeAttribute("disabled");
92
93   var customizePopup = document.getElementById("CustomizeMainToolbar");
94   if (customizePopup)
95     customizePopup.removeAttribute("disabled");
96   customizePopup = document.getElementById("CustomizeFormatToolbar");
97   if (customizePopup)
98     customizePopup.removeAttribute("disabled");
99
100   // make sure our toolbar buttons have the correct enabled state restored to them...
101   if (this.UpdateMainToolbar != undefined)
102     UpdateMainToolbar(focus); 
103 }
104
105 function onViewToolbarCommand(aToolbarId, aMenuItemId)
106 {
107   var toolbar = document.getElementById(aToolbarId);
108   var menuItem = document.getElementById(aMenuItemId);
109
110   if (!toolbar || !menuItem) return;
111
112   var toolbarCollapsed = toolbar.collapsed;
113
114   // toggle the checkbox
115   menuItem.setAttribute('checked', toolbarCollapsed);
116
117   // toggle visibility of the toolbar
118   toolbar.collapsed = !toolbarCollapsed;
119
120   document.persist(aToolbarId, 'collapsed');
121   document.persist(aMenuItemId, 'checked');
122 }
123
124 function UpdateMainToolbar(caller)
125 {
126     dump("===> UPDATING TOOLBAR\n");
127 }
128
129 function UpdateCustomizeMenuPopup(aPopup)
130 {
131   while (aPopup.hasChildNodes())
132     aPopup.removeChild(aPopup.lastChild);
133
134   var toolboxes = document.getElementsByTagName("toolbox");
135   
136 }
137
138 function InstallCustomizationDoneCallbacks()
139 {
140   gDialog.MainToolbox.customizeDone   = ToolboxCustomizeDone;
141   gDialog.FormatToolbox.customizeDone = ToolboxCustomizeDone;
142 }