Update data dir prefs for new default location

- Show "Default (<path>)" for default option unless set to profile directory
- Don't try to restart on selection if location hasn't changed
This commit is contained in:
Dan Stillman 2016-11-01 02:14:25 -04:00
parent a5b222edac
commit b22850efed
4 changed files with 83 additions and 26 deletions

View file

@ -32,6 +32,8 @@ Zotero_Preferences.Advanced = {
init: function () {
Zotero_Preferences.Debug_Output.init();
Zotero_Preferences.Keys.init();
this.onDataDirLoad();
},
revealDataDirectory: function () {
@ -190,9 +192,25 @@ Zotero_Preferences.Advanced = {
onDataDirLoad: function () {
var path = document.getElementById('dataDirPath');
var useDataDir = Zotero.Prefs.get('useDataDir');
path.setAttribute('disabled', !useDataDir);
var dataDir = Zotero.Prefs.get('lastDataDir') || Zotero.Prefs.get('dataDir');
var defaultDataDir = Zotero.getDefaultDataDir();
// Change "Use profile directory" label to home directory location unless using profile dir
if (useDataDir || Zotero.getZoteroDirectory().path == defaultDataDir) {
document.getElementById('defaultDataDir').setAttribute(
'label', Zotero.getString('dataDir.default', Zotero.getDefaultDataDir())
);
}
// Don't show custom data dir as in-use if set to the default
if (dataDir == defaultDataDir) {
useDataDir = false;
}
document.getElementById('dataDirPath').setAttribute('disabled', !useDataDir);
return useDataDir;
},
@ -201,20 +219,16 @@ Zotero_Preferences.Advanced = {
var useDataDir = Zotero.Prefs.get('useDataDir');
var newUseDataDir = radiogroup.selectedIndex == 1;
if (newUseDataDir == useDataDir && !useDataDir) {
if (newUseDataDir && !this._usingDefaultDataDir()) {
return;
}
// This call shows a filepicker if needed,
// forces a restart if required
// and does nothing if cancel was pressed
// This call shows a filepicker if needed, forces a restart if required, and does nothing if
// cancel was pressed or value hasn't changed
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;
radiogroup.selectedIndex = this._usingDefaultDataDir() ? 0 : 1;
},
@ -227,7 +241,30 @@ Zotero_Preferences.Advanced = {
getDataDirPath: function () {
// TEMP: lastDataDir can be removed once old persistent descriptors have been
// converted, which they are in getZoteroDirectory() in 5.0
return Zotero.Prefs.get('lastDataDir') || Zotero.Prefs.get('dataDir') || '';
var prefValue = Zotero.Prefs.get('lastDataDir') || Zotero.Prefs.get('dataDir');
// Don't show path if the default
if (prefValue == Zotero.getDefaultDataDir()) {
return '';
}
return prefValue || '';
},
_usingDefaultDataDir: function () {
// Legacy profile directory location
if (!Zotero.Prefs.get('useDataDir')) {
return true;
}
var dataDir = Zotero.Prefs.get('lastDataDir') || Zotero.Prefs.get('dataDir');
// Default home directory location
if (dataDir == Zotero.getDefaultDataDir()) {
return true;
}
return false;
},

View file

@ -184,9 +184,9 @@
<radiogroup id="dataDir"
preference="pref-useDataDir"
onsyncfrompreference="Zotero_Preferences.Advanced.onDataDirLoad();"
onsyncfrompreference="return Zotero_Preferences.Advanced.onDataDirLoad()"
onsynctopreference="return Zotero_Preferences.Advanced.onDataDirUpdate(event);">
<radio label="&zotero.preferences.dataDir.useProfile;" value="false"/>
<radio id="defaultDataDir" label="&zotero.preferences.dataDir.useProfile;" value="false"/>
<hbox>
<radio label="&zotero.preferences.dataDir.custom;" value="true"/>
<textbox id="dataDirPath" preference="pref-dataDir"

View file

@ -290,11 +290,11 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
Zotero.startupError + '\n\n' +
Zotero.getString('dataDir.previousDir') + ' ' + previousDir,
buttonFlags, null,
Zotero.getString('dataDir.useProfileDir', Zotero.appName),
Zotero.getString('dataDir.useDefaultLocation'),
Zotero.getString('general.locate'),
null, {});
// Revert to profile directory
// Revert to home directory
if (index == 1) {
Zotero.chooseZoteroDirectory(false, true);
}
@ -921,9 +921,9 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
return _zoteroDirectory.clone();
}
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
if (Zotero.Prefs.get('useDataDir')) {
var file = Components.classes["@mozilla.org/file/local;1"].
createInstance(Components.interfaces.nsILocalFile);
let prefVal = Zotero.Prefs.get('dataDir');
// Convert old persistent descriptor pref to string path and clear obsolete lastDataDir pref
//
@ -960,8 +960,7 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
}
}
else {
let homeDir = OS.Constants.Path.homeDir;
let dataDir = OS.Path.join(homeDir, ZOTERO_CONFIG.CLIENT_NAME);
let dataDir = this.getDefaultDataDir();
//
// TODO: asyncify
@ -1088,6 +1087,11 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
}
this.getDefaultDataDir = function () {
return OS.Path.join(OS.Constants.Path.homeDir, ZOTERO_CONFIG.CLIENT_NAME);
};
function getStorageDirectory(){
var file = Zotero.getZoteroDirectory();
@ -1145,12 +1149,15 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
}
function chooseZoteroDirectory(forceQuitNow, useProfileDir, moreInfoCallback) {
function chooseZoteroDirectory(forceQuitNow, useHomeDir, moreInfoCallback) {
var win = Services.wm.getMostRecentWindow('navigator:browser');
var ps = Services.prompt;
if (useProfileDir) {
Zotero.Prefs.set('useDataDir', false);
if (useHomeDir) {
let changed = this.setDataDirectory(this.getDefaultDataDir());
if (!changed) {
return false;
}
}
else {
var nsIFilePicker = Components.interfaces.nsIFilePicker;
@ -1164,7 +1171,12 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
var file = fp.file;
let dialogText = '';
let dialogTitle = '';
if (file.path == (Zotero.Prefs.get('lastDataDir') || Zotero.Prefs.get('dataDir'))) {
Zotero.debug("Data directory hasn't changed");
return false;
}
// In dropbox folder
if (Zotero.File.isDropboxDirectory(file.path)) {
dialogTitle = Zotero.getString('general.warning');
@ -1242,7 +1254,7 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
Services.startup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit);
}
return useProfileDir ? true : file;
return useHomeDir ? true : file;
}
@ -1309,11 +1321,18 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
}
/**
* @return {Boolean} - True if the directory changed; false otherwise
*/
this.setDataDirectory = function (path) {
var origPath = Zotero.Prefs.get('dataDir');
Zotero.Prefs.set('dataDir', path);
// Clear legacy pref
Zotero.Prefs.clear('lastDataDir');
Zotero.Prefs.set('useDataDir', true);
return path != origPath;
};

View file

@ -111,7 +111,8 @@ attachmentBasePath.clearBasePath.button = Clear Base Dire
dataDir.notFound = The Zotero data directory could not be found.
dataDir.previousDir = Previous directory:
dataDir.useProfileDir = Use %S profile directory
dataDir.default = Default (%S)
dataDir.useDefaultLocation = Use Default Location
dataDir.selectDir = Select a Zotero data directory
dataDir.selectNewDir = Select a new %S data directory
dataDir.changeDataDirectory = Change Data Directory…