www

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

commit b53423e8dd3462d51ac6e3dcbed955e9e6ac3e43
parent a47390b5c41da7a2c5a409200aef4cff8cd267e2
Author: Dan Stillman <dstillman@zotero.org>
Date:   Fri, 15 Apr 2011 14:46:21 +0000

Tag colors, as in http://forums.zotero.org/discussion/1787/1/simple-marking-of-items/

Should be considered proof-of-concept at this stage, with refinements needed

(Among other things, no handling of multiple tags per item)


Diffstat:
Mchrome/content/zotero/bindings/tagselector.xml | 43+++++++++++++++++++++++++++++++++++++++++--
Mchrome/content/zotero/xpcom/data/tags.js | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mchrome/content/zotero/xpcom/itemTreeView.js | 22++++++++++++++++++----
Mchrome/content/zotero/xpcom/notifier.js | 2+-
Mchrome/skin/default/zotero/overlay.css | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 204 insertions(+), 7 deletions(-)

diff --git a/chrome/content/zotero/bindings/tagselector.xml b/chrome/content/zotero/bindings/tagselector.xml @@ -258,6 +258,7 @@ // Set attributes var labels = tagsToggleBox.getElementsByTagName('label'); + var tagColors = Zotero.Tags.getColors(); for (var i=0; i<labels.length; i++){ var tagIDs = labels[i].getAttribute('tagID').split('-'); @@ -333,6 +334,13 @@ labels[i].setAttribute('hidden', false); empty = false; } + + if (color = tagColors[labels[i].value]) { + labels[i].setAttribute('style', 'color:' + color); + } + else { + labels[i].removeAttribute('style'); + } } //start tag cloud code @@ -684,6 +692,31 @@ </body> </method> + <method name="getColor"> + <parameter name="tagIDs"/> + <body> + <![CDATA[ + tagIDs = tagIDs.split('-'); + var name = Zotero.Tags.getName(tagIDs[0]); + return Zotero.Tags.getColor(name); + ]]> + </body> + </method> + + + <method name="setColor"> + <parameter name="tagIDs"/> + <parameter name="color"/> + <body> + <![CDATA[ + tagIDs = tagIDs.split('-'); + var name = Zotero.Tags.getName(tagIDs[0]); + Zotero.Tags.setColor(name, color); + this.refresh(); + ]]> + </body> + </method> + <method name="focusTextbox"> <body> <![CDATA[ @@ -784,8 +817,14 @@ <content> <xul:groupbox flex="1"> <xul:menupopup id="tag-menu"> - <xul:menuitem label="&zotero.tagSelector.renameTag;" class="menuitem-non-iconic" oncommand="document.getBindingParent(this).rename(document.popupNode.getAttribute('tagID')); event.stopPropagation()"/> - <xul:menuitem label="&zotero.tagSelector.deleteTag;" class="menuitem-non-iconic" oncommand="document.getBindingParent(this).delete(document.popupNode.getAttribute('tagID')); event.stopPropagation()"/> + <xul:menuitem label="&zotero.tagSelector.renameTag;" oncommand="document.getBindingParent(this).rename(document.popupNode.getAttribute('tagID')); event.stopPropagation()"/> + <xul:menuitem label="&zotero.tagSelector.deleteTag;" oncommand="document.getBindingParent(this).delete(document.popupNode.getAttribute('tagID')); event.stopPropagation()"/> + <!-- TODO: localized --> + <xul:menu label="Assign Color"> + <xul:menupopup onpopupshowing="var color = document.getBindingParent(this).getColor(document.popupNode.getAttribute('tagID')); this.children[0].color = color"> + <xul:colorpicker onclick="document.getBindingParent(this).setColor(document.popupNode.getAttribute('tagID'), event.originalTarget.getAttribute('color')); document.getBindingParent(this).id('tag-menu').hidePopup(); event.stopPropagation()"/> + </xul:menupopup> + </xul:menu> </xul:menupopup> <xul:vbox id="no-tags-box" align="center" pack="center" flex="1"> diff --git a/chrome/content/zotero/xpcom/data/tags.js b/chrome/content/zotero/xpcom/data/tags.js @@ -32,6 +32,7 @@ Zotero.Tags = new function() { this.constructor.prototype = new Zotero.DataObjects(); var _tags = {}; // indexed by tag text + var _colorsByItem = {}; this.get = get; this.getName = getName; @@ -385,6 +386,76 @@ Zotero.Tags = new function() { } + this.getColor = function (name) { + var tagColors = this.getColors(); + return tagColors[name] ? tagColors[name] : '#000000'; + } + + + this.getColors = function (name) { + var tagColors = Zotero.Prefs.get('tagColors'); + return tagColors ? JSON.parse(tagColors) : {}; + } + + + this.getItemColor = function (itemID) { + var item = Zotero.Items.get(itemID); + if (!item) { + return false; + } + + // Init library tag colors if not yet done + var libraryID = item.libraryID ? item.libraryID : 0; + if (!_colorsByItem[libraryID]) { + _colorsByItem[libraryID] = {}; + var tagColors = this.getColors(); + for (var name in tagColors) { + var color = tagColors[name]; + var tagIDs = Zotero.Tags.getIDs(name, libraryID); + if (!tagIDs) { + continue; + } + for each(var tagID in tagIDs) { + var tag = Zotero.Tags.get(tagID); + var itemIDs = tag.getLinkedItems(true); + if (!itemIDs) { + continue; + } + for each(var id in itemIDs) { + _colorsByItem[libraryID][id] = color; + } + } + } + } + + return _colorsByItem[libraryID][itemID] ? _colorsByItem[libraryID][itemID] : false; + } + + + this.setColor = function (name, color) { + var tagColors = this.getColors(); + + // Unset + if (!color || color == '#000000') { + delete tagColors[name]; + } + else { + tagColors[name] = color; + } + + tagColors = JSON.stringify(tagColors); + Zotero.Prefs.set('tagColors', tagColors); + + _reloadTagColors() + Zotero.Notifier.trigger('redraw', 'item', []); + } + + + function _reloadTagColors() { + _colorsByItem = {}; + } + + function erase(ids) { ids = Zotero.flattenArguments(ids); @@ -488,6 +559,7 @@ Zotero.Tags = new function() { */ this._reload = function (ids) { _tags = {}; + _reloadTagColors(); } diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js @@ -277,6 +277,12 @@ Zotero.ItemTreeView.prototype.notify = function(action, type, ids, extraData) var savedSelection = this.saveSelection(); + // Redraw the tree (for tag color changes) + if (action == 'redraw') { + this._treebox.invalidate(); + return; + } + // If refreshing a single item, just unselect and reselect it if (action == 'refresh') { if (type == 'share-items') { @@ -2410,11 +2416,19 @@ Zotero.ItemTreeView.prototype.onDragExit = function (event) { Zotero.ItemTreeView.prototype.isSeparator = function(row) { return false; } Zotero.ItemTreeView.prototype.getRowProperties = function(row, prop) { } -Zotero.ItemTreeView.prototype.getColumnProperties = function(col, prop) { } - -/* Mark items not matching search as context rows, displayed in gray */ +Zotero.ItemTreeView.prototype.getColumnProperties = function(col, prop) { } Zotero.ItemTreeView.prototype.getCellProperties = function(row, col, prop) { - if (this._searchMode && !this._searchItemIDs[this._getItemAtRow(row).ref.id]) { + var itemID = this._getItemAtRow(row).ref.id; + + // Set tag colors + if (color = Zotero.Tags.getItemColor(itemID)) { + var aServ = Components.classes["@mozilla.org/atom-service;1"]. + getService(Components.interfaces.nsIAtomService); + prop.AppendElement(aServ.getAtom("color" + color.substr(1))); + } + + // Mark items not matching search as context rows, displayed in gray + if (this._searchMode && !this._searchItemIDs[itemID]) { var aServ = Components.classes["@mozilla.org/atom-service;1"]. getService(Components.interfaces.nsIAtomService); prop.AppendElement(aServ.getAtom("contextRow")); diff --git a/chrome/content/zotero/xpcom/notifier.js b/chrome/content/zotero/xpcom/notifier.js @@ -89,7 +89,7 @@ Zotero.Notifier = new function(){ * Possible values: * * event: 'add', 'modify', 'delete', 'move' ('c', for changing parent), - * 'remove' (ci, it), 'refresh', 'trash' + * 'remove' (ci, it), 'refresh', 'redraw', 'trash' * type - 'collection', 'search', 'item', 'collection-item', 'item-tag', 'tag', 'group' * ids - single id or array of ids * diff --git a/chrome/skin/default/zotero/overlay.css b/chrome/skin/default/zotero/overlay.css @@ -70,6 +70,78 @@ margin-right: 5px; } +/* Set tag colors */ +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFFFFFF) { color:#FFFFFF } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFFCCCC) { color:#FFCCCC } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFFCC99) { color:#FFCC99 } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFFFF99) { color:#FFFF99 } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFFFFCC) { color:#FFFFCC } +#zotero-items-tree treechildren::-moz-tree-cell-text(color99FF99) { color:#99FF99 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color99FFFF) { color:#99FFFF } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorCCFFFF) { color:#CCFFFF } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorCCCCFF) { color:#CCCCFF } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFFCCFF) { color:#FFCCFF } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorCCCCCC) { color:#CCCCCC } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFF6666) { color:#FF6666 } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFF9966) { color:#FF9966 } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFFFF66) { color:#FFFF66 } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFFFF33) { color:#FFFF33 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color66FF99) { color:#66FF99 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color33FFFF) { color:#33FFFF } +#zotero-items-tree treechildren::-moz-tree-cell-text(color66FFFF) { color:#66FFFF } +#zotero-items-tree treechildren::-moz-tree-cell-text(color9999FF) { color:#9999FF } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFF99FF) { color:#FF99FF } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorC0C0C0) { color:#C0C0C0 } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFF0000) { color:#FF0000 } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFF9900) { color:#FF9900 } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFFCC66) { color:#FFCC66 } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFFFF00) { color:#FFFF00 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color33FF33) { color:#33FF33 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color66CCCC) { color:#66CCCC } +#zotero-items-tree treechildren::-moz-tree-cell-text(color33CCFF) { color:#33CCFF } +#zotero-items-tree treechildren::-moz-tree-cell-text(color6666CC) { color:#6666CC } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorCC66CC) { color:#CC66CC } +#zotero-items-tree treechildren::-moz-tree-cell-text(color999999) { color:#999999 } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorCC0000) { color:#CC0000 } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFF6600) { color:#FF6600 } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFFCC33) { color:#FFCC33 } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorFFCC00) { color:#FFCC00 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color33CC00) { color:#33CC00 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color00CCCC) { color:#00CCCC } +#zotero-items-tree treechildren::-moz-tree-cell-text(color3366FF) { color:#3366FF } +#zotero-items-tree treechildren::-moz-tree-cell-text(color6633FF) { color:#6633FF } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorCC33CC) { color:#CC33CC } +#zotero-items-tree treechildren::-moz-tree-cell-text(color666666) { color:#666666 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color990000) { color:#990000 } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorCC6600) { color:#CC6600 } +#zotero-items-tree treechildren::-moz-tree-cell-text(colorCC9933) { color:#CC9933 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color999900) { color:#999900 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color009900) { color:#009900 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color339999) { color:#339999 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color3333FF) { color:#3333FF } +#zotero-items-tree treechildren::-moz-tree-cell-text(color6600CC) { color:#6600CC } +#zotero-items-tree treechildren::-moz-tree-cell-text(color993399) { color:#993399 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color333333) { color:#333333 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color660000) { color:#660000 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color993300) { color:#993300 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color996633) { color:#996633 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color666600) { color:#666600 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color006600) { color:#006600 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color336666) { color:#336666 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color000099) { color:#000099 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color333399) { color:#333399 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color663366) { color:#663366 } +/*#zotero-items-tree treechildren::-moz-tree-cell-text(color000000) { color:#000000 }*/ +#zotero-items-tree treechildren::-moz-tree-cell-text(color330000) { color:#330000 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color663300) { color:#663300 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color663333) { color:#663333 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color333300) { color:#333300 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color003300) { color:#003300 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color003333) { color:#003333 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color000066) { color:#000066 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color330099) { color:#330099 } +#zotero-items-tree treechildren::-moz-tree-cell-text(color330033) { color:#330033 } + /* Style search results, display non-matches in gray */ #zotero-items-tree treechildren::-moz-tree-cell-text(contextRow) { color: gray;