Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix window height bug in Zotero preferences, and reorganize code

Prefpanes are now in separate overlays, which fixes the age-old resizing
bug when switching between panes (at least on OS X) that varied
depending on the initial pane. Code has also been moved into
pane-specific files and objects, with strict mode enabled. When calling
code from another pane (e.g., for a UI update in another pane), first
check whether the Zotero_Preferences.[Pane] object exists--if it doesn't
then nothing needs to be called.

This change breaks the word integration plugin pref overlays, which
hopefully can be rewritten to work with either overlay format.

There is a good chance that this breaks some other things in the
preferences too.

Fixes #243
  • Loading branch information...
commit a417c9ef59071950bf371a2f72221bab3b771f98 1 parent 41e2f30
@dstillman dstillman authored
Showing with 3,753 additions and 3,115 deletions.
  1. +6 −1 chrome.manifest
  2. +59 −2,180 chrome/content/zotero/preferences/preferences.js
  3. +31 −813 chrome/content/zotero/preferences/preferences.xul
  4. +789 −0 chrome/content/zotero/preferences/preferences_advanced.js
  5. +204 −0 chrome/content/zotero/preferences/preferences_advanced.xul
  6. +51 −0 chrome/content/zotero/preferences/preferences_advanced_firefox.xul
  7. +170 −0 chrome/content/zotero/preferences/preferences_cite.js
  8. +93 −0 chrome/content/zotero/preferences/preferences_cite.xul
  9. +246 −0 chrome/content/zotero/preferences/preferences_export.js
  10. +82 −0 chrome/content/zotero/preferences/preferences_export.xul
  11. +53 −0 chrome/content/zotero/preferences/preferences_export_firefox.xul
  12. +8 −117 chrome/content/zotero/preferences/preferences_firefox.xul
  13. +76 −0 chrome/content/zotero/preferences/preferences_general.js
  14. +137 −0 chrome/content/zotero/preferences/preferences_general.xul
  15. +75 −0 chrome/content/zotero/preferences/preferences_general_firefox.xul
  16. +36 −0 chrome/content/zotero/preferences/preferences_keys.js
  17. +125 −0 chrome/content/zotero/preferences/preferences_keys.xul
  18. +147 −0 chrome/content/zotero/preferences/preferences_proxies.js
  19. +483 −0 chrome/content/zotero/preferences/preferences_search.js
  20. +118 −0 chrome/content/zotero/preferences/preferences_search.xul
  21. +435 −0 chrome/content/zotero/preferences/preferences_sync.js
  22. +319 −0 chrome/content/zotero/preferences/preferences_sync.xul
  23. +10 −4 chrome/content/zotero/preferences/quickCopySiteEditor.xul
View
7 chrome.manifest
@@ -49,8 +49,13 @@ skin zotero default chrome/skin/default/zotero/
overlay chrome://browser/content/browser.xul chrome://zotero/content/statusBarOverlay.xul appversion<4.0
overlay chrome://browser/content/browser.xul chrome://zotero/content/overlay.xul
-overlay chrome://zotero/content/preferences/preferences.xul chrome://zotero/content/preferences/preferences_firefox.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
+
+overlay chrome://zotero/content/preferences/preferences.xul chrome://zotero/content/preferences/preferences_firefox.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
overlay chrome://zotero/content/preferences/preferences.xul#cite chrome://zotero/content/preferences/preferences_firefox.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
+overlay chrome://zotero/content/preferences/preferences_general.xul chrome://zotero/content/preferences/preferences_general_firefox.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
+overlay chrome://zotero/content/preferences/preferences_export.xul chrome://zotero/content/preferences/preferences_export_firefox.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
+overlay chrome://zotero/content/preferences/preferences_advanced.xul chrome://zotero/content/preferences/preferences_advanced_firefox.xul application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
+
overlay chrome://mozapps/content/downloads/unknownContentType.xul chrome://zotero/content/downloadOverlay.xul
style chrome://browser/content/browser.xul chrome://zotero/skin/zotero.css
View
2,239 chrome/content/zotero/preferences/preferences.js
@@ -1,7 +1,7 @@
/*
***** BEGIN LICENSE BLOCK *****
- Copyright © 2009 Center for History and New Media
+ Copyright © 2006–2013 Center for History and New Media
George Mason University, Fairfax, Virginia, USA
http://zotero.org
@@ -23,15 +23,40 @@
***** END LICENSE BLOCK *****
*/
-var openURLResolvers;
-var proxies;
-var charsets;
-var _io = {};
-
+"use strict";
var Zotero_Preferences = {
+ init: function () {
+ if(Zotero.isConnector) {
+ Zotero.activateStandalone();
+ window.close();
+ return;
+ }
+
+ observerService.addObserver(function() {
+ if(Zotero.isConnector) window.close();
+ }, "zotero-reloaded", false);
+
+ if(window.arguments) {
+ var io = window.arguments[0];
+
+ if(io.pane) {
+ var pane = document.getElementById(io.pane);
+ document.getElementById('zotero-prefs').showPane(pane);
+ // Quick hack to support install prompt from PDF recognize option
+ if (io.action && io.action == 'pdftools-install') {
+ this.Search.checkPDFToolsDownloadVersion();
+ }
+ }
+ } else if(document.location.hash == "#cite") {
+ document.getElementById('zotero-prefs').showPane(document.getElementById("zotero-prefpane-cite"));
+ }
+ },
+
onUnload: function () {
- Zotero_Preferences.Debug_Output.onUnload();
+ if (Zotero_Preferences.Debug_Output) {
+ Zotero_Preferences.Debug_Output.onUnload();
+ }
},
openHelpLink: function () {
@@ -69,2185 +94,39 @@ var Zotero_Preferences = {
);
}
}
- }
-}
-
-function init()
-{
- if(Zotero.isConnector) {
- Zotero.activateStandalone();
- window.close();
- return;
- }
-
- observerService.addObserver(function() {
- if(Zotero.isConnector) window.close();
- }, "zotero-reloaded", false);
-
- // Display the appropriate modifier keys for the platform
- var rows = document.getElementById('zotero-prefpane-keys').getElementsByTagName('row');
- for (var i=0; i<rows.length; i++) {
- rows[i].firstChild.nextSibling.value = Zotero.isMac ? 'Cmd+Shift+' : 'Ctrl+Alt+';
- }
-
- // JS-based strings
- var checkbox = document.getElementById('launchNonNativeFiles-checkbox');
- if (checkbox ) {
- checkbox.label = Zotero.getString(
- 'zotero.preferences.launchNonNativeFiles', Zotero.appName
- );
- }
-
- updateStorageSettings(null, null, true);
- updateWordProcessorInstructions();
- refreshStylesList();
- refreshProxyList();
- populateQuickCopyList();
- updateQuickCopyInstructions();
- initSearchPane();
- Zotero_Preferences.Debug_Output.init();
-
- var charsetMenu = document.getElementById("zotero-import-charsetMenu");
- var charsetMap = Zotero_Charset_Menu.populate(charsetMenu, false);
- charsetMenu.selectedItem =
- charsetMap[Zotero.Prefs.get("import.charset")] ?
- charsetMap[Zotero.Prefs.get("import.charset")] : charsetMap["auto"];
-
- if(window.arguments) {
- _io = window.arguments[0];
-
- if(_io.pane) {
- var pane = document.getElementById(_io.pane);
- document.getElementById('zotero-prefs').showPane(pane);
- // Quick hack to support install prompt from PDF recognize option
- if (_io.action && _io.action == 'pdftools-install') {
- checkPDFToolsDownloadVersion();
- }
- }
- } else if(document.location.hash == "#cite") {
- document.getElementById('zotero-prefs').showPane(document.getElementById("zotero-prefpane-cite"));
- }
-}
-
-
-function onDataDirLoad() {
- var path = document.getElementById('dataDirPath');
- var useDataDir = Zotero.Prefs.get('useDataDir');
- path.setAttribute('disabled', !useDataDir);
-}
-
-
-function onDataDirUpdate(event) {
- var radiogroup = document.getElementById('dataDir');
- var path = document.getElementById('dataDirPath');
- var useDataDir = Zotero.Prefs.get('useDataDir');
-
- // If triggered from the Choose button, don't show the dialog, since
- // Zotero.chooseZoteroDirectory() shows its own
- if (event.originalTarget && event.originalTarget.tagName == 'button') {
- return true;
- }
- // Fx3.6
- else if (event.explicitOriginalTarget && event.explicitOriginalTarget.tagName == 'button') {
- return true;
- }
-
- // If directory not set or invalid, prompt for location
- if (!getDataDirPath()) {
- event.stopPropagation();
- var file = Zotero.chooseZoteroDirectory(true);
- 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);
- var app = Zotero.isStandalone ? Zotero.getString('app.standalone') : Zotero.getString('app.firefox');
- var index = ps.confirmEx(window,
- Zotero.getString('general.restartRequired'),
- Zotero.getString('general.restartRequiredForChange', app),
- buttonFlags,
- Zotero.getString('general.restartNow'),
- null, null, 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
- | Components.interfaces.nsIAppStartup.eRestart);
- }
-
- radiogroup.selectedIndex = useDataDir ? 1 : 0;
- return useDataDir;
-}
-
-
-function getDataDirPath() {
- var desc = Zotero.Prefs.get('dataDir');
- if (desc == '') {
- return '';
- }
-
- var file = Components.classes["@mozilla.org/file/local;1"].
- createInstance(Components.interfaces.nsILocalFile);
- try {
- file.persistentDescriptor = desc;
- }
- catch (e) {
- return '';
- }
- return file.path;
-}
-
-
-function populateOpenURLResolvers() {
- var openURLMenu = document.getElementById('openURLMenu');
-
- openURLResolvers = Zotero.OpenURL.discoverResolvers();
- var i = 0;
- for each(var r in openURLResolvers) {
- openURLMenu.insertItemAt(i, r.name);
- if (r.url == Zotero.Prefs.get('openURL.resolver') && r.version == Zotero.Prefs.get('openURL.version')) {
- openURLMenu.selectedIndex = i;
- }
- i++;
- }
-
- var button = document.getElementById('openURLSearchButton');
- switch (openURLResolvers.length) {
- case 0:
- var num = 'zero';
- break;
- case 1:
- var num = 'singular';
- break;
- default:
- var num = 'plural';
- }
-
- button.setAttribute('label', Zotero.getString('zotero.preferences.openurl.resolversFound.' + num, openURLResolvers.length));
-}
-
-
-//
-// Sync
-//
-function updateStorageSettings(enabled, protocol, skipWarnings) {
- if (enabled === null) {
- enabled = document.getElementById('pref-storage-enabled').value;
- }
-
- var oldProtocol = document.getElementById('pref-storage-protocol').value;
- if (protocol === null) {
- protocol = oldProtocol;
- }
-
- var storageSettings = document.getElementById('storage-settings');
- var protocolMenu = document.getElementById('storage-protocol');
- var settings = document.getElementById('storage-webdav-settings');
- var sep = document.getElementById('storage-separator');
-
- if (!enabled || protocol == 'zotero') {
- settings.hidden = true;
- sep.hidden = false;
- }
- else {
- settings.hidden = false;
- sep.hidden = true;
- }
-
- var menulists = storageSettings.getElementsByTagName('menulist');
- for each(var menulist in menulists) {
- if (menulist.className == 'storage-personal') {
- menulist.disabled = !enabled;
- }
- }
-
- if (!skipWarnings) {
- // WARN if going between
- }
-
- if (oldProtocol == 'zotero' && protocol == 'webdav') {
- var sql = "SELECT COUNT(*) FROM version WHERE schema='storage_zfs'";
- if (Zotero.DB.valueQuery(sql)) {
- 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_IS_STRING)
- + ps.BUTTON_DELAY_ENABLE;
- var account = Zotero.Sync.Server.username;
- var index = ps.confirmEx(
- null,
- Zotero.getString('zotero.preferences.sync.purgeStorage.title'),
- Zotero.getString('zotero.preferences.sync.purgeStorage.desc'),
- buttonFlags,
- Zotero.getString('zotero.preferences.sync.purgeStorage.confirmButton'),
- Zotero.getString('zotero.preferences.sync.purgeStorage.cancelButton'), null, null, {}
- );
-
- if (index == 0) {
- var sql = "INSERT OR IGNORE INTO settings VALUES (?,?,?)";
- Zotero.DB.query(sql, ['storage', 'zfsPurge', 'user']);
-
- Zotero.Sync.Storage.ZFS.purgeDeletedStorageFiles(function (success) {
- if (success) {
- ps.alert(
- null,
- Zotero.getString("general.success"),
- "Attachment files from your personal library have been removed from the Zotero servers."
- );
- }
- else {
- ps.alert(
- null,
- Zotero.getString("general.error"),
- "An error occurred. Please try again later."
- );
- }
- });
- }
- }
- }
-
- setTimeout(function () {
- updateStorageTerms();
- }, 1)
-}
-
-
-function updateStorageSettingsGroups(enabled) {
- var storageSettings = document.getElementById('storage-settings');
- var menulists = storageSettings.getElementsByTagName('menulist');
- for each(var menulist in menulists) {
- if (menulist.className == 'storage-groups') {
- menulist.disabled = !enabled;
- }
- }
-
- setTimeout(function () {
- updateStorageTerms();
- }, 1)
-}
-
-
-function updateStorageTerms() {
- var terms = document.getElementById('storage-terms');
-
- var libraryEnabled = document.getElementById('pref-storage-enabled').value;
- var storageProtocol = document.getElementById('pref-storage-protocol').value;
- var groupsEnabled = document.getElementById('pref-group-storage-enabled').value;
-
- terms.hidden = !((libraryEnabled && storageProtocol == 'zotero') || groupsEnabled);
-}
-
-
-
-function unverifyStorageServer() {
- Zotero.Prefs.set('sync.storage.verified', false);
- Zotero.Sync.Storage.resetAllSyncStates(null, true, false);
-}
-
-function verifyStorageServer() {
- Zotero.debug("Verifying storage");
-
- var verifyButton = document.getElementById("storage-verify");
- var abortButton = document.getElementById("storage-abort");
- var progressMeter = document.getElementById("storage-progress");
- var urlField = document.getElementById("storage-url");
- var usernameField = document.getElementById("storage-username");
- var passwordField = document.getElementById("storage-password");
-
- verifyButton.hidden = true;
- abortButton.hidden = false;
- progressMeter.hidden = false;
-
- var request = null;
- var onDone = false;
-
- Zotero.Sync.Storage.WebDAV.checkServer()
- // Get the XMLHttpRequest for possible cancelling
- .progress(function (obj) {
- request = obj.xmlhttp;
- })
- .finally(function () {
- verifyButton.hidden = false;
- abortButton.hidden = true;
- progressMeter.hidden = true;
- })
- .spread(function (uri, status) {
- switch (status) {
- case Zotero.Sync.Storage.ERROR_NO_URL:
- onDone = function () {
- urlField.focus();
- };
- break;
-
- case Zotero.Sync.Storage.ERROR_NO_USERNAME:
- onDone = function () {
- usernameField.focus();
- };
- break;
-
- case Zotero.Sync.Storage.ERROR_NO_PASSWORD:
- case Zotero.Sync.Storage.ERROR_AUTH_FAILED:
- onDone = function () {
- passwordField.focus();
- };
- break;
- }
-
- return Zotero.Sync.Storage.WebDAV.checkServerCallback(uri, status, window);
- })
- .then(function (success) {
- if (success) {
- Zotero.debug("WebDAV verification succeeded");
-
- var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
- promptService.alert(
- window,
- Zotero.getString('sync.storage.serverConfigurationVerified'),
- Zotero.getString('sync.storage.fileSyncSetUp')
- );
- Zotero.Prefs.set("sync.storage.verified", true);
- }
- else {
- Zotero.debug("WebDAV verification failed");
- if (onDone) {
- setTimeout(function () {
- onDone();
- }, 1);
- }
- }
- })
- .catch(function (e) {
- Zotero.debug("WebDAV verification failed");
- Zotero.debug(e, 1);
- Components.utils.reportError(e);
- Zotero.Utilities.Internal.errorPrompt(Zotero.getString('general.error'), e);
-
- if (onDone) {
- setTimeout(function () {
- onDone();
- }, 1);
- }
- })
- .done();
-
- abortButton.onclick = function () {
- if (request) {
- Zotero.debug("Cancelling verification request");
- request.onreadystatechange = undefined;
- request.abort();
- verifyButton.hidden = false;
- abortButton.hidden = true;
- progressMeter.hidden = true;
- }
- }
-}
-
-function handleSyncResetSelect(obj) {
- var index = obj.selectedIndex;
- var rows = obj.getElementsByTagName('row');
-
- for (var i=0; i<rows.length; i++) {
- if (i == index) {
- rows[i].setAttribute('selected', 'true');
- }
- else {
- rows[i].removeAttribute('selected');
- }
- }
-}
-
-function handleSyncReset(action) {
- var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
-
- if (!Zotero.Sync.Server.enabled) {
- ps.alert(
- null,
- Zotero.getString('general.error'),
- Zotero.getString('zotero.preferences.sync.reset.userInfoMissing',
- document.getElementById('zotero-prefpane-sync')
- .getElementsByTagName('tab')[0].label)
- );
- return;
- }
-
- var account = Zotero.Sync.Server.username;
-
- switch (action) {
- case 'restore-from-server':
- var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
- + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL)
- + ps.BUTTON_POS_1_DEFAULT;
- var index = ps.confirmEx(
- null,
- Zotero.getString('general.warning'),
- Zotero.getString('zotero.preferences.sync.reset.restoreFromServer', account),
- buttonFlags,
- Zotero.getString('zotero.preferences.sync.reset.replaceLocalData'),
- null, null, null, {}
- );
-
- switch (index) {
- case 0:
- // TODO: better error handling
-
- // Verify username and password
- var callback = function () {
- Zotero.Schema.stopRepositoryTimer();
- Zotero.Sync.Runner.clearSyncTimeout();
-
- Zotero.DB.skipBackup = true;
-
- var file = Zotero.getZoteroDirectory();
- file.append('restore-from-server');
- Zotero.File.putContents(file, '');
-
- var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING);
- var index = ps.confirmEx(
- null,
- Zotero.getString('general.restartRequired'),
- Zotero.getString('zotero.preferences.sync.reset.restartToComplete'),
- buttonFlags,
- Zotero.getString('general.restartNow'),
- null, null, null, {}
- );
-
- var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
- .getService(Components.interfaces.nsIAppStartup);
- appStartup.quit(Components.interfaces.nsIAppStartup.eRestart | Components.interfaces.nsIAppStartup.eAttemptQuit);
- };
-
- // TODO: better way of checking for an active session?
- if (Zotero.Sync.Server.sessionIDComponent == 'sessionid=') {
- Zotero.Sync.Server.login(callback);
- }
- else {
- callback();
- }
- break;
-
- // Cancel
- case 1:
- return;
- }
- break;
-
- case 'restore-to-server':
- var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
- + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL)
- + ps.BUTTON_POS_1_DEFAULT;
- var index = ps.confirmEx(
- null,
- Zotero.getString('general.warning'),
- Zotero.getString('zotero.preferences.sync.reset.restoreToServer', account),
- buttonFlags,
- Zotero.getString('zotero.preferences.sync.reset.replaceServerData'),
- null, null, null, {}
- );
-
- switch (index) {
- case 0:
- // TODO: better error handling
- Zotero.Sync.Server.clear(function () {
- Zotero.Sync.Server.sync(/*{
-
- // TODO: this doesn't work if the pref window is
- closed. fix, perhaps by making original callbacks
- available to the custom callbacks
-
- onSuccess: function () {
- Zotero.Sync.Runner.setSyncIcon();
- ps.alert(
- null,
- "Restore Completed",
- "Data on the Zotero server has been successfully restored."
- );
- },
- onError: function (msg) {
- // TODO: combine with error dialog for regular syncs
- ps.alert(
- null,
- "Restore Failed",
- "An error occurred uploading your data to the server.\n\n"
- + "Click the sync error icon in the Zotero toolbar "
- + "for further information."
- );
- Zotero.Sync.Runner.error(msg);
- }
- }*/);
- });
- break;
-
- // Cancel
- case 1:
- return;
- }
-
- break;
-
-
- case 'reset-storage-history':
- var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
- + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL)
- + ps.BUTTON_POS_1_DEFAULT;
- var index = ps.confirmEx(
- null,
- Zotero.getString('general.warning'),
- Zotero.getString('zotero.preferences.sync.reset.fileSyncHistory'),
- buttonFlags,
- Zotero.getString('general.reset'),
- null, null, null, {}
- );
-
- switch (index) {
- case 0:
- Zotero.Sync.Storage.resetAllSyncStates();
- ps.alert(
- null,
- "File Sync History Cleared",
- "The file sync history has been cleared."
- );
- break;
-
- // Cancel
- case 1:
- return;
- }
-
- break;
-
- default:
- throw ("Invalid action '" + action + "' in handleSyncReset()");
- }
-}
-
-
-/*
- * Builds the main Quick Copy drop-down from the current global pref
- */
-function populateQuickCopyList() {
- // Initialize default format drop-down
- var format = Zotero.Prefs.get("export.quickCopy.setting");
- var menulist = document.getElementById("zotero-quickCopy-menu");
- buildQuickCopyFormatDropDown(menulist, Zotero.QuickCopy.getContentType(format), format);
- menulist.setAttribute('preference', "pref-quickCopy-setting");
- updateQuickCopyHTMLCheckbox();
-
- if (!Zotero.isStandalone) {
- refreshQuickCopySiteList();
- }
-}
-
-
-/*
- * Builds a Quick Copy drop-down
- */
-function buildQuickCopyFormatDropDown(menulist, contentType, currentFormat) {
- if (!currentFormat) {
- currentFormat = menulist.value;
- }
- // Strip contentType from mode
- currentFormat = Zotero.QuickCopy.stripContentType(currentFormat);
-
- menulist.selectedItem = null;
- menulist.removeAllItems();
-
- // Prevent Cmd-w from setting "Wikipedia"
- menulist.onkeydown = function (event) {
- if ((Zotero.isMac && event.metaKey) || event.ctrlKey) {
- event.preventDefault();
- }
- }
-
- var popup = document.createElement('menupopup');
- menulist.appendChild(popup);
-
- var itemNode = document.createElement("menuitem");
- itemNode.setAttribute("label", Zotero.getString('zotero.preferences.export.quickCopy.bibStyles'));
- itemNode.setAttribute("disabled", true);
- popup.appendChild(itemNode);
-
- // add styles to list
- var styles = Zotero.Styles.getVisible();
- for each(var style in styles) {
- var baseVal = 'bibliography=' + style.styleID;
- var val = 'bibliography' + (contentType == 'html' ? '/html' : '') + '=' + style.styleID;
- var itemNode = document.createElement("menuitem");
- itemNode.setAttribute("value", val);
- itemNode.setAttribute("label", style.title);
- itemNode.setAttribute("oncommand", 'updateQuickCopyHTMLCheckbox()');
- popup.appendChild(itemNode);
-
- if (baseVal == currentFormat) {
- menulist.selectedItem = itemNode;
- }
- }
-
- var itemNode = document.createElement("menuitem");
- itemNode.setAttribute("label", Zotero.getString('zotero.preferences.export.quickCopy.exportFormats'));
- itemNode.setAttribute("disabled", true);
- popup.appendChild(itemNode);
-
- // add export formats to list
- var translation = new Zotero.Translate("export");
- var translators = translation.getTranslators();
-
- for (var i=0; i<translators.length; i++) {
- // Skip RDF formats
- switch (translators[i].translatorID) {
- case '6e372642-ed9d-4934-b5d1-c11ac758ebb7':
- case '14763d24-8ba0-45df-8f52-b8d1108e7ac9':
- continue;
- }
- var val = 'export=' + translators[i].translatorID;
- var itemNode = document.createElement("menuitem");
- itemNode.setAttribute("value", val);
- itemNode.setAttribute("label", translators[i].label);
- itemNode.setAttribute("oncommand", 'updateQuickCopyHTMLCheckbox()');
- popup.appendChild(itemNode);
-
- if (val == currentFormat) {
- menulist.selectedItem = itemNode;
- }
- }
-
- menulist.click();
-
- return popup;
-}
-
-function updateQuickCopyHTMLCheckbox() {
- var format = document.getElementById('zotero-quickCopy-menu').value;
- var mode, contentType;
-
- var checkbox = document.getElementById('zotero-quickCopy-copyAsHTML');
- [mode, format] = format.split('=');
- [mode, contentType] = mode.split('/');
-
- checkbox.checked = contentType == 'html';
- checkbox.disabled = mode != 'bibliography';
-}
-
-function showQuickCopySiteEditor(index) {
- var treechildren = document.getElementById('quickCopy-siteSettings-rows');
-
- if (index != undefined && index > -1 && index < treechildren.childNodes.length) {
- var treerow = treechildren.childNodes[index].firstChild;
- var domain = treerow.childNodes[0].getAttribute('label');
- var format = treerow.childNodes[1].getAttribute('label');
- var asHTML = treerow.childNodes[2].getAttribute('label') != '';
- }
-
- var format = Zotero.QuickCopy.getSettingFromFormattedName(format);
- if (asHTML) {
- format = format.replace('bibliography=', 'bibliography/html=');
- }
-
- var io = {domain: domain, format: format, ok: false};
- window.openDialog('chrome://zotero/content/preferences/quickCopySiteEditor.xul', "zotero-preferences-quickCopySiteEditor", "chrome, modal", io);
-
- if (!io.ok) {
- return;
- }
-
- if (domain && domain != io.domain) {
- Zotero.DB.query("DELETE FROM settings WHERE setting='quickCopySite' AND key=?", [domain]);
- }
-
- Zotero.DB.query("REPLACE INTO settings VALUES ('quickCopySite', ?, ?)", [io.domain, io.format]);
-
- refreshQuickCopySiteList();
-}
-
-function refreshQuickCopySiteList() {
- var treechildren = document.getElementById('quickCopy-siteSettings-rows');
- while (treechildren.hasChildNodes()) {
- treechildren.removeChild(treechildren.firstChild);
- }
-
- var sql = "SELECT key AS domainPath, value AS format FROM settings "
- + "WHERE setting='quickCopySite' ORDER BY domainPath COLLATE NOCASE";
- var siteData = Zotero.DB.query(sql);
-
- if (!siteData) {
- return;
- }
-
- for (var i=0; i<siteData.length; i++) {
- var treeitem = document.createElement('treeitem');
- var treerow = document.createElement('treerow');
- var domainCell = document.createElement('treecell');
- var formatCell = document.createElement('treecell');
- var HTMLCell = document.createElement('treecell');
-
- domainCell.setAttribute('label', siteData[i].domainPath);
-
- var formatted = Zotero.QuickCopy.getFormattedNameFromSetting(siteData[i].format);
- formatCell.setAttribute('label', formatted);
- var copyAsHTML = Zotero.QuickCopy.getContentType(siteData[i].format) == 'html';
- HTMLCell.setAttribute('label', copyAsHTML ? '' : '');
-
- treerow.appendChild(domainCell);
- treerow.appendChild(formatCell);
- treerow.appendChild(HTMLCell);
- treeitem.appendChild(treerow);
- treechildren.appendChild(treeitem);
- }
-}
-
-
-function deleteSelectedQuickCopySite() {
- var tree = document.getElementById('quickCopy-siteSettings');
- var treeitem = tree.lastChild.childNodes[tree.currentIndex];
- var domainPath = treeitem.firstChild.firstChild.getAttribute('label');
- Zotero.DB.query("DELETE FROM settings WHERE setting='quickCopySite' AND key=?", [domainPath]);
- refreshQuickCopySiteList();
-}
-
-
-function updateQuickCopyInstructions() {
- var prefix = Zotero.isMac ? 'Cmd+Shift+' : 'Ctrl+Alt+';
-
- var key = Zotero.Prefs.get('keys.copySelectedItemsToClipboard');
- var str = Zotero.getString('zotero.preferences.export.quickCopy.instructions', prefix + key);
- var instr = document.getElementById('quickCopy-instructions');
- while (instr.hasChildNodes()) {
- instr.removeChild(instr.firstChild);
- }
- instr.appendChild(document.createTextNode(str));
-
- var key = Zotero.Prefs.get('keys.copySelectedItemCitationsToClipboard');
- var str = Zotero.getString('zotero.preferences.export.quickCopy.citationInstructions', prefix + key);
- var instr = document.getElementById('quickCopy-citationInstructions');
- while (instr.hasChildNodes()) {
- instr.removeChild(instr.firstChild);
- }
- instr.appendChild(document.createTextNode(str));
-}
-
-
-function rebuildIndexPrompt() {
- var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
- createInstance(Components.interfaces.nsIPromptService);
- var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
- + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING)
- + (ps.BUTTON_POS_2) * (ps.BUTTON_TITLE_CANCEL);
-
- var index = ps.confirmEx(null,
- Zotero.getString('zotero.preferences.search.rebuildIndex'),
- Zotero.getString('zotero.preferences.search.rebuildWarning',
- Zotero.getString('zotero.preferences.search.indexUnindexed')),
- buttonFlags,
- Zotero.getString('zotero.preferences.search.rebuildIndex'),
- Zotero.getString('zotero.preferences.search.indexUnindexed'),
- null, null, {});
-
- if (index == 0) {
- Zotero.Fulltext.rebuildIndex();
- }
- else if (index == 1) {
- Zotero.Fulltext.rebuildIndex(true)
- }
-
- updateIndexStats();
-}
-
-
-function clearIndexPrompt() {
- var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
- createInstance(Components.interfaces.nsIPromptService);
- var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
- + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING)
- + (ps.BUTTON_POS_2) * (ps.BUTTON_TITLE_CANCEL);
-
- var index = ps.confirmEx(null,
- Zotero.getString('zotero.preferences.search.clearIndex'),
- Zotero.getString('zotero.preferences.search.clearWarning',
- Zotero.getString('zotero.preferences.search.clearNonLinkedURLs')),
- buttonFlags,
- Zotero.getString('zotero.preferences.search.clearIndex'),
- Zotero.getString('zotero.preferences.search.clearNonLinkedURLs'),
- null, null, {});
-
- if (index == 0) {
- Zotero.Fulltext.clearIndex();
- }
- else if (index == 1) {
- Zotero.Fulltext.clearIndex(true);
- }
-
- updateIndexStats();
-}
-
-
-function initSearchPane() {
- document.getElementById('fulltext-rebuildIndex').setAttribute('label',
- Zotero.getString('zotero.preferences.search.rebuildIndex'));
- document.getElementById('fulltext-clearIndex').setAttribute('label',
- Zotero.getString('zotero.preferences.search.clearIndex'));
- updatePDFToolsStatus();
-}
-
-
-/*
- * Update window according to installation status for PDF tools
- * (e.g. status line, install/update button, etc.)
- */
-function updatePDFToolsStatus() {
- var converterIsRegistered = Zotero.Fulltext.pdfConverterIsRegistered();
- var infoIsRegistered = Zotero.Fulltext.pdfInfoIsRegistered();
+ },
- var converterStatusLabel = document.getElementById('pdfconverter-status');
- var infoStatusLabel = document.getElementById('pdfinfo-status');
- var requiredLabel = document.getElementById('pdftools-required');
- var updateButton = document.getElementById('pdftools-update-button');
- var documentationLink = document.getElementById('pdftools-documentation-link');
- var settingsBox = document.getElementById('pdftools-settings');
- // If we haven't already generated the required and documentation messages
- if (!converterIsRegistered && !requiredLabel.hasChildNodes()) {
-
- // Xpdf link
- var str = Zotero.getString('zotero.preferences.search.pdf.toolsRequired',
- [Zotero.Fulltext.pdfConverterName, Zotero.Fulltext.pdfInfoName,
- '<a href="' + Zotero.Fulltext.pdfToolsURL + '">'
- + Zotero.Fulltext.pdfToolsName + '</a>']);
- var parts = Zotero.Utilities.parseMarkup(str);
- for (var i=0; i<parts.length; i++) {
- var part = parts[i];
- if (part.type == 'text') {
- var elem = document.createTextNode(part.text);
- }
- else if (part.type == 'link') {
- var elem = document.createElement('label');
- elem.setAttribute('value', part.text);
- elem.setAttribute('class', 'zotero-text-link');
- for (var key in part.attributes) {
- elem.setAttribute(key, part.attributes[key]);
-
- if (key == 'href') {
- elem.setAttribute('tooltiptext', part.attributes[key]);
- }
- }
- }
- requiredLabel.appendChild(elem);
- }
+ /**
+ * Opens a URI in the basic viewer in Standalone, or a new window in Firefox
+ */
+ openInViewer: function (uri, newTab) {
+ var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
+ .getService(Components.interfaces.nsIWindowMediator);
+ const features = "menubar=yes,toolbar=no,location=no,scrollbars,centerscreen,resizable";
- requiredLabel.appendChild(document.createTextNode(' '
- + Zotero.getString('zotero.preferences.search.pdf.automaticInstall')));
-
- // Documentation link
- var link = '<a href="http://www.zotero.org/documentation/pdf_fulltext_indexing">'
- + Zotero.getString('zotero.preferences.search.pdf.documentationLink')
- + '</a>';
- var str = Zotero.getString('zotero.preferences.search.pdf.advancedUsers', link);
- var parts = Zotero.Utilities.parseMarkup(str);
-
- for (var i=0; i<parts.length; i++) {
- var part = parts[i];
- if (part.type == 'text') {
- var elem = document.createTextNode(part.text);
- }
- else if (part.type == 'link') {
- var elem = document.createElement('label');
- elem.setAttribute('value', part.text);
- elem.setAttribute('class', 'zotero-text-link');
- for (var key in part.attributes) {
- elem.setAttribute(key, part.attributes[key]);
-
- if (key == 'href') {
- elem.setAttribute('tooltiptext', part.attributes[key]);
- }
- }
+ if(Zotero.isStandalone) {
+ var win = wm.getMostRecentWindow("zotero:basicViewer");
+ if(win) {
+ win.loadURI(uri);
+ } else {
+ window.openDialog("chrome://zotero/content/standalone/basicViewer.xul",
+ "basicViewer", "chrome,resizable,centerscreen,menubar,scrollbars", uri);
}
- documentationLink.appendChild(elem);
- }
- }
-
- // converter status line
- var prefix = 'zotero.preferences.search.pdf.tool';
- if (converterIsRegistered) {
- var version = Zotero.Fulltext.pdfConverterVersion;
- str = Zotero.getString(prefix + 'Registered',
- Zotero.getString('zotero.preferences.search.pdf.toolVersionPlatform',
- [Zotero.Fulltext.pdfConverterName, version]));
- }
- else {
- str = Zotero.getString(prefix + 'NotRegistered',
- [Zotero.Fulltext.pdfConverterFileName]);
- }
- converterStatusLabel.setAttribute('value', str);
-
- // pdfinfo status line
- if (infoIsRegistered) {
- var version = Zotero.Fulltext.pdfInfoVersion;
- str = Zotero.getString(prefix + 'Registered',
- Zotero.getString('zotero.preferences.search.pdf.toolVersionPlatform',
- [Zotero.Fulltext.pdfInfoName, version]));
- }
- else {
- str = Zotero.getString(prefix + 'NotRegistered',
- [Zotero.Fulltext.pdfInfoFileName]);
- }
- infoStatusLabel.setAttribute('value', str);
-
- str = converterIsRegistered ?
- Zotero.getString('general.checkForUpdate') :
- Zotero.getString('zotero.preferences.search.pdf.checkForInstaller');
- updateButton.setAttribute('label', str);
-
- requiredLabel.setAttribute('hidden', converterIsRegistered);
- documentationLink.setAttribute('hidden', converterIsRegistered);
- settingsBox.setAttribute('hidden', !converterIsRegistered);
-}
-
-
-/*
- * Check available versions of PDF tools from server and prompt for installation
- * if a newer version is available
- */
-function checkPDFToolsDownloadVersion() {
- var url = Zotero.Fulltext.pdfToolsDownloadBaseURL
- + Zotero.platform.replace(' ', '-') + '.latest';
-
- // Find latest version for this platform
- var sent = Zotero.HTTP.doGet(url, function (xmlhttp) {
- try {
- if (xmlhttp.status == 200) {
- var converterIsRegistered = Zotero.Fulltext.pdfConverterIsRegistered();
- var infoIsRegistered = Zotero.Fulltext.pdfInfoIsRegistered();
- var bothRegistered = converterIsRegistered && infoIsRegistered;
-
- var converterVersion = xmlhttp.responseText.split(/\s/)[0];
- var infoVersion = xmlhttp.responseText.split(/\s/)[1];
-
- var converterVersionAvailable = converterVersion &&
- (!converterIsRegistered ||
- Zotero.Fulltext.pdfConverterVersion == 'UNKNOWN' ||
- converterVersion > Zotero.Fulltext.pdfConverterVersion);
- var infoVersionAvailable = infoVersion &&
- (!infoIsRegistered ||
- Zotero.Fulltext.pdfInfoVersion == 'UNKNOWN' ||
- infoVersion > Zotero.Fulltext.pdfInfoVersion);
- var bothAvailable = converterVersionAvailable && infoVersionAvailable;
-
- /*
- Zotero.debug(converterIsRegistered);
- Zotero.debug(infoIsRegistered);
- Zotero.debug(converterVersion);
- Zotero.debug(infoVersion);
- Zotero.debug(Zotero.Fulltext.pdfConverterVersion);
- Zotero.debug(Zotero.Fulltext.pdfInfoVersion);
- Zotero.debug(converterVersionAvailable);
- Zotero.debug(infoVersionAvailable);
- */
-
- // Up to date -- disable update button
- if (!converterVersionAvailable && !infoVersionAvailable) {
- var button = document.getElementById('pdftools-update-button');
- button.setAttribute('label', Zotero.getString('zotero.preferences.update.upToDate'));
- button.setAttribute('disabled', true);
- }
- // New version available -- display update prompt
- else {
- var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].
- createInstance(Components.interfaces.nsIPromptService);
- var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
- + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL);
-
- var msg = Zotero.getString('zotero.preferences.search.pdf.available'
- + ((converterIsRegistered || infoIsRegistered) ? 'Updates' : 'Downloads'),
- [Zotero.platform, 'zotero.org']) + '\n\n';
-
- if (converterVersionAvailable) {
- tvp = Zotero.getString('zotero.preferences.search.pdf.toolVersionPlatform',
- [Zotero.Fulltext.pdfConverterName, converterVersion]);
- msg += '- ' + tvp + '\n';
- }
- if (infoVersionAvailable) {
- tvp = Zotero.getString('zotero.preferences.search.pdf.toolVersionPlatform',
- [Zotero.Fulltext.pdfInfoName, infoVersion]);
- msg += '- ' + tvp + '\n';
- }
- msg += '\n';
- msg += Zotero.getString('zotero.preferences.search.pdf.zoteroCanInstallVersion'
- + (bothAvailable ? 's' : ''));
-
- var index = ps.confirmEx(null,
- converterIsRegistered ?
- Zotero.getString('general.updateAvailable') : '',
- msg,
- buttonFlags,
- converterIsRegistered ?
- Zotero.getString('general.upgrade') :
- Zotero.getString('general.install'),
- null, null, null, {});
-
- if (index == 0) {
- var installVersions = {
- converter: converterVersionAvailable ?
- converterVersion : null,
- info: infoVersionAvailable ?
- infoVersion : null
- };
- installPDFTools(installVersions);
- }
+ } else {
+ var win = wm.getMostRecentWindow("navigator:browser");
+ if(win) {
+ if(newTab) {
+ win.gBrowser.selectedTab = win.gBrowser.addTab(uri);
+ } else {
+ win.open(uri, null, features);
}
}
- // Version not found for platform
- else if (xmlhttp.status == 404) {
- onPDFToolsDownloadError(404);
+ else {
+ var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
+ .getService(Components.interfaces.nsIWindowWatcher);
+ var win = ww.openWindow(null, uri, null, features + ",width=775,height=575", null);
}
}
- catch (e) {
- onPDFToolsDownloadError(e);
- }
- });
-
- // Browser is offline
- if (!sent) {
- onPDFToolsDownloadError();
- }
-}
-
-
-/*
- * Begin installation of specified PDF tools from server -- does a HEAD call to
- * make sure file exists and then calls downloadPDFTool() if so
- */
-function installPDFTools(installVersions) {
- if (!installVersions) {
- installVersions = {
- converter: true,
- info: true
- };
- }
-
- // We install the converter first if it's available
- var url = Zotero.Fulltext.pdfToolsDownloadBaseURL;
- if (installVersions.converter) {
- var tool = 'converter';
- var version = installVersions.converter;
- url += Zotero.Fulltext.pdfConverterFileName + '-' + installVersions.converter;
- }
- else if (installVersions.info) {
- var tool = 'info';
- var version = installVersions.info;
- url += Zotero.Fulltext.pdfInfoFileName + '-' + installVersions.info;
- }
- else {
- return;
- }
-
- // Find latest version for this platform
- var sent = Zotero.HTTP.doHead(url, function (xmlhttp) {
- try {
- if (xmlhttp.status == 200) {
- // If doing both and on converter, chain pdfinfo
- if (installVersions.converter && installVersions.info) {
- downloadPDFTool(tool, version, function () {
- return installPDFTools({ info: installVersions.info });
- });
- }
- else {
- downloadPDFTool(tool, version);
- }
- }
- // Version not found for platform
- else if (xmlhttp.status == 404) {
- onPDFToolsDownloadError(404);
- }
- }
- catch (e) {
- onPDFToolsDownloadError(e);
- }
- });
-
- // Browser is offline
- if (!sent) {
- onPDFToolsDownloadError();
- }
-}
-
-
-/*
- * Download and install specified PDF tool
- */
-function downloadPDFTool(tool, version, callback) {
- var ioService = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService);
-
- if (tool == 'converter') {
- var fileName = Zotero.Fulltext.pdfConverterFileName;
- }
- else {
- var fileName = Zotero.Fulltext.pdfInfoFileName;
- }
-
-
- var url = Zotero.Fulltext.pdfToolsDownloadBaseURL + fileName + '-' + version;
- var uri = ioService.newURI(url, null, null);
-
- var file = Zotero.getZoteroDirectory();
- file.append(fileName);
- var fileURL = ioService.newFileURI(file);
-
- const nsIWBP = Components.interfaces.nsIWebBrowserPersist;
- var wbp = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
- .createInstance(nsIWBP);
-
- var progressListener = new Zotero.WebProgressFinishListener(function () {
- // Set permissions to 755
- if (Zotero.isMac) {
- file.permissions = 33261;
- }
- else if (Zotero.isLinux) {
- file.permissions = 493;
- }
-
- // Write the version number to a file
- var versionFile = Zotero.getZoteroDirectory();
- versionFile.append(fileName + '.version');
- Zotero.File.putContents(versionFile, version + '');
-
- Zotero.Fulltext.registerPDFTool(tool);
-
- // Used to install info tool after converter
- if (callback) {
- callback();
- }
- // If done
- else {
- updatePDFToolsStatus();
- }
- });
-
- /*
- var tr = Components.classes["@mozilla.org/transfer;1"].
- createInstance(Components.interfaces.nsITransfer);
- tr.init(uri, fileURL, "", null, null, null, wbp);
- */
-
- document.getElementById('pdftools-update-button').disabled = true;
- var str = Zotero.getString('zotero.preferences.search.pdf.downloading');
- document.getElementById('pdftools-update-button').setAttribute('label', str);
-
- wbp.progressListener = progressListener;
- Zotero.debug("Saving " + uri.spec + " to " + fileURL.spec);
- try {
- wbp.saveURI(uri, null, null, null, null, fileURL);
- } catch(e if e.name === "NS_ERROR_XPC_NOT_ENOUGH_ARGS") {
- // https://bugzilla.mozilla.org/show_bug.cgi?id=794602
- // XXX Always use when we no longer support Firefox < 18
- wbp.saveURI(uri, null, null, null, null, fileURL, null);
- }
-}
-
-
-function onPDFToolsDownloadError(e) {
- if (e == 404) {
- var str = Zotero.getString('zotero.preferences.search.pdf.toolDownloadsNotAvailable',
- Zotero.Fulltext.pdfToolsName) + ' '
- + Zotero.getString('zotero.preferences.search.pdf.viewManualInstructions');
- }
- else if (e) {
- Components.utils.reportError(e);
- var str = Zotero.getString('zotero.preferences.search.pdf.toolsDownloadError', Zotero.Fulltext.pdfToolsName)
- + ' ' + Zotero.getString('zotero.preferences.search.pdf.tryAgainOrViewManualInstructions');
- }
- else {
- var info = Components.classes["@mozilla.org/xre/app-info;1"]
- .getService(Components.interfaces.nsIXULAppInfo);
- var browser = info.name; // Returns "Firefox" for Firefox
- var str = Zotero.getString('general.browserIsOffline', browser);
- }
- alert(str);
-}
-
-
-function updateIndexStats() {
- var stats = Zotero.Fulltext.getIndexStats();
- document.getElementById('fulltext-stats-indexed').
- lastChild.setAttribute('value', stats.indexed);
- document.getElementById('fulltext-stats-partial').
- lastChild.setAttribute('value', stats.partial);
- document.getElementById('fulltext-stats-unindexed').
- lastChild.setAttribute('value', stats.unindexed);
- document.getElementById('fulltext-stats-words').
- lastChild.setAttribute('value', stats.words);
-}
-
-
-function revealDataDirectory() {
- var dataDir = Zotero.getZoteroDirectory();
- dataDir.QueryInterface(Components.interfaces.nsILocalFile);
- try {
- dataDir.reveal();
- }
- catch (e) {
- // On platforms that don't support nsILocalFile.reveal() (e.g. Linux),
- // launch the directory
- window.opener.ZoteroPane_Local.launchFile(dataDir);
- }
-}
-
-
-function runIntegrityCheck() {
- var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
-
- var ok = Zotero.DB.integrityCheck();
- if (ok) {
- ok = Zotero.Schema.integrityCheck();
- if (!ok) {
- var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
- + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL);
- var index = ps.confirmEx(window,
- Zotero.getString('general.failed'),
- Zotero.getString('db.integrityCheck.failed') + "\n\n" +
- Zotero.getString('db.integrityCheck.repairAttempt') + " " +
- Zotero.getString('db.integrityCheck.appRestartNeeded', Zotero.appName),
- buttonFlags,
- Zotero.getString('db.integrityCheck.fixAndRestart', Zotero.appName),
- null, null, null, {}
- );
-
- if (index == 0) {
- // Safety first
- Zotero.DB.backupDatabase();
-
- // Fix the errors
- Zotero.Schema.integrityCheck(true);
-
- // And run the check again
- ok = Zotero.Schema.integrityCheck();
- var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING);
- if (ok) {
- var str = 'success';
- var msg = Zotero.getString('db.integrityCheck.errorsFixed');
- }
- else {
- var str = 'failed';
- var msg = Zotero.getString('db.integrityCheck.errorsNotFixed')
- + "\n\n" + Zotero.getString('db.integrityCheck.reportInForums');
- }
-
- ps.confirmEx(window,
- Zotero.getString('general.' + str),
- msg,
- buttonFlags,
- Zotero.getString('general.restartApp', Zotero.appName),
- null, null, null, {}
- );
-
- var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
- .getService(Components.interfaces.nsIAppStartup);
- appStartup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit
- | Components.interfaces.nsIAppStartup.eRestart);
- }
-
- return;
- }
- }
- var str = ok ? 'passed' : 'failed';
-
- ps.alert(window,
- Zotero.getString('general.' + str),
- Zotero.getString('db.integrityCheck.' + str)
- + (!ok ? "\n\n" + Zotero.getString('db.integrityCheck.dbRepairTool') : ''));
-}
-
-
-function updateTranslators() {
- Zotero.Schema.updateFromRepository(true, function (xmlhttp, updated) {
- var button = document.getElementById('updateButton');
- if (button) {
- if (updated===-1) {
- var label = Zotero.getString('zotero.preferences.update.upToDate');
- }
- else if (updated) {
- var label = Zotero.getString('zotero.preferences.update.updated');
- }
- else {
- var label = Zotero.getString('zotero.preferences.update.error');
- }
- button.setAttribute('label', label);
-
- if (updated) {
- refreshStylesList();
- }
- }
- });
-}
-
-
-function resetTranslatorsAndStyles() {
- 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);
-
- var index = ps.confirmEx(null,
- Zotero.getString('general.warning'),
- Zotero.getString('zotero.preferences.advanced.resetTranslatorsAndStyles.changesLost'),
- buttonFlags,
- Zotero.getString('zotero.preferences.advanced.resetTranslatorsAndStyles'),
- null, null, null, {});
-
- if (index == 0) {
- Zotero.Schema.resetTranslatorsAndStyles(function (xmlhttp, updated) {
- populateQuickCopyList();
- });
- }
-}
-
-
-function resetTranslators() {
- 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);
-
- var index = ps.confirmEx(null,
- Zotero.getString('general.warning'),
- Zotero.getString('zotero.preferences.advanced.resetTranslators.changesLost'),
- buttonFlags,
- Zotero.getString('zotero.preferences.advanced.resetTranslators'),
- null, null, null, {});
-
- if (index == 0) {
- Zotero.Schema.resetTranslators();
- }
-}
-
-
-function resetStyles() {
- 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);
-
- var index = ps.confirmEx(null,
- Zotero.getString('general.warning'),
- Zotero.getString('zotero.preferences.advanced.resetStyles.changesLost'),
- buttonFlags,
- Zotero.getString('zotero.preferences.advanced.resetStyles'),
- null, null, null, {});
-
- if (index == 0) {
- Zotero.Schema.resetStyles(function (xmlhttp, updated) {
- populateQuickCopyList();
- });
- }
-}
-
-
-Zotero_Preferences.Debug_Output = {
- _timer: null,
-
- init: function () {
- var storing = Zotero.Debug.storing;
- this._updateButton();
- this.updateLines();
- if (storing) {
- this._initTimer();
- }
- },
-
-
- toggleStore: function () {
- this.setStore(!Zotero.Debug.storing);
- },
-
-
- setStore: function (set) {
- Zotero.Debug.setStore(set);
- if (set) {
- this._initTimer();
- }
- else {
- if (this._timerID) {
- this._timer.cancel();
- this._timerID = null;
- }
- }
- this._updateButton();
- this.updateLines();
- },
-
-
- view: function () {
- openInViewer("zotero://debug/");
- },
-
-
- submit: function () {
- document.getElementById('debug-output-submit').disabled = true;
- document.getElementById('debug-output-submit-progress').hidden = false;
-
- var url = "https://repo.zotero.org/repo/report?debug=1";
- var output = Zotero.Debug.get(
- Zotero.Prefs.get('debug.store.submitSize'),
- Zotero.Prefs.get('debug.store.submitLineLength')
- );
- Zotero_Preferences.Debug_Output.setStore(false);
-
- var uploadCallback = function (xmlhttp) {
- document.getElementById('debug-output-submit').disabled = false;
- document.getElementById('debug-output-submit-progress').hidden = true;
-
- Zotero.debug(xmlhttp.responseText);
-
- var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
-
- if (!xmlhttp.responseXML) {
- ps.alert(
- null,
- Zotero.getString('general.error'),
- Zotero.getString('general.invalidResponseServer')
- );
- return;
- }
- var reported = xmlhttp.responseXML.getElementsByTagName('reported');
- if (reported.length != 1) {
- ps.alert(
- null,
- Zotero.getString('general.error'),
- Zotero.getString('general.serverError')
- );
- return;
- }
-
- var reportID = reported[0].getAttribute('reportID');
- ps.alert(
- null,
- Zotero.getString('zotero.preferences.advanced.debug.title'),
- Zotero.getString('zotero.preferences.advanced.debug.sent', reportID)
- );
- }
-
- var bufferUploader = function (data) {
- var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
-
- var oldLen = output.length;
- var newLen = data.length;
- var savings = Math.round(((oldLen - newLen) / oldLen) * 100)
- Zotero.debug("HTTP POST " + newLen + " bytes to " + url
- + " (gzipped from " + oldLen + " bytes; "
- + savings + "% savings)");
-
- if (Zotero.HTTP.browserIsOffline()) {
- ps.alert(
- null,
- Zotero.getString('general.error'),
- Zotero.getString('general.browserIsOffline', Zotero.appName)
- );
- return false;
- }
-
- var req =
- Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].
- createInstance();
- req.open('POST', url, true);
- req.setRequestHeader('Content-Type', "text/plain");
- req.setRequestHeader('Content-Encoding', 'gzip');
-
- req.channel.notificationCallbacks = {
- onProgress: function (request, context, progress, progressMax) {
- var pm = document.getElementById('debug-output-submit-progress');
- pm.mode = 'determined'
- pm.value = progress;
- pm.max = progressMax;
- },
-
- // nsIInterfaceRequestor
- getInterface: function (iid) {
- try {
- return this.QueryInterface(iid);
- }
- catch (e) {
- throw Components.results.NS_NOINTERFACE;
- }
- },
-
- QueryInterface: function(iid) {
- if (iid.equals(Components.interfaces.nsISupports) ||
- iid.equals(Components.interfaces.nsIInterfaceRequestor) ||
- iid.equals(Components.interfaces.nsIProgressEventSink)) {
- return this;
- }
- throw Components.results.NS_NOINTERFACE;
- },
-
- }
- req.onreadystatechange = function () {
- if (req.readyState == 4) {
- uploadCallback(req);
- }
- };
- try {
- req.sendAsBinary(data);
- }
- catch (e) {
- ps.alert(
- null,
- Zotero.getString('general.error'),
- Zotero.getString('zotero.preferences.advanced.debug.error')
- );
- }
- }
-
- // Get input stream from debug output data
- var unicodeConverter =
- Components.classes["@mozilla.org/intl/scriptableunicodeconverter"]
- .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
- unicodeConverter.charset = "UTF-8";
- var bodyStream = unicodeConverter.convertToInputStream(output);
-
- // Get listener for when compression is done
- var listener = new Zotero.BufferedInputListener(bufferUploader);
-
- // Initialize stream converter
- var converter =
- Components.classes["@mozilla.org/streamconv;1?from=uncompressed&to=gzip"]
- .createInstance(Components.interfaces.nsIStreamConverter);
- converter.asyncConvertData("uncompressed", "gzip", listener, null);
-
- // Send input stream to stream converter
- var pump = Components.classes["@mozilla.org/network/input-stream-pump;1"].
- createInstance(Components.interfaces.nsIInputStreamPump);
- pump.init(bodyStream, -1, -1, 0, 0, true);
- pump.asyncRead(converter, null);
- },
-
-
- clear: function () {
- Zotero.Debug.clear();
- this.updateLines();
- },
-
-
- updateLines: function () {
- var enabled = Zotero.Debug.storing;
- var lines = Zotero.Debug.count();
- document.getElementById('debug-output-lines').value = lines;
- var empty = lines == 0;
- document.getElementById('debug-output-view').disabled = !enabled && empty;
- document.getElementById('debug-output-clear').disabled = empty;
- document.getElementById('debug-output-submit').disabled = empty;
- },
-
-
- _initTimer: function () {
- this._timer = Components.classes["@mozilla.org/timer;1"].
- createInstance(Components.interfaces.nsITimer);
- this._timer.initWithCallback({
- notify: function() {
- Zotero_Preferences.Debug_Output.updateLines();
- }
- }, 10000, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK);
- },
-
-
- _updateButton: function () {
- var storing = Zotero.Debug.storing
-
- var button = document.getElementById('debug-output-enable');
- if (storing) {
- button.label = Zotero.getString('general.disable');
- }
- else {
- button.label = Zotero.getString('general.enable');
- }
- },
-
-
- onUnload: function () {
- if (this._timer) {
- this._timer.cancel();
- }
- }
-}
-
-function onOpenURLSelected()
-{
- var openURLServerField = document.getElementById('openURLServerField');
- var openURLVersionMenu = document.getElementById('openURLVersionMenu');
- var openURLMenu = document.getElementById('openURLMenu');
-
- if(openURLMenu.value == "custom")
- {
- openURLServerField.focus();
- }
- else
- {
- openURLServerField.value = openURLResolvers[openURLMenu.selectedIndex]['url'];
- openURLVersionMenu.value = openURLResolvers[openURLMenu.selectedIndex]['version'];
- Zotero.Prefs.set("openURL.resolver", openURLResolvers[openURLMenu.selectedIndex]['url']);
- Zotero.Prefs.set("openURL.version", openURLResolvers[openURLMenu.selectedIndex]['version']);
- }
-}
-
-function onOpenURLCustomized()
-{
- document.getElementById('openURLMenu').value = "custom";
-}
-
-/** STYLES **/
-
-/**
- * Refreshes the list of styles in the styles pane
- * @param {String} cslID Style to select
- */
-function refreshStylesList(cslID) {
- var treechildren = document.getElementById('styleManager-rows');
- while (treechildren.hasChildNodes()) {
- treechildren.removeChild(treechildren.firstChild);
- }
-
- var styles = Zotero.Styles.getVisible();
-
- var selectIndex = false;
- var i = 0;
- for each(var style in styles) {
- var treeitem = document.createElement('treeitem');
- var treerow = document.createElement('treerow');
- var titleCell = document.createElement('treecell');
- var updatedCell = document.createElement('treecell');
- var cslCell = document.createElement('treecell');
-
- if (style.updated) {
- var updatedDate = Zotero.Date.formatDate(Zotero.Date.strToDate(style.updated), true);
- }
- else {
- var updatedDate = '';
- }
-
- treeitem.setAttribute('id', 'zotero-csl-' + style.styleID);
- titleCell.setAttribute('label', style.title);
- updatedCell.setAttribute('label', updatedDate);
- // if not EN
- if(style.type == "csl") {
- cslCell.setAttribute('src', 'chrome://zotero/skin/tick.png');
- }
-
- treerow.appendChild(titleCell);
- treerow.appendChild(updatedCell);
- treerow.appendChild(cslCell);
- treeitem.appendChild(treerow);
- treechildren.appendChild(treeitem);
-
- if (cslID == style.styleID) {
- document.getElementById('styleManager').view.selection.select(i);
- }
- i++;
- }
-}
-
-/**
- * Adds a new style to the style pane
- **/
-function addStyle() {
- const nsIFilePicker = Components.interfaces.nsIFilePicker;
- var fp = Components.classes["@mozilla.org/filepicker;1"]
- .createInstance(nsIFilePicker);
- fp.init(window, Zotero.getString("zotero.preferences.styles.addStyle"), nsIFilePicker.modeOpen);
-
- fp.appendFilter("CSL Style", "*.csl");
- fp.appendFilter("ENS Style", "*.ens");
-
- var rv = fp.show();
- if (rv == nsIFilePicker.returnOK || rv == nsIFilePicker.returnReplace) {
- Zotero.Styles.install(fp.file);
- }
-}
-
-/**
- * Deletes selected styles from the styles pane
- **/
-function deleteStyle() {
- // get selected cslIDs
- var tree = document.getElementById('styleManager');
- var treeItems = tree.lastChild.childNodes;
- var cslIDs = [];
- var start = {};
- var end = {};
- var nRanges = tree.view.selection.getRangeCount();
- for(var i=0; i<nRanges; i++) {
- tree.view.selection.getRangeAt(i, start, end);
- for(var j=start.value; j<=end.value; j++) {
- cslIDs.push(treeItems[j].getAttribute('id').substr(11));
- }
- }
-
- if(cslIDs.length == 0) {
- return;
- } else if(cslIDs.length == 1) {
- var selectedStyle = Zotero.Styles.get(cslIDs[0])
- var text = Zotero.getString('styles.deleteStyle', selectedStyle.title);
- } else {
- var text = Zotero.getString('styles.deleteStyles');
- }
-
- var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
- if(ps.confirm(null, '', text)) {
- // delete if requested
- if(cslIDs.length == 1) {
- selectedStyle.remove();
- } else {
- for(var i=0; i<cslIDs.length; i++) {
- Zotero.Styles.get(cslIDs[i]).remove();
- }
- }
-
- this.refreshStylesList();
- document.getElementById('styleManager-delete').disabled = true;
- }
-}
-
-/**
- * Shows an error if import fails
- **/
-function styleImportError() {
- alert(Zotero.getString('styles.installError', "This"));
-}
-
-/**PROXIES**/
-
-/**
- * Adds a proxy to the proxy pane
- */
-function showProxyEditor(index) {
- if(index == -1) return;
- window.openDialog('chrome://zotero/content/preferences/proxyEditor.xul',
- "zotero-preferences-proxyEditor", "chrome, modal", index !== undefined ? proxies[index] : null);
- refreshProxyList();
-}
-
-/**
- * Deletes the currently selected proxy
- */
-function deleteProxy() {
- if(document.getElementById('proxyTree').currentIndex == -1) return;
- proxies[document.getElementById('proxyTree').currentIndex].erase();
- refreshProxyList();
- document.getElementById('proxyTree-delete').disabled = true;
-}
-
-/**
- * Refreshes the proxy pane
- */
-function refreshProxyList() {
- if(!document.getElementById("zotero-prefpane-proxies")) return;
-
- // get and sort proxies
- proxies = Zotero.Proxies.proxies.slice();
- for(var i=0; i<proxies.length; i++) {
- if(!proxies[i].proxyID) {
- proxies.splice(i, 1);
- i--;
- }
- }
- proxies = proxies.sort(function(a, b) {
- if(a.multiHost) {
- if(b.multiHost) {
- if(a.hosts[0] < b.hosts[0]) {
- return -1;
- } else {
- return 1;
- }
- } else {
- return -1;
- }
- } else if(b.multiHost) {
- return 1;
- }
-
- if(a.scheme < b.scheme) {
- return -1;
- } else if(b.scheme > a.scheme) {
- return 1;
- }
-
- return 0;
- });
-
- // erase old children
- var treechildren = document.getElementById('proxyTree-rows');
- while (treechildren.hasChildNodes()) {
- treechildren.removeChild(treechildren.firstChild);
- }
-
- // add proxies to list
- for (var i=0; i<proxies.length; i++) {
- var treeitem = document.createElement('treeitem');
- var treerow = document.createElement('treerow');
- var hostnameCell = document.createElement('treecell');
- var schemeCell = document.createElement('treecell');
-
- hostnameCell.setAttribute('label', proxies[i].multiHost ? Zotero.getString("proxies.multiSite") : proxies[i].hosts[0]);
- schemeCell.setAttribute('label', proxies[i].scheme);
-
- treerow.appendChild(hostnameCell);
- treerow.appendChild(schemeCell);
- treeitem.appendChild(treerow);
- treechildren.appendChild(treeitem);
- }
-
- document.getElementById('proxyTree').currentIndex = -1;
- document.getElementById('proxyTree-delete').disabled = true;
- document.getElementById('zotero-proxies-transparent').checked = Zotero.Prefs.get("proxies.transparent");
- document.getElementById('zotero-proxies-autoRecognize').checked = Zotero.Prefs.get("proxies.autoRecognize");
- document.getElementById('zotero-proxies-disableByDomain-checkbox').checked = Zotero.Prefs.get("proxies.disableByDomain");
- document.getElementById('zotero-proxies-disableByDomain-textbox').value = Zotero.Prefs.get("proxies.disableByDomainString");
-}
-
-/**
- * Updates proxy autoRecognize and transparent settings based on checkboxes
- */
-function updateProxyPrefs() {
- var transparent = document.getElementById('zotero-proxies-transparent').checked;
- Zotero.Prefs.set("proxies.transparent", transparent);
- Zotero.Prefs.set("proxies.autoRecognize", document.getElementById('zotero-proxies-autoRecognize').checked);
- Zotero.Prefs.set("proxies.disableByDomainString", document.getElementById('zotero-proxies-disableByDomain-textbox').value);
- Zotero.Prefs.set("proxies.disableByDomain", document.getElementById('zotero-proxies-disableByDomain-checkbox').checked &&
- document.getElementById('zotero-proxies-disableByDomain-textbox').value != "");
-
- Zotero.Proxies.init();
-
- document.getElementById('proxyTree-add').disabled =
- document.getElementById('proxyTree-delete').disabled =
- document.getElementById('proxyTree').disabled =
- document.getElementById('zotero-proxies-autoRecognize').disabled =
- document.getElementById('zotero-proxies-disableByDomain-checkbox').disabled =
- document.getElementById('zotero-proxies-disableByDomain-textbox').disabled = !transparent;
-
-}
-
-/**
- * Determines if there are word processors, and if not, enables no word processor message
- */
-function updateWordProcessorInstructions() {
- if(document.getElementById("wordProcessors").childNodes.length == 2) {
- document.getElementById("wordProcessors-noWordProcessorPluginsInstalled").hidden = undefined;
- }
- if(Zotero.isStandalone) {
- document.getElementById("wordProcessors-getWordProcessorPlugins").hidden = true;
- }
-}
-
-/**
- * Sets "Status bar icon" to "None" if Zotero is set to load in separate tab
- */
-function handleShowInPreferenceChange() {
- var showInSeparateTab = document.getElementById("zotero-prefpane-general-showIn-separateTab");
- var showInAppTab = document.getElementById("zotero-prefpane-general-showIn-appTab");
- if(showInAppTab.selected) {
- document.getElementById('statusBarIcon').selectedItem = document.getElementById('statusBarIcon-none');
- Zotero.Prefs.set("statusBarIcon", 0);
- } else {
- document.getElementById('statusBarIcon').selectedItem = document.getElementById('statusBarIcon-full');
- Zotero.Prefs.set("statusBarIcon", 2);
- }
-}
-
-/**
- * Opens a URI in the basic viewer in Standalone, or a new window in Firefox
- */
-function openInViewer(uri, newTab) {
- var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
- .getService(Components.interfaces.nsIWindowMediator);
- const features = "menubar=yes,toolbar=no,location=no,scrollbars,centerscreen,resizable";
-
- if(Zotero.isStandalone) {
- var win = wm.getMostRecentWindow("zotero:basicViewer");
- if(win) {
- win.loadURI(uri);
- } else {
- window.openDialog("chrome://zotero/content/standalone/basicViewer.xul",
- "basicViewer", "chrome,resizable,centerscreen,menubar,scrollbars", uri);
- }
- } else {
- var win = wm.getMostRecentWindow("navigator:browser");
- if(win) {
- if(newTab) {
- win.gBrowser.selectedTab = win.gBrowser.addTab(uri);
- } else {
- win.open(uri, null, features);
- }
- }
- else {
- var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
- .getService(Components.interfaces.nsIWindowWatcher);
- var win = ww.openWindow(null, uri, null, features + ",width=775,height=575", null);
- }
- }
-}
-
-
-Zotero_Preferences.Attachment_Base_Directory = {
- choosePath: function () {
- // 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<allAttachments.length; i++) {
- let attachmentID = allAttachments[i];
-
- try {
- let attachment = Zotero.Items.get(attachmentID);
- attachmentFile.persistentDescriptor = attachment.attachmentPath;
- }
- catch (e) {
- // Don't deal with bad attachment paths. Just skip them.
- continue;
- }
-
- // If a file with the same relative path exists within the new base directory,
- // don't touch the attachment, since it will continue to work
- let isExistingRelativeAttachment = oldRelativeAttachmentIDs.indexOf(attachmentID) != -1;
- if (isExistingRelativeAttachment && oldBasePathFile) {
- let relFile = attachmentFile.clone();
- let relPath = attachmentFile.getRelativeDescriptor(oldBasePathFile);
- relFile.setRelativeDescriptor(newBasePathFile, relPath);
- if (relFile.exists()) {
- numNewAttachments++;
- continue;
- }
- }
-
- // Files within the new base directory need to be updated to use
- // relative paths (or, if the new base directory is an ancestor or
- // descendant of the old one, new relative paths)
- if (Zotero.File.directoryContains(newBasePathFile, attachmentFile)) {
- newAttachmentPaths[attachmentID] = isExistingRelativeAttachment
- ? attachmentFile.persistentDescriptor : null;
- numNewAttachments++;
- }
- // Existing relative attachments not within the new base directory
- // will be converted to absolute paths
- else if (isExistingRelativeAttachment && oldBasePathFile) {
- newAttachmentPaths[attachmentID] = attachmentFile.persistentDescriptor;
- numOldAttachments++;
- }
- }
-
- //Confirm change of the base path
- var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
-
- var chooseStrPrefix = 'attachmentBasePath.chooseNewPath.';
- var clearStrPrefix = 'attachmentBasePath.clearBasePath.';
- var title = Zotero.getString(chooseStrPrefix + 'title');
- var msg1 = Zotero.getString(chooseStrPrefix + 'message') + "\n\n", msg2 = msg3 = "";
- switch (numNewAttachments) {
- case 0:
- break;
-
- case 1:
- msg2 += Zotero.getString(chooseStrPrefix + 'existingAttachments.singular') + " ";
- break;
-
- default:
- msg2 += Zotero.getString(chooseStrPrefix + 'existingAttachments.plural', numNewAttachments) + " ";
- }
-
- switch (numOldAttachments) {
- case 0:
- break;
-
- case 1:
- msg3 += Zotero.getString(clearStrPrefix + 'existingAttachments.singular');
- break;
-
- default:
- msg3 += Zotero.getString(clearStrPrefix + 'existingAttachments.plural', numOldAttachments);
- }
-
-
- var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
- + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL);
- var index = ps.confirmEx(
- null,
- title,
- (msg1 + msg2 + msg3).trim(),
- buttonFlags,
- Zotero.getString(chooseStrPrefix + 'button'),
- null,
- null,
- null,
- {}
- );
-
- if (index == 1) {
- return false;
- }
-
- // Set new data directory
- Zotero.debug("Setting new base directory");
- Zotero.Prefs.set('baseAttachmentPath', newBasePathFile.persistentDescriptor);
- Zotero.Prefs.set('saveRelativeAttachmentPath', true);
- // Resave all attachments on base path (so that their paths become relative)
- // and all other relative attachments (so that their paths become absolute)
- for (let id in newAttachmentPaths) {
- let attachment = Zotero.Items.get(id);
- if (newAttachmentPaths[id]) {
- attachment.attachmentPath = newAttachmentPaths[id];
- attachment.save();
- }
- else {
- attachment.updateAttachmentPath();
- }
- }
- return newBasePathFile.persistentDescriptor;
- },
-
-
- getPath: function (asFile) {
- var desc = Zotero.Prefs.get('baseAttachmentPath');
- if (desc == '') {
- return asFile ? null : '';
- }
-
- var file = Components.classes["@mozilla.org/file/local;1"]
- .createInstance(Components.interfaces.nsILocalFile);
- try {
- file.persistentDescriptor = desc;
- }
- catch (e) {
- return asFile ? null : '';
- }
- return asFile ? file : file.path;
- },
-
-
- clearPath: function () {
- // Find all current attachments with relative 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 relativeAttachmentIDs = Zotero.DB.columnQuery(sql, params) || [];
-
- // Prompt for confirmation
- var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
- .getService(Components.interfaces.nsIPromptService);
-
- var strPrefix = 'attachmentBasePath.clearBasePath.';
- var title = Zotero.getString(strPrefix + 'title');
- var msg = Zotero.getString(strPrefix + 'message');
- switch (relativeAttachmentIDs.length) {
- case 0:
- break;
-
- case 1:
- msg += "\n\n" + Zotero.getString(strPrefix + 'existingAttachments.singular');
- break;
-
- default:
- msg += "\n\n" + Zotero.getString(strPrefix + 'existingAttachments.plural',
- relativeAttachmentIDs.length);
- }
-
- var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
- + (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_CANCEL);
- var index = ps.confirmEx(
- window,
- title,
- msg,
- buttonFlags,
- Zotero.getString(strPrefix + 'button'),
- null,
- null,
- null,
- {}
- );
-
- if (index == 1) {
- return false;
- }
-
- // Disable relative path saving and then resave all relative
- // attachments so that their absolute paths are stored
- Zotero.debug('Clearing base directory');
- Zotero.Prefs.set('saveRelativeAttachmentPath', false);
- for (var i=0; i<relativeAttachmentIDs.length; i++) {
- Zotero.Items.get(relativeAttachmentIDs[i]).updateAttachmentPath();
- }
- Zotero.Prefs.set('baseAttachmentPath', '');
- },
-
-
- updateUI: function () {
- var filefield = document.getElementById('baseAttachmentPath');
- var file = this.getPath(true);
- filefield.file = file;
- if (file) {
- filefield.label = file.path;
- }
- else {
- filefield.label = '';
- }
-
- document.getElementById('resetBasePath').disabled = !Zotero.Prefs.get('baseAttachmentPath');
}
-}
+};
View
844 chrome/content/zotero/preferences/preferences.xul
@@ -2,7 +2,7 @@
<!--
***** BEGIN LICENSE BLOCK *****
- Copyright © 2009 Center for History and New Media
+ Copyright © 2006–2013 Center for History and New Media
George Mason University, Fairfax, Virginia, USA
http://zotero.org
@@ -31,834 +31,52 @@
<?xml-stylesheet href="chrome://zotero/skin/zotero.css"?>
<!--
-
-To add a new preference:
- 1) Add a new <preference> to <preferences>
- 2) Add a XUL control with a 'preference' attribute
- 3) (Optional) Add additional setup/change logic to preferences.js
- 4) (Optional) To add an observer for a preference change,
- add an appropriate case in the switch statement
- in Zotero.Prefs.observe()
-
+ To add an observer for a preference change, add an appropriate case in
+ the switch statement in Zotero.Prefs.observe().
-->
-<prefwindow id="zotero-prefs" title="&zotero.preferences.title;" onload="init()" onunload="Zotero_Preferences.onUnload()"
- windowtype="zotero:pref" ondialoghelp="Zotero_Preferences.openHelpLink()"
+<prefwindow id="zotero-prefs"
+ title="&zotero.preferences.title;"
+ onload="Zotero_Preferences.init()"
+ onunload="Zotero_Preferences.onUnload()"
+ ondialoghelp="Zotero_Preferences.openHelpLink()"
+ windowtype="zotero:pref"
+ width="620"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<prefpane id="zotero-prefpane-general"
- label="&zotero.preferences.prefpane.general;"
- image="chrome://zotero/skin/prefs-general.png"
- helpTopic="general">
- <preferences id="zotero-prefpane-general-preferences">
- <preference id="pref-fontSize" name="extensions.zotero.fontSize" type="string"/>
- <preference id="pref-noteFontSize" name="extensions.zotero.note.fontSize" type="string"/>
- <preference id="pref-automaticScraperUpdates" name="extensions.zotero.automaticScraperUpdates" type="bool"/>
- <preference id="pref-reportTranslationFailure" name="extensions.zotero.reportTranslationFailure" type="bool"/>
- <preference id="pref-automaticSnapshots" name="extensions.zotero.automaticSnapshots" type="bool"/>
- <preference id="pref-downloadAssociatedFiles" name="extensions.zotero.downloadAssociatedFiles" type="bool"/>
- <preference id="pref-automaticTags" name="extensions.zotero.automaticTags" type="bool"/>
- <preference id="pref-trashAutoEmptyDays" name="extensions.zotero.trashAutoEmptyDays" type="int"/>
-
- <preference id="pref-groups-copyChildNotes" name="extensions.zotero.groups.copyChildNotes" type="bool"/>
- <preference id="pref-groups-copyChildFileAttachments" name="extensions.zotero.groups.copyChildFileAttachments" type="bool"/>
- <preference id="pref-groups-copyChildLinks" name="extensions.zotero.groups.copyChildLinks" type="bool"/>
- <preference id="pref-groups-copyTags" name="extensions.zotero.groups.copyTags" type="bool"/>
- </preferences>
-
- <groupbox id="zotero-prefpane-general-groupbox">
- <caption label="&zotero.preferences.userInterface;"/>
-
- <grid id="zotero-prefpane-general-grid">
- <columns>
- <column/>
- <column flex="1"/>
- </columns>
-
- <rows id="zotero-prefpane-general-rows">
- <row>
- <hbox align="center">
- <label value="&zotero.preferences.fontSize;" control="fontSize"/>
- </hbox>
- <radiogroup id="fontSize" orient="horizontal" align="center" preference="pref-fontSize">
- <radio id="fontSize1" label="&zotero.preferences.fontSize.small;" value="1.0"/>
- <radio id="fontSize2" label="&zotero.preferences.fontSize.medium;" value="1.15"/>
- <radio id="fontSize3" label="&zotero.preferences.fontSize.large;" value="1.3"/>
- <radio id="fontSize4" label="&zotero.preferences.fontSize.xlarge;" value="1.5"/>
- </radiogroup>
- </row>
-
- <row>
- <hbox align="center">
- <label value="&zotero.preferences.fontSize.notes;" control="noteFontSize"/>
- </hbox>
- <hbox>
- <menulist id="noteFontSize" preference="pref-noteFontSize" editable="true">
- <menupopup>
- <menuitem label="11"/>
- <menuitem label="12"/>
- <menuitem label="13"/>
- <menuitem label="14"/>
- <menuitem label="18"/>
- <menuitem label="24"/>
- <menuitem label="36"/>
- <menuitem label="48"/>
- <menuitem label="64"/>
- <menuitem label="72"/>
- <menuitem label="96"/>
- </menupopup>
- </menulist>
- </hbox>
- </row>
- </rows>
- </grid>
-
- <label class="statusLine" value="&zotero.preferences.keys.changesTakeEffect;"/>
- </groupbox>
-
- <groupbox id="zotero-prefpane-miscellaneous-groupbox">
- <caption label="&zotero.preferences.miscellaneous;"/>
-
- <hbox align="center">
- <checkbox label="&zotero.preferences.autoUpdate;" preference="pref-automaticScraperUpdates"/>
- <button id="updateButton" style="margin-top:0" label="&zotero.preferences.updateNow;" oncommand="updateTranslators()"/>
- </hbox>
-
- <checkbox label="&zotero.preferences.reportTranslationFailure;" preference="pref-reportTranslationFailure"/>
- <checkbox id="automaticSnapshots-checkbox"
- label="&zotero.preferences.automaticSnapshots;"
- preference="pref-automaticSnapshots"/>
- <checkbox label="&zotero.preferences.downloadAssociatedFiles;" preference="pref-downloadAssociatedFiles"/>
- <checkbox label="&zotero.preferences.automaticTags;" preference="pref-automaticTags"/>
- <hbox align="center">
- <label value="&zotero.preferences.trashAutoEmptyDaysPre;"/>
- <textbox size="2" preference="pref-trashAutoEmptyDays"/>
- <label value="&zotero.preferences.trashAutoEmptyDaysPost;"/>
- </hbox>
- </groupbox>
-
- <groupbox>
- <caption label="&zotero.preferences.groups;"/>
-
- <label value="&zotero.preferences.groups.whenCopyingInclude;"/>
- <vbox style="margin-left: 2em">
- <checkbox label="&zotero.preferences.groups.childNotes;" preference="pref-groups-copyChildNotes"/>
- <checkbox label="&zotero.preferences.groups.childFiles;" preference="pref-groups-copyChildFileAttachments"/>
- <checkbox label="&zotero.preferences.groups.childLinks;" preference="pref-groups-copyChildLinks"/>
- <checkbox label="&zotero.preferences.groups.tags;" preference="pref-groups-copyTags"/>
- </vbox>
- </groupbox>
-
- <separator/>
- </prefpane>
-
+ label="&zotero.preferences.prefpane.general;"
+ image="chrome://zotero/skin/prefs-general.png"
+ src="chrome://zotero/content/preferences/preferences_general.xul"/>
<prefpane id="zotero-prefpane-sync"
- label="&zotero.preferences.prefpane.sync;"
- onpaneload="document.getElementById('sync-password').value = Zotero.Sync.Server.password; var pass = Zotero.Sync.Storage.WebDAV.password; if (pass) { document.getElementById('storage-password').value = pass; }"
- image="chrome://zotero/skin/prefs-sync.png"
- helpTopic="sync">
- <preferences>
- <preference id="pref-sync-autosync" name="extensions.zotero.sync.autoSync" type="bool"/>
- <preference id="pref-sync-username" name="extensions.zotero.sync.server.username" type="string" instantApply="true"/>
- <preference id="pref-storage-enabled" name="extensions.zotero.sync.storage.enabled" type="bool"/>
- <preference id="pref-storage-protocol" name="extensions.zotero.sync.storage.protocol" type="string" onchange="unverifyStorageServer()"/>
- <preference id="pref-storage-scheme" name="extensions.zotero.sync.storage.scheme" type="string" instantApply="true"/>
- <preference id="pref-storage-url" name="extensions.zotero.sync.storage.url" type="string"/>
- <preference id="pref-storage-username" name="extensions.zotero.sync.storage.username" type="string"/>
- <preference id="pref-storage-downloadMode-personal" name="extensions.zotero.sync.storage.downloadMode.personal" type="string"/>
- <preference id="pref-storage-downloadMode-groups" name="extensions.zotero.sync.storage.downloadMode.groups" type="string"/>
- <preference id="pref-group-storage-enabled" name="extensions.zotero.sync.storage.groups.enabled" type="bool"/>
- </preferences>
-
- <tabbox>
- <tabs>
- <tab label="&zotero.preferences.settings;"/>
- <tab label="&zotero.preferences.sync.reset;"/>
- </tabs>
-
- <tabpanels>
- <tabpanel orient="vertical">
- <groupbox>
- <caption label="&zotero.preferences.sync.syncServer;"/>
-
- <hbox>
- <grid>
- <columns>
- <column/>
- <column/>
- </columns>
-
- <rows>
- <row>
- <label value="&zotero.preferences.sync.username;"/>
- <textbox preference="pref-sync-username"
- onchange="this.value = this.value.trim(); Zotero.Prefs.set('sync.server.username', this.value); var pass = document.getElementById('sync-password'); if (pass.value) { Zotero.Sync.Server.password = pass.value; }"/>
- </row>
- <row>
- <label value="&zotero.preferences.sync.password;"/>
- <textbox id="sync-password" type="password"
- onchange="Zotero.Sync.Server.password = this.value"/>
- </row>
- <row>
- <box/>
- <checkbox label="&zotero.preferences.sync.syncAutomatically;" preference="pref-sync-autosync"/>
- </row>
- <!--
- <row>
- <box/>
- <hbox>
- <button label="Verify login"
- oncommand="alert('Unimplemented')"/>
- </hbox>
- </row>
- -->
- </rows>
- </grid>
-
- <hbox style="width:2em"/>
-
- <vbox>
- <label class="zotero-text-link" value="&zotero.preferences.sync.about;" href="http://www.zotero.org/support/sync"/>
- <separator class="thin"/>
- <label class="zotero-text-link" value="&zotero.preferences.sync.createAccount;" href="http://zotero.org/user/register"/>
- <separator class="thin"/>
- <label class="zotero-text-link" value="&zotero.preferences.sync.lostPassword;" href="http://zotero.org/user/lostpassword"/>
- </vbox>
- </hbox>
- </groupbox>
-
-
- <groupbox id="storage-settings">
- <caption label="&zotero.preferences.sync.fileSyncing;"/>
-
- <!-- My Library -->
- <hbox>
- <checkbox label="&zotero.preferences.sync.fileSyncing.myLibrary;" preference="pref-storage-enabled" oncommand="updateStorageSettings(this.checked, null)"/>
- <menulist id="storage-protocol" class="storage-personal" style="margin-left: .5em" preference="pref-storage-protocol" oncommand="updateStorageSettings(null, this.value)">
- <menupopup>
- <menuitem label=