From 3988bce5ac81faba08d1a12353b779d519a96966 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 15 Dec 2006 23:06:36 +0000 Subject: [PATCH] Closes #446, either add icons for new item types or implement a function to get the image src for a given item type Adds Item.getImageSrc() and ItemTypes.getImageSrc(string itemType) --- chrome/content/zotero/xpcom/data_access.js | 67 +++++++++++++++++++++ chrome/content/zotero/xpcom/itemTreeView.js | 66 +------------------- 2 files changed, 68 insertions(+), 65 deletions(-) diff --git a/chrome/content/zotero/xpcom/data_access.js b/chrome/content/zotero/xpcom/data_access.js index 771f23a92..87d721750 100644 --- a/chrome/content/zotero/xpcom/data_access.js +++ b/chrome/content/zotero/xpcom/data_access.js @@ -1670,6 +1670,32 @@ Zotero.Item.prototype.getSeeAlso = function(){ } +Zotero.Item.prototype.getImageSrc = function() { + var itemType = Zotero.ItemTypes.getName(this.getType()); + if (itemType == 'attachment') { + var linkMode = this.getAttachmentLinkMode(); + if (linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_FILE) { + itemType = itemType + "-file"; + } + else if (linkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE) { + itemType = itemType + "-link"; + } + else if (linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_URL) { + itemType = itemType + "-snapshot"; + } + else if (linkMode == Zotero.Attachments.LINK_MODE_LINKED_URL) { + itemType = itemType + "-web-link"; + } + } + + if (itemType == 'note' && this.isAbstract()) { + itemType = 'note-abstract'; + } + + return Zotero.ItemTypes.getImageSrc(itemType); +} + + /** * Delete item from database and clear from Zotero.Items internal array **/ @@ -3251,6 +3277,7 @@ Zotero.ItemTypes = new function(){ this.getPrimaryTypes = getPrimaryTypes; this.getSecondaryTypes = getSecondaryTypes; this.getHiddenTypes = getHiddenTypes; + this.getImageSrc = getImageSrc; this._typeDesc = 'item type'; this._idCol = 'itemTypeID'; @@ -3268,6 +3295,46 @@ Zotero.ItemTypes = new function(){ function getHiddenTypes(){ return this.getTypes('WHERE display=0'); } + + function getImageSrc(itemType) { + // DEBUG: only have icons for some types so far + switch (itemType) { + case 'attachment-file': + case 'attachment-link': + case 'attachment-snapshot': + case 'attachment-web-link': + case 'artwork': + case 'audioRecording': + case 'blogPost': + case 'book': + case 'bookSection': + case 'computerProgram': + case 'conferencePaper': + case 'email': + case 'film': + case 'forumPost': + case 'interview': + case 'journalArticle': + case 'letter': + case 'magazineArticle': + case 'manuscript': + case 'map': + case 'newspaperArticle': + case 'note': + case 'note-abstract': + case 'podcast': + case 'radioBroadcast': + case 'report': + case 'thesis': + case 'tvBroadcast': + case 'videoRecording': + case 'webpage': + + return "chrome://zotero/skin/treeitem-" + itemType + ".png"; + } + + return "chrome://zotero/skin/treeitem.png"; + } } diff --git a/chrome/content/zotero/xpcom/itemTreeView.js b/chrome/content/zotero/xpcom/itemTreeView.js index 183fc7eca..cf590d69f 100644 --- a/chrome/content/zotero/xpcom/itemTreeView.js +++ b/chrome/content/zotero/xpcom/itemTreeView.js @@ -328,71 +328,7 @@ Zotero.ItemTreeView.prototype.getImageSrc = function(row, col) { if(col.id == 'zotero-items-title-column') { - var item = this._getItemAtRow(row); - var itemType = Zotero.ItemTypes.getName(item.getType()); - if(itemType == 'attachment') - { - var linkMode = item.ref.getAttachmentLinkMode(); - if(linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_FILE) - { - itemType = itemType + "-file"; - } - else if(linkMode == Zotero.Attachments.LINK_MODE_LINKED_FILE) - { - itemType = itemType + "-link"; - } - else if(linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_URL) - { - itemType = itemType + "-snapshot"; - } - else if(linkMode == Zotero.Attachments.LINK_MODE_LINKED_URL) - { - itemType = itemType + "-web-link"; - } - } - - if (itemType == 'note' && item.ref.isAbstract()) { - itemType = 'note-abstract'; - } - - // DEBUG: only have icons for some types so far - switch (itemType) - { - case 'attachment-file': - case 'attachment-link': - case 'attachment-snapshot': - case 'attachment-web-link': - case 'artwork': - case 'audioRecording': - case 'blogPost': - case 'book': - case 'bookSection': - case 'computerProgram': - case 'conferencePaper': - case 'email': - case 'film': - case 'forumPost': - case 'interview': - case 'journalArticle': - case 'letter': - case 'magazineArticle': - case 'manuscript': - case 'map': - case 'newspaperArticle': - case 'note': - case 'note-abstract': - case 'podcast': - case 'radioBroadcast': - case 'report': - case 'thesis': - case 'tvBroadcast': - case 'videoRecording': - case 'webpage': - - return "chrome://zotero/skin/treeitem-"+itemType+".png"; - } - - return "chrome://zotero/skin/treeitem.png"; + return this._getItemAtRow(row).ref.getImageSrc(); } }