From b75cc8f9d0cccc03bec937121e230ddeb3785fa4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Wed, 4 Nov 2015 19:30:25 +0000 Subject: [PATCH] Closes #437, Detect when data directory is in Dropbox Display a warning when choosing data directory Or on opening Zotero Pane for existing users with data dir in dropbox Also: Fix a bug where it won't use custom path if "Choose..." button is pressed instead of radio button. Change filepicker to show current data directory on display --- chrome/content/zotero/overlay.js | 4 + .../preferences/preferences_advanced.js | 61 ++++-------- .../preferences/preferences_advanced.xul | 5 +- chrome/content/zotero/xpcom/file.js | 5 + chrome/content/zotero/xpcom/zotero.js | 96 ++++++++++++------- chrome/locale/en-US/zotero/zotero.properties | 4 + defaults/preferences/zotero.js | 1 + 7 files changed, 92 insertions(+), 84 deletions(-) diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js index 8de42e036..91fe971f6 100644 --- a/chrome/content/zotero/overlay.js +++ b/chrome/content/zotero/overlay.js @@ -210,6 +210,10 @@ var ZoteroOverlay = new function() // Make visible ZoteroPane.makeVisible(); + // Warn about unsafe data directory on first display + let dataDir = Zotero.getZoteroDirectory(); + Zotero.checkForUnsafeDataDirectory(dataDir.path); + // Make sure tags splitter isn't missing for people upgrading from <2.0b7 document.getElementById('zotero-tags-splitter').collapsed = false; } else { diff --git a/chrome/content/zotero/preferences/preferences_advanced.js b/chrome/content/zotero/preferences/preferences_advanced.js index e5eee6659..de4ea80f6 100644 --- a/chrome/content/zotero/preferences/preferences_advanced.js +++ b/chrome/content/zotero/preferences/preferences_advanced.js @@ -198,59 +198,32 @@ Zotero_Preferences.Advanced = { onDataDirUpdate: function (event) { var radiogroup = document.getElementById('dataDir'); - var path = document.getElementById('dataDirPath'); var useDataDir = Zotero.Prefs.get('useDataDir'); + var newUseDataDir = radiogroup.selectedIndex == 1; - // If triggered from the Choose button, don't show the dialog, since - // Zotero.chooseZoteroDirectory() (called below due to the radio button - // change) shows its own - if (event.originalTarget && event.originalTarget.tagName == 'button') { - return true; + if (newUseDataDir == useDataDir && !useDataDir) { + return; } - - // If changing from default to custom - if (!useDataDir) { - event.stopPropagation(); - var file = Zotero.chooseZoteroDirectory(true, false, function () { - Zotero_Preferences.openURL('http://zotero.org/support/zotero_data'); - }); - radiogroup.selectedIndex = file ? 1 : 0; - return !!file; - } - - var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Components.interfaces.nsIPromptService); - var buttonFlags = ps.BUTTON_POS_0 * ps.BUTTON_TITLE_IS_STRING - + ps.BUTTON_POS_1 * ps.BUTTON_TITLE_CANCEL - + ps.BUTTON_POS_2 * ps.BUTTON_TITLE_IS_STRING; - var app = Zotero.appName; - var index = ps.confirmEx(window, - Zotero.getString('general.restartRequired'), - Zotero.getString('general.restartRequiredForChange', app) + '\n\n' - + Zotero.getString('dataDir.moveFilesToNewLocation', app), - buttonFlags, - Zotero.getString('general.quitApp', app), - null, - Zotero.getString('general.moreInformation'), - null, {}); - - if (index == 0) { - useDataDir = !!radiogroup.selectedIndex; - // quit() is asynchronous, but set this here just in case - Zotero.Prefs.set('useDataDir', useDataDir); - var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"] - .getService(Components.interfaces.nsIAppStartup); - appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit); - } - else if (index == 2) { + + // This call shows a filepicker if needed, + // forces a restart if required + // and does nothing if cancel was pressed + Zotero.chooseZoteroDirectory(true, !newUseDataDir, function () { Zotero_Preferences.openURL('http://zotero.org/support/zotero_data'); - } - + }); + useDataDir = Zotero.Prefs.get('useDataDir'); radiogroup.selectedIndex = useDataDir ? 1 : 0; + return useDataDir; }, + chooseDataDir: function(event) { + document.getElementById('dataDir').selectedIndex = 1; + //this.onDataDirUpdate(event); + }, + + getDataDirPath: function () { var desc = Zotero.Prefs.get('dataDir'); if (desc == '') { diff --git a/chrome/content/zotero/preferences/preferences_advanced.xul b/chrome/content/zotero/preferences/preferences_advanced.xul index 630aa07f1..6ffc2eda5 100644 --- a/chrome/content/zotero/preferences/preferences_advanced.xul +++ b/chrome/content/zotero/preferences/preferences_advanced.xul @@ -181,10 +181,7 @@ onsyncfrompreference="return Zotero_Preferences.Advanced.getDataDirPath();" readonly="true" flex="1"/>