www

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

commit 7cfa857887033cef2c5137d2d5ffc212ff6b13d4
parent 90286d2a509e5fa2d36b8c15d0e3687fa3041e87
Author: Dan Stillman <dstillman@zotero.org>
Date:   Thu, 29 Oct 2015 02:33:25 -0400

Make Zotero.Item::attachmentFilename work without file

And have getFilePath() return false instead of failing on unsaved items

Diffstat:
Mchrome/content/zotero/xpcom/data/item.js | 16++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/chrome/content/zotero/xpcom/data/item.js b/chrome/content/zotero/xpcom/data/item.js @@ -1979,6 +1979,11 @@ Zotero.Item.prototype.getFilePath = function () { return false; } + if (!this._identified) { + Zotero.debug("Can't get file path for unsaved file"); + return false; + } + // Imported file with relative path if (linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_URL || linkMode == Zotero.Attachments.LINK_MODE_IMPORTED_FILE) { @@ -2560,11 +2565,15 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentFilename', { if (!this.isAttachment()) { return undefined; } - var file = this.getFile(); - if (!file) { + var path = this.attachmentPath; + if (!path) { return ''; } - return file.leafName; + var prefixedPath = path.match(/^(?:attachments|storage):(.+)$/); + if (prefixedPath) { + return prefixedPath[1]; + } + return OS.Path.basename(path); }, set: function (val) { if (!this.isAttachment()) { @@ -2655,7 +2664,6 @@ Zotero.defineProperty(Zotero.Item.prototype, 'attachmentPath', { this._changed.attachmentData = {}; } this._changed.attachmentData.path = true; - this._attachmentPath = val; } });