zotero/chrome/content/zotero/bindings/columnpicker.xml
2012-04-08 15:24:39 -04:00

146 lines
No EOL
5.4 KiB
XML

<?xml version="1.0"?>
<!--
***** BEGIN LICENSE BLOCK *****
Copyright © 2012 Center for History and New Media
George Mason University, Fairfax, Virginia, USA
http://zotero.org
The Initial Developer of this code is Gracile. Portions created by the
Initial Developer are Copyright © 2012 the Initial Developer.
This file contains code derived from Mozilla's tree.xml, © 2012 its
developers.
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
-->
<!DOCTYPE bindings SYSTEM "chrome://zotero/locale/zotero.dtd">
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="extended-columnpicker" display="xul:button"
extends="chrome://global/content/bindings/tree.xml#tree-base">
<content>
<xul:image class="tree-columnpicker-icon"/>
<xul:menupopup anonid="zotero-items-column-main-menu">
<xul:menuseparator/>
<xul:menu label="&zotero.items.moreColumns.label;">
<xul:menupopup anonid="zotero-items-column-sub-menu"/>
</xul:menu>
<xul:menuseparator/>
<xul:menuitem anonid="menuitem" label="&zotero.items.restoreColumnOrder.label;"/>
</xul:menupopup>
</content>
<implementation implements="nsIAccessibleProvider">
<property name="accessibleType" readonly="true">
<getter>
return Components.interfaces.nsIAccessibleProvider.XULButton;
</getter>
</property>
<method name="buildPopup">
<parameter name="aPopup"/>
<parameter name="bPopup"/>
<body>
<![CDATA[
// We no longer cache the picker content, remove the old content.
while (aPopup.childNodes.length > 4) {
aPopup.removeChild(aPopup.firstChild);
}
while (bPopup.childNodes.length > 0) {
bPopup.removeChild(bPopup.firstChild);
}
var refChild = aPopup.firstChild;
var refChild2 = bPopup.firstChild;
var tree = this.parentNode.parentNode;
for (var currCol = tree.columns.getFirstColumn(); currCol; currCol = currCol.getNext()) {
var currElement = currCol.element;
// Construct an entry for each column in the row, unless
// it is not being shown.
if ((!currElement.hasAttribute("ignoreincolumnpicker")) && (!currElement.hasAttribute("submenu"))) {
var popupChild = document.createElement("menuitem");
popupChild.setAttribute("type", "checkbox");
var columnName = currElement.getAttribute("display") || currElement.getAttribute("label");
popupChild.setAttribute("label", columnName);
popupChild.setAttribute("colindex", currCol.index);
if (currElement.getAttribute("hidden") != "true") {
popupChild.setAttribute("checked", "true");
}
if (currCol.primary) {
popupChild.setAttribute("disabled", "true");
}
aPopup.insertBefore(popupChild, refChild);
}
//Idem for the submenu
if ((!currElement.hasAttribute("ignoreincolumnpicker")) && (currElement.hasAttribute("submenu"))) {
var popupChild = document.createElement("menuitem");
popupChild.setAttribute("type", "checkbox");
var columnName = currElement.getAttribute("display") || currElement.getAttribute("label");
popupChild.setAttribute("label", columnName);
popupChild.setAttribute("colindex", currCol.index);
if (currElement.getAttribute("hidden") != "true") {
popupChild.setAttribute("checked", "true");
}
bPopup.insertBefore(popupChild, refChild2);
}
}
]]>
</body>
</method>
</implementation>
<handlers>
<handler event="command">
<![CDATA[
if (event.originalTarget == this) {
var popup = document.getAnonymousElementByAttribute(this, "anonid", "zotero-items-column-main-menu");
var popup2 = document.getAnonymousElementByAttribute(this, "anonid", "zotero-items-column-sub-menu");
this.buildPopup(popup, popup2);
popup.showPopup(this, -1, -1, "popup", "bottomright", "topright");
} else {
var tree = this.parentNode.parentNode;
tree.stopEditing(true);
var menuitem = document.getAnonymousElementByAttribute(this, "anonid", "menuitem");
if (event.originalTarget == menuitem) {
tree.columns.restoreNaturalOrder();
tree._ensureColumnOrder();
} else {
var colindex = event.originalTarget.getAttribute("colindex");
var column = tree.columns[colindex];
if (column) {
var element = column.element;
if (element.getAttribute("hidden") == "true") {
element.setAttribute("hidden", "false");
} else {
element.setAttribute("hidden", "true");
}
}
}
}
]]>
</handler>
</handlers>
</binding>
</bindings>