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:
parent
a5b222edac
commit
b22850efed
|
@ -32,6 +32,8 @@ Zotero_Preferences.Advanced = {
|
||||||
init: function () {
|
init: function () {
|
||||||
Zotero_Preferences.Debug_Output.init();
|
Zotero_Preferences.Debug_Output.init();
|
||||||
Zotero_Preferences.Keys.init();
|
Zotero_Preferences.Keys.init();
|
||||||
|
|
||||||
|
this.onDataDirLoad();
|
||||||
},
|
},
|
||||||
|
|
||||||
revealDataDirectory: function () {
|
revealDataDirectory: function () {
|
||||||
|
@ -190,9 +192,25 @@ Zotero_Preferences.Advanced = {
|
||||||
|
|
||||||
|
|
||||||
onDataDirLoad: function () {
|
onDataDirLoad: function () {
|
||||||
var path = document.getElementById('dataDirPath');
|
|
||||||
var useDataDir = Zotero.Prefs.get('useDataDir');
|
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 useDataDir = Zotero.Prefs.get('useDataDir');
|
||||||
var newUseDataDir = radiogroup.selectedIndex == 1;
|
var newUseDataDir = radiogroup.selectedIndex == 1;
|
||||||
|
|
||||||
if (newUseDataDir == useDataDir && !useDataDir) {
|
if (newUseDataDir && !this._usingDefaultDataDir()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This call shows a filepicker if needed,
|
// This call shows a filepicker if needed, forces a restart if required, and does nothing if
|
||||||
// forces a restart if required
|
// cancel was pressed or value hasn't changed
|
||||||
// and does nothing if cancel was pressed
|
|
||||||
Zotero.chooseZoteroDirectory(true, !newUseDataDir, function () {
|
Zotero.chooseZoteroDirectory(true, !newUseDataDir, function () {
|
||||||
Zotero_Preferences.openURL('http://zotero.org/support/zotero_data');
|
Zotero_Preferences.openURL('http://zotero.org/support/zotero_data');
|
||||||
});
|
});
|
||||||
useDataDir = Zotero.Prefs.get('useDataDir');
|
radiogroup.selectedIndex = this._usingDefaultDataDir() ? 0 : 1;
|
||||||
radiogroup.selectedIndex = useDataDir ? 1 : 0;
|
|
||||||
|
|
||||||
return useDataDir;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
@ -227,7 +241,30 @@ Zotero_Preferences.Advanced = {
|
||||||
getDataDirPath: function () {
|
getDataDirPath: function () {
|
||||||
// TEMP: lastDataDir can be removed once old persistent descriptors have been
|
// TEMP: lastDataDir can be removed once old persistent descriptors have been
|
||||||
// converted, which they are in getZoteroDirectory() in 5.0
|
// 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;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -184,9 +184,9 @@
|
||||||
|
|
||||||
<radiogroup id="dataDir"
|
<radiogroup id="dataDir"
|
||||||
preference="pref-useDataDir"
|
preference="pref-useDataDir"
|
||||||
onsyncfrompreference="Zotero_Preferences.Advanced.onDataDirLoad();"
|
onsyncfrompreference="return Zotero_Preferences.Advanced.onDataDirLoad()"
|
||||||
onsynctopreference="return Zotero_Preferences.Advanced.onDataDirUpdate(event);">
|
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>
|
<hbox>
|
||||||
<radio label="&zotero.preferences.dataDir.custom;" value="true"/>
|
<radio label="&zotero.preferences.dataDir.custom;" value="true"/>
|
||||||
<textbox id="dataDirPath" preference="pref-dataDir"
|
<textbox id="dataDirPath" preference="pref-dataDir"
|
||||||
|
|
|
@ -290,11 +290,11 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||||
Zotero.startupError + '\n\n' +
|
Zotero.startupError + '\n\n' +
|
||||||
Zotero.getString('dataDir.previousDir') + ' ' + previousDir,
|
Zotero.getString('dataDir.previousDir') + ' ' + previousDir,
|
||||||
buttonFlags, null,
|
buttonFlags, null,
|
||||||
Zotero.getString('dataDir.useProfileDir', Zotero.appName),
|
Zotero.getString('dataDir.useDefaultLocation'),
|
||||||
Zotero.getString('general.locate'),
|
Zotero.getString('general.locate'),
|
||||||
null, {});
|
null, {});
|
||||||
|
|
||||||
// Revert to profile directory
|
// Revert to home directory
|
||||||
if (index == 1) {
|
if (index == 1) {
|
||||||
Zotero.chooseZoteroDirectory(false, true);
|
Zotero.chooseZoteroDirectory(false, true);
|
||||||
}
|
}
|
||||||
|
@ -921,9 +921,9 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||||
return _zoteroDirectory.clone();
|
return _zoteroDirectory.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var file = Components.classes["@mozilla.org/file/local;1"]
|
||||||
|
.createInstance(Components.interfaces.nsILocalFile);
|
||||||
if (Zotero.Prefs.get('useDataDir')) {
|
if (Zotero.Prefs.get('useDataDir')) {
|
||||||
var file = Components.classes["@mozilla.org/file/local;1"].
|
|
||||||
createInstance(Components.interfaces.nsILocalFile);
|
|
||||||
let prefVal = Zotero.Prefs.get('dataDir');
|
let prefVal = Zotero.Prefs.get('dataDir');
|
||||||
// Convert old persistent descriptor pref to string path and clear obsolete lastDataDir pref
|
// 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 {
|
else {
|
||||||
let homeDir = OS.Constants.Path.homeDir;
|
let dataDir = this.getDefaultDataDir();
|
||||||
let dataDir = OS.Path.join(homeDir, ZOTERO_CONFIG.CLIENT_NAME);
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// TODO: asyncify
|
// 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(){
|
function getStorageDirectory(){
|
||||||
var file = Zotero.getZoteroDirectory();
|
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 win = Services.wm.getMostRecentWindow('navigator:browser');
|
||||||
var ps = Services.prompt;
|
var ps = Services.prompt;
|
||||||
|
|
||||||
if (useProfileDir) {
|
if (useHomeDir) {
|
||||||
Zotero.Prefs.set('useDataDir', false);
|
let changed = this.setDataDirectory(this.getDefaultDataDir());
|
||||||
|
if (!changed) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var nsIFilePicker = Components.interfaces.nsIFilePicker;
|
var nsIFilePicker = Components.interfaces.nsIFilePicker;
|
||||||
|
@ -1165,6 +1172,11 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||||
let dialogText = '';
|
let dialogText = '';
|
||||||
let dialogTitle = '';
|
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
|
// In dropbox folder
|
||||||
if (Zotero.File.isDropboxDirectory(file.path)) {
|
if (Zotero.File.isDropboxDirectory(file.path)) {
|
||||||
dialogTitle = Zotero.getString('general.warning');
|
dialogTitle = Zotero.getString('general.warning');
|
||||||
|
@ -1242,7 +1254,7 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||||
Services.startup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit);
|
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) {
|
this.setDataDirectory = function (path) {
|
||||||
|
var origPath = Zotero.Prefs.get('dataDir');
|
||||||
|
|
||||||
Zotero.Prefs.set('dataDir', path);
|
Zotero.Prefs.set('dataDir', path);
|
||||||
// Clear legacy pref
|
// Clear legacy pref
|
||||||
Zotero.Prefs.clear('lastDataDir');
|
Zotero.Prefs.clear('lastDataDir');
|
||||||
Zotero.Prefs.set('useDataDir', true);
|
Zotero.Prefs.set('useDataDir', true);
|
||||||
|
|
||||||
|
return path != origPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,8 @@ attachmentBasePath.clearBasePath.button = Clear Base Dire
|
||||||
|
|
||||||
dataDir.notFound = The Zotero data directory could not be found.
|
dataDir.notFound = The Zotero data directory could not be found.
|
||||||
dataDir.previousDir = Previous directory:
|
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.selectDir = Select a Zotero data directory
|
||||||
dataDir.selectNewDir = Select a new %S data directory
|
dataDir.selectNewDir = Select a new %S data directory
|
||||||
dataDir.changeDataDirectory = Change Data Directory…
|
dataDir.changeDataDirectory = Change Data Directory…
|
||||||
|
|
Loading…
Reference in New Issue
Block a user