commit a979acb4b811abbb45d71b0fc21f601863e20ad8
parent 7cacff3a087559e765cf25dff256cffb1ddcb937
Author: Dan Stillman <dstillman@zotero.org>
Date: Mon, 2 May 2011 19:20:22 +0000
Fix selection of single top-level item after site translation
Diffstat:
1 file changed, 38 insertions(+), 4 deletions(-)
diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js
@@ -502,9 +502,43 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
if(madeChanges)
{
- // If adding and this is the active window, select the item
- if(action == 'add' && ids.length===1 && activeWindow)
- {
+ var singleSelect = false;
+ // If adding a single top-level item and this is the active window, select it
+ if (action == 'add' && activeWindow) {
+ if (ids.length == 1) {
+ singleSelect = ids[0];
+ }
+ // If there's only one parent item in the set of added items,
+ // mark that for selection in the UI
+ //
+ // Only bother checking for single parent item if 1-5 total items,
+ // since a translator is unlikely to save more than 4 child items
+ else if (ids.length <= 5) {
+ var items = Zotero.Items.get(ids);
+ if (items) {
+ var found = false;
+ for each(var item in items) {
+ // Check for note and attachment type, since it's quicker
+ // than checking for parent item
+ if (item.itemTypeID == 1 || item.itemTypeID == 14) {
+ continue;
+ }
+
+ // We already found a top-level item, so cancel the
+ // single selection
+ if (found) {
+ singleSelect = false;
+ break;
+ }
+ found = true;
+ singleSelect = item.id;
+ }
+ }
+ }
+ }
+
+
+ if (singleSelect) {
if (sort) {
this.sort(typeof sort == 'number' ? sort : false);
}
@@ -515,7 +549,7 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData)
// Reset to Info tab
this._ownerDocument.getElementById('zotero-view-tabbox').selectedIndex = 0;
- this.selectItem(ids[0]);
+ this.selectItem(singleSelect);
}
// If single item is selected and was modified
else if (action == 'modify' && ids.length == 1 &&