zotero/chrome/content/zotero/standalone/standalone.js

236 lines
7.4 KiB
JavaScript
Raw Normal View History

/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2009 Center for History and New Media
George Mason University, Fairfax, Virginia, USA
http://zotero.org
This file is part of Zotero.
Zotero is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Zotero is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
***** END LICENSE BLOCK *****
*/
Components.utils.import("resource://gre/modules/Services.jsm");
/**
* This object contains the various functions for the interface
*/
const ZoteroStandalone = new function() {
2011-07-02 03:09:13 +00:00
/**
* Run when standalone window first opens
*/
this.onLoad = function() {
Async DB megacommit Promise-based rewrite of most of the codebase, with asynchronous database and file access -- see https://github.com/zotero/zotero/issues/518 for details. WARNING: This includes backwards-incompatible schema changes. An incomplete list of other changes: - Schema overhaul - Replace main tables with new versions with updated schema - Enable real foreign key support and remove previous triggers - Don't use NULLs for local libraryID, which broke the UNIQUE index preventing object key duplication. All code (Zotero and third-party) using NULL for the local library will need to be updated to use 0 instead (already done for Zotero code) - Add 'compatibility' DB version that can be incremented manually to break DB compatibility with previous versions. 'userdata' upgrades will no longer automatically break compatibility. - Demote creators and tags from first-class objects to item properties - New API syncing properties - 'synced'/'version' properties to data objects - 'etag' to groups - 'version' to libraries - Create Zotero.DataObject that other objects inherit from - Consolidate data object loading into Zotero.DataObjects - Change object reloading so that only the loaded and changed parts of objects are reloaded, instead of reloading all data from the database (with some exceptions, including item primary data) - Items and collections now have .parentItem and .parentKey properties, replacing item.getSource() and item.getSourceKey() - New function Zotero.serial(fn), to wrap an async function such that all calls are run serially - New function Zotero.Utilities.Internal.forEachChunkAsync(arr, chunkSize, func) - Add tag selector loading message - Various API and name changes, since everything was breaking anyway Known broken things: - Syncing (will be completely rewritten for API syncing) - Translation architecture (needs promise-based rewrite) - Duplicates view - DB integrity check (from schema changes) - Dragging (may be difficult to fix) Lots of other big and little things are certainly broken, particularly with the UI, which can be affected by async code in all sorts of subtle ways.
2014-08-06 21:38:05 +00:00
Zotero.Promise.try(function () {
if(!Zotero) {
throw true;
}
2016-02-07 06:51:07 +00:00
if(Zotero.initializationPromise.isPending()) {
Zotero.showZoteroPaneProgressMeter();
}
return Zotero.initializationPromise;
})
.then(function () {
if (Zotero.Prefs.get('devtools.errorconsole.enabled', true)) {
document.getElementById('menu_errorConsole').hidden = false;
}
Zotero.hideZoteroPaneOverlays();
ZoteroPane.init();
ZoteroPane.makeVisible();
// Don't ask before handing http and https URIs
var eps = Components.classes['@mozilla.org/uriloader/external-protocol-service;1']
.getService(Components.interfaces.nsIExternalProtocolService);
var hs = Components.classes["@mozilla.org/uriloader/handler-service;1"]
.getService(Components.interfaces.nsIHandlerService);
2016-05-03 21:51:12 +00:00
for (let scheme of ["http", "https"]) {
var handlerInfo = eps.getProtocolHandlerInfo(scheme);
handlerInfo.preferredAction = Components.interfaces.nsIHandlerInfo.useSystemDefault;
handlerInfo.alwaysAskBeforeHandling = false;
hs.store(handlerInfo);
}
// Add add-on listeners (not yet hooked up)
Services.obs.addObserver(gXPInstallObserver, "addon-install-disabled", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-started", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-blocked", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-failed", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-complete", false);
})
.catch(function (e) {
try { Zotero.debug(e, 1); } catch (e) {}
Components.utils.reportError(e);
2011-02-10 01:53:15 +00:00
ZoteroPane.displayStartupError();
window.close();
return;
});
}
2011-07-02 03:09:13 +00:00
/**
* Builds new item menu
*/
this.buildNewItemMenu = function() {
var addMenu = document.getElementById('menu_NewItemPopup');
// Remove all nodes so we can regenerate
while(addMenu.hasChildNodes()) addMenu.removeChild(addMenu.firstChild);
var typeSets = [Zotero.ItemTypes.getPrimaryTypes(), Zotero.ItemTypes.getSecondaryTypes()];
for(var j=0; j<typeSets.length; j++) {
var t = typeSets[j];
2011-07-02 03:09:13 +00:00
// Sort by localized name
var itemTypes = [];
for (var i=0; i<t.length; i++) {
itemTypes.push({
id: t[i].id,
name: t[i].name,
localized: Zotero.ItemTypes.getLocalizedString(t[i].id)
});
}
var collation = Zotero.getLocaleCollation();
itemTypes.sort(function(a, b) {
return collation.compareString(1, a.localized, b.localized);
});
for (var i = 0; i<itemTypes.length; i++) {
var menuitem = document.createElement("menuitem");
menuitem.setAttribute("label", itemTypes[i].localized);
menuitem.setAttribute("tooltiptext", "");
let type = itemTypes[i].id;
menuitem.addEventListener("command", function() {
ZoteroPane_Local.newItem(type, null, null, true);
}, false);
2011-07-02 03:09:13 +00:00
menuitem.className = "zotero-tb-add";
addMenu.appendChild(menuitem);
}
// add separator between sets
if(j !== typeSets.length-1) {
2011-07-02 03:09:13 +00:00
addMenu.appendChild(document.createElement("menuseparator"));
}
}
}
this.updateAddonsPane = function (doc) {
// Hide unsigned add-on verification warnings
//
// This only works for the initial load of the window. If the user switches to Appearance
// or Plugins and then back to Extensions, the warnings will appear again. A better way to
// disable this might be discoverable by studying
// https://dxr.mozilla.org/mozilla-central/source/toolkit/mozapps/extensions/content/extensions.js
var addonList = doc.getElementById('addon-list');
setTimeout(function () {
for (let i = 0; i < addonList.itemCount; i++) {
let richListItem = addonList.getItemAtIndex(i);
let container = doc.getAnonymousElementByAttribute(
richListItem, 'anonid', 'warning-container'
);
if (container) {
let link = doc.getAnonymousElementByAttribute(
richListItem, 'anonid', 'warning-link'
);
if (link && link.href.indexOf('unsigned-addons') != -1) {
richListItem.removeAttribute('notification');
container.hidden = true;
}
}
}
});
2011-07-02 07:16:24 +00:00
}
2011-07-02 03:09:13 +00:00
/**
* Handles help menu requests
*/
2011-05-31 06:34:21 +00:00
this.openHelp = function(type) {
switch (type) {
case "troubleshooting":
ZoteroPane.loadURI(ZOTERO_CONFIG.TROUBLESHOOTING_URL);
break;
case "feedback":
ZoteroPane.loadURI(ZOTERO_CONFIG.FEEDBACK_URL);
break;
case "extensions":
ZoteroPane.loadURI(ZOTERO_CONFIG.EXTENSIONS_URL);
break;
default:
ZoteroPane.loadURI(ZOTERO_CONFIG.SUPPORT_URL);
2011-05-31 06:34:21 +00:00
}
}
/**
* Checks for updates
*/
this.checkForUpdates = function() {
window.open('chrome://mozapps/content/update/updates.xul', 'updateChecker', 'chrome,centerscreen');
}
2011-07-02 03:09:13 +00:00
/**
* Called before standalone window is closed
*/
this.onUnload = function() {
ZoteroPane.destroy();
goQuitApplication();
}
}
/** Taken from browser.js **/
function toJavaScriptConsole() {
toOpenWindowByType("global:console", "chrome://global/content/console.xul");
}
function toOpenWindowByType(inType, uri, features)
{
var topWindow = Services.wm.getMostRecentWindow(inType);
if (topWindow) {
topWindow.focus();
} else if(features) {
window.open(uri, "_blank", features);
} else {
window.open(uri, "_blank", "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar");
}
}
const gXPInstallObserver = {
observe: function (aSubject, aTopic, aData) {
var installInfo = aSubject.QueryInterface(Components.interfaces.amIWebInstallInfo);
var win = installInfo.originatingWindow;
switch (aTopic) {
case "addon-install-disabled":
case "addon-install-blocked":
case "addon-install-failed":
var promptService = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
promptService.alert(win, Zotero.getString("standalone.addonInstallationFailed.title"),
Zotero.getString("standalone.addonInstallationFailed.body", installInfo.installs[0].name));
break;
/*case "addon-install-started":
case "addon-install-complete":*/
}
}
};
2017-01-16 07:56:58 +00:00
// Used by update prompt
function openUILinkIn(url) {
ZoteroPane.loadURI(url);
}
window.addEventListener("load", function(e) { ZoteroStandalone.onLoad(e); }, false);
window.addEventListener("unload", function(e) { ZoteroStandalone.onUnload(e); }, false);