www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit dea69fac3d5a82ebbe7b8169b4a46b98a6d696d1
parent 75baa706cd62946f3d3a43b6eb8ac09ad9e12ccf
Author: Mikko Rönkkö <mikko.ronkko@aalto.fi>
Date:   Thu,  3 Nov 2011 16:31:31 +0200

Added grouping of items by library and separators for libraries to QuickFormat dialog

Diffstat:
Mchrome/content/zotero/integration/quickFormat.js | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 66 insertions(+), 6 deletions(-)

diff --git a/chrome/content/zotero/integration/quickFormat.js b/chrome/content/zotero/integration/quickFormat.js @@ -265,19 +265,38 @@ var Zotero_QuickFormat = new function () { while(referenceBox.hasChildNodes()) referenceBox.removeChild(referenceBox.firstChild); + var firstSelectableIndex = 0; + if(ids.length) { if(ids.length > 50) ids = ids.slice(0, 50); var items = Zotero.Items.get(ids); + + firstSelectableIndex = 1; + + //TODO: sort the currently used items in before any other items + items.sort(function(a, b) {return a.libraryID > b.libraryID}) + + var previousLibrary = -1; + for(var i=0, n=items.length; i<n; i++) { - referenceBox.appendChild(_buildListItem(items[i])); + if(previousLibrary!=items[i].libraryID){ + //TODO: Make localized labels and resolve the library name based on library ID + referenceBox.appendChild(_buildListSeparator("Items from "+items[i].libraryID)); + } + + referenceBox.appendChild(_buildListItem(items[i]),false); + + previousLibrary=items[i].libraryID + } } _resize(); - referenceBox.selectedIndex = 0; - referenceBox.ensureIndexIsVisible(0); + referenceBox.selectedIndex = firstSelectableIndex; + referenceBox.ensureIndexIsVisible(firstSelectableIndex); } + /** * Builds a string describing an item. We avoid CSL here for speed. @@ -374,6 +393,25 @@ var Zotero_QuickFormat = new function () { return rll; } + + function _buildListSeparator(labelText) { + var titleNode = document.createElement("label"); + //TODO: CSS style needed for this class + titleNode.setAttribute("class", "quick-format-separator"); + titleNode.setAttribute("flex", "1"); + titleNode.setAttribute("crop", "end"); + titleNode.setAttribute("value", labelText); + + // add to rich list item + var rll = document.createElement("richlistitem"); + rll.setAttribute("orient", "vertical"); + rll.setAttribute("flex", "1"); + rll.setAttribute("disabled", true); + rll.setAttribute("class", "quick-format-separator"); + rll.appendChild(titleNode); + + return rll; + } /** * Builds the string to go inside a bubble @@ -719,10 +757,24 @@ var Zotero_QuickFormat = new function () { } else if(keyCode === event.DOM_VK_UP) { var selectedItem = referenceBox.selectedItem; + var previousSibling; - if((previousSibling = selectedItem.previousSibling)) { + + //Seek the closet previous sibling that is not disabled + while((previousSibling = selectedItem.previousSibling) && previousSibling.getAttribute("disabled")){ + selectedItem = previousSibling; + } + //If found, change to that + if(previousSibling) { referenceBox.selectedItem = previousSibling; - referenceBox.ensureElementIsVisible(previousSibling); + + //If there are separators before this item, ensure that they are visible + var visibleItem = previousSibling; + + while(visibleItem.previousSibling && visibleItem.previousSibling.getAttribute("disabled")){ + visibleItem = visibleItem.previousSibling; + } + referenceBox.ensureElementIsVisible(visibleItem); event.preventDefault(); }; } else if(keyCode === event.DOM_VK_DOWN) { @@ -768,7 +820,15 @@ var Zotero_QuickFormat = new function () { } else { var selectedItem = referenceBox.selectedItem; var nextSibling; - if((nextSibling = selectedItem.nextSibling)) { + + //Seek the closet next sibling that is not disabled + while((nextSibling = selectedItem.nextSibling) && nextSibling.getAttribute("disabled")){ + selectedItem = nextSibling; + } + + //If found, change to that + + if(nextSibling){ referenceBox.selectedItem = nextSibling; referenceBox.ensureElementIsVisible(nextSibling); event.preventDefault();