www

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

commit 87c47c0615bc84f0e92ef37e817277a9cf2acc2d
parent e10d049428c38008035f79b46c1edd384b0a4da1
Author: Will S <terribleangel@gmail.com>
Date:   Tue, 27 Dec 2011 09:02:06 -0500

Select next logical tag when adding multiple tags at once.

Diffstat:
Mchrome/content/zotero/bindings/tagsbox.xml | 51+++++++++++++++++++++++++++++++--------------------
Mchrome/content/zotero/xpcom/data/item.js | 20++++++++++++++++++--
2 files changed, 49 insertions(+), 22 deletions(-)

diff --git a/chrome/content/zotero/bindings/tagsbox.xml b/chrome/content/zotero/bindings/tagsbox.xml @@ -411,12 +411,9 @@ var fieldName = 'tag'; var tabindex = textbox.getAttribute('ztabindex'); - - //var value = t.value; + var value = textbox.value; - var elem; - var tagsbox = Zotero.getAncestorByTagName(textbox, 'tagsbox'); if (!tagsbox) { @@ -462,7 +459,34 @@ value = value.replace('\r\n','\n'); value = value.replace('\r','\n'); var nameArray = value.split('\n'); + + var extremeTag = false; + var nextTag = false; + if (this._tabDirection == -1) { + if (this._lastTabIndex == 1) { + extremeTag = true; + } else { + nextTag = row.previousSibling.getAttribute('id').split('-')[1]; + } + } else if (this._tabDirection == 1) { + if (this._lastTabIndex >= this.item.getTags().length) { + extremeTag = true; + } else { + nextTag = row.nextSibling.getAttribute('id').split('-')[1]; + } + } + id = this.item.addTags(nameArray); + + if (extremeTag) { + if (this._tabDirection == 1) { + this._lastTabIndex = this.item.getTags().length; + } else if (this._tabDirection == -1) { + this._lastTabIndex = 2; + } + } else { + this._lastTabIndex = this.item.getTagIndex(nextTag)+1-this._tabDirection; + } } else { id = tagsbox.add(value); @@ -474,7 +498,7 @@ } if (id) { - elem = this.createValueElement( + var elem = this.createValueElement( value, tabindex ); @@ -492,22 +516,10 @@ catch (e) {} } - var focusMode = 'tags'; var focusBox = tagsbox; - //Move at least one field even if no entry was added because of - //the way bookkeeping is done above - var fieldsToMove = 1; - //Check if id is an array and, if so, how many new entries - //were added at once - if (Object.prototype.toString.call(id) === '[object Array]') { - fieldsToMove = id.length; - } - if (this._tabDirection) { - for (var i = 0; i < fieldsToMove; i++) { - this._focusNextField(focusBox, this._lastTabIndex, this._tabDirection == -1); - } + this._focusNextField(focusBox, this._lastTabIndex, this._tabDirection == -1); } ]]> </body> @@ -752,4 +764,4 @@ </xul:scrollbox> </content> </binding> -</bindings> -\ No newline at end of file +</bindings> diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js @@ -1,7 +1,7 @@ /* ***** BEGIN LICENSE BLOCK ***** - Copyright © 2009 Center for History and New Media + Copyright ¬© 2009 Center for History and New Media George Mason University, Fairfax, Virginia, USA http://zotero.org @@ -2703,7 +2703,7 @@ Zotero.Item.prototype.getFile = function(row, skipExistsCheck) { // Strip "storage:" var path = row.path.substr(8); // setRelativeDescriptor() silently uses the parent directory on Windows - // if the filename contains certain characters, so strip them — + // if the filename contains certain characters, so strip them ‚Äî // but don't skip characters outside of XML range, since they may be // correct in the opaque relative descriptor string // @@ -3637,6 +3637,22 @@ Zotero.Item.prototype.getTagIDs = function() { return Zotero.DB.columnQuery(sql, this.id); } +//Return the index of tagID in the list of the item's tags +//sorted in alphabetical order. +Zotero.Item.prototype.getTagIndex = function(tagID) { + var tags = this.getTags(); + + var tagIndex=-1; + for (var i=0;i<tags.length;i++) { + if (tagID == tags[i].id) { + tagIndex=i; + break; + } + } + + return tagIndex; +} + Zotero.Item.prototype.replaceTag = function(oldTagID, newTag) { if (!this.id) { throw ('Cannot replace tag on unsaved item');