From b224c5cf66e31d6a527957d35c2620b59e9c03aa Mon Sep 17 00:00:00 2001 From: Will S Date: Fri, 20 Jan 2012 18:36:04 -0500 Subject: [PATCH] Relative path support for linked files --- .../content/zotero/preferences/preferences.js | 154 ++++++++++++++++++ .../zotero/preferences/preferences.xul | 21 +++ chrome/content/zotero/xpcom/attachments.js | 1 + chrome/content/zotero/xpcom/data/item.js | 88 +++++++++- chrome/locale/en-US/zotero/preferences.dtd | 6 + chrome/locale/en-US/zotero/zotero.properties | 12 +- defaults/preferences/zotero.js | 2 + 7 files changed, 274 insertions(+), 10 deletions(-) diff --git a/chrome/content/zotero/preferences/preferences.js b/chrome/content/zotero/preferences/preferences.js index d47ba0809..fac8874e8 100644 --- a/chrome/content/zotero/preferences/preferences.js +++ b/chrome/content/zotero/preferences/preferences.js @@ -129,6 +129,160 @@ function init() } } +function chooseBaseAttachmentPath() { + var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] + .getService(Components.interfaces.nsIWindowMediator); + var win = wm.getMostRecentWindow('navigator:browser'); + + //Prompt user to choose new base path + var nsIFilePicker = Components.interfaces.nsIFilePicker; + var fp = Components.classes["@mozilla.org/filepicker;1"] + .createInstance(nsIFilePicker); + fp.init(win, Zotero.getString('attachmentBasePath.selectDir'), nsIFilePicker.modeGetFolder); + fp.appendFilters(nsIFilePicker.filterAll); + if (fp.show() != nsIFilePicker.returnOK) { + return false; + } + var basePathFile = fp.file; + + //Find all current attachments with relative attachment paths + var sql = "SELECT itemID FROM itemAttachments WHERE linkMode=? AND path LIKE '" + + Zotero.Attachments.BASE_PATH_PLACEHOLDER + "%'"; + var params=[Zotero.Attachments.LINK_MODE_LINKED_FILE]; + var oldRelativeAttachmentIDs = Zotero.DB.columnQuery(sql,params); + if (!oldRelativeAttachmentIDs) { + oldRelativeAttachmentIDs=[]; + } + + //Find all attachments on the new base path + var sql = "SELECT itemID FROM itemAttachments WHERE linkMode=?"; + var params=[Zotero.Attachments.LINK_MODE_LINKED_FILE]; + var allAttachments = Zotero.DB.columnQuery(sql,params); + var newRelativeAttachmentIDs = []; + var attachmentFile = Components.classes["@mozilla.org/file/local;1"] + .createInstance(Components.interfaces.nsILocalFile); + var tempAttachmentID,tempAttachment; + for (var index=0; index + @@ -725,6 +726,26 @@ To add a new preference: + + + + + + &zotero.preferences.attachments.message; + + + +