From 76b5e135b23243aacd86b8aafe9b88c04b8df72d Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Tue, 8 Sep 2009 19:12:23 +0000 Subject: [PATCH] Function left out of previous commit --- chrome/content/zotero/xpcom/data/item.js | 35 +++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js index 8980c43d52..4d79b15362 100644 --- a/chrome/content/zotero/xpcom/data/item.js +++ b/chrome/content/zotero/xpcom/data/item.js @@ -2002,7 +2002,7 @@ Zotero.Item.prototype.getSource = function() { } var sourceItem = Zotero.Items.getByLibraryAndKey(this.libraryID, this._sourceItem); if (!sourceItem) { - var msg = "Source item for keyed source doesn't exist in Zotero.Item.getSource()"; + var msg = "Source item for keyed source doesn't exist in Zotero.Item.getSource() " + "(" + this._sourceItem + ")"; var e = new Zotero.Error(msg, "MISSING_OBJECT"); throw (e); } @@ -2537,6 +2537,39 @@ Zotero.Item.prototype.getFile = function(row, skipExistsCheck) { } +/** + * _row_ is optional itemAttachments row if available to skip queries + */ +Zotero.Item.prototype.getFilename = function (row) { + if (!this.isAttachment()) { + throw ("getFileName() can only be called on attachment items in Zotero.Item.getFilename()"); + } + + if (!row) { + var row = { + linkMode: this.attachmentLinkMode, + path: this.attachmentPath + }; + } + + if (row.linkMode == Zotero.Attachments.LINK_MODE_LINKED_URL) { + throw ("getFilename() cannot be called on link attachments in Zotero.Item.getFilename()"); + } + + if (this.isImportedAttachment()) { + var matches = row.path.match("^storage:(.+)$"); + return matches[1]; + } + + var file = this.getFile(); + if (!file) { + return false; + } + + return file.leafName; +} + + /* * Rename file associated with an attachment *