From d68d510547a203ec54826671a2fd061d0e98792e Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 21 Feb 2013 06:22:26 -0500 Subject: [PATCH] Move relative paths pref code into its own object --- .../content/zotero/preferences/preferences.js | 502 +++++++++--------- .../zotero/preferences/preferences.xul | 6 +- 2 files changed, 256 insertions(+), 252 deletions(-) diff --git a/chrome/content/zotero/preferences/preferences.js b/chrome/content/zotero/preferences/preferences.js index bcfaf81759..56968d3ef6 100644 --- a/chrome/content/zotero/preferences/preferences.js +++ b/chrome/content/zotero/preferences/preferences.js @@ -130,255 +130,6 @@ function init() } -function chooseBaseAttachmentPath() { - // Get existing base directory - var oldBasePath = Zotero.Prefs.get('baseAttachmentPath'); - if (oldBasePath) { - var oldBasePathFile = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); - try { - oldBasePathFile.persistentDescriptor = oldBasePath; - } - catch (e) { - Zotero.debug(e, 1); - Components.utils.reportError(e); - oldBasePathFile = null; - } - } - - //Prompt user to choose new base path - var nsIFilePicker = Components.interfaces.nsIFilePicker; - var fp = Components.classes["@mozilla.org/filepicker;1"] - .createInstance(nsIFilePicker); - if (oldBasePathFile) { - fp.displayDirectory = oldBasePathFile; - } - fp.init(window, Zotero.getString('attachmentBasePath.selectDir'), nsIFilePicker.modeGetFolder); - fp.appendFilters(nsIFilePicker.filterAll); - if (fp.show() != nsIFilePicker.returnOK) { - return false; - } - var newBasePathFile = fp.file; - - if (oldBasePathFile && oldBasePathFile.equals(newBasePathFile)) { - Zotero.debug("Base directory hasn't changed"); - return false; - } - - // 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) || []; - - //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 newAttachmentPaths = {}; - var numNewAttachments = 0; - var numOldAttachments = 0; - var attachmentFile = Components.classes["@mozilla.org/file/local;1"] - .createInstance(Components.interfaces.nsILocalFile); - for (let i=0; i