2011-01-30 09:44:01 +00:00
|
|
|
/*
|
|
|
|
***** 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
|
2011-05-18 18:34:22 +00:00
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
2011-01-30 09:44:01 +00:00
|
|
|
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
|
2011-05-18 18:34:22 +00:00
|
|
|
GNU Affero General Public License for more details.
|
2011-01-30 09:44:01 +00:00
|
|
|
|
2011-05-18 18:34:22 +00:00
|
|
|
You should have received a copy of the GNU Affero General Public License
|
2011-01-30 09:44:01 +00:00
|
|
|
along with Zotero. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
***** END LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-05-31 05:32:45 +00:00
|
|
|
Components.utils.import("resource://gre/modules/Services.jsm");
|
|
|
|
|
|
|
|
/**
|
2011-01-30 09:44:01 +00:00
|
|
|
* This object contains the various functions for the interface
|
|
|
|
*/
|
|
|
|
var ZoteroStandalone = new function()
|
|
|
|
{
|
2011-07-02 03:09:13 +00:00
|
|
|
/**
|
|
|
|
* Run when standalone window first opens
|
|
|
|
*/
|
2011-01-30 09:44:01 +00:00
|
|
|
this.onLoad = function() {
|
2011-02-10 01:53:15 +00:00
|
|
|
if(!Zotero || !Zotero.initialized) {
|
|
|
|
ZoteroPane.displayStartupError();
|
|
|
|
window.close();
|
2011-02-10 01:58:47 +00:00
|
|
|
return;
|
2011-02-10 01:53:15 +00:00
|
|
|
}
|
2011-01-30 09:44:01 +00:00
|
|
|
ZoteroPane.init();
|
2011-02-10 01:53:15 +00:00
|
|
|
ZoteroPane.makeVisible();
|
2011-05-31 04:35:47 +00:00
|
|
|
|
|
|
|
// Run check for corrupt installation, where the wrong Gecko runtime is being used
|
|
|
|
if(Zotero.isMac) {
|
|
|
|
var greDir = Components.classes["@mozilla.org/file/directory_service;1"]
|
|
|
|
.getService(Components.interfaces.nsIProperties)
|
|
|
|
.get("GreD", Components.interfaces.nsIFile);
|
|
|
|
if(greDir.isSymlink() || greDir.leafName !== "Current") {
|
|
|
|
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
|
|
|
|
.getService(Components.interfaces.nsIPromptService);
|
|
|
|
ps.alert(null, "", Zotero.getString('standalone.corruptInstallation'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-03 06:27:04 +00:00
|
|
|
// 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);
|
|
|
|
for each(var scheme in ["http", "https"]) {
|
|
|
|
var handlerInfo = eps.getProtocolHandlerInfo(scheme);
|
|
|
|
handlerInfo.preferredAction = Components.interfaces.nsIHandlerInfo.useSystemDefault;
|
|
|
|
handlerInfo.alwaysAskBeforeHandling = false;
|
|
|
|
hs.store(handlerInfo);
|
|
|
|
}
|
2011-01-30 09:44:01 +00:00
|
|
|
}
|
|
|
|
|
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 i in typeSets) {
|
|
|
|
var t = typeSets[i];
|
|
|
|
|
|
|
|
// 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("oncommand","ZoteroPane_Local.newItem("+itemTypes[i]['id']+")");
|
|
|
|
menuitem.setAttribute("tooltiptext", "");
|
|
|
|
menuitem.className = "zotero-tb-add";
|
|
|
|
addMenu.appendChild(menuitem);
|
|
|
|
}
|
|
|
|
|
|
|
|
// add separator between sets
|
|
|
|
if(i !== typeSets.length-1) {
|
|
|
|
addMenu.appendChild(document.createElement("menuseparator"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-02 07:16:24 +00:00
|
|
|
/**
|
|
|
|
* Opens a URL in the basic viewer
|
|
|
|
*/
|
|
|
|
this.openInViewer = function(uri) {
|
|
|
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
|
|
|
.getService(Components.interfaces.nsIWindowMediator);
|
|
|
|
var win = wm.getMostRecentWindow("zotero:basicViewer");
|
|
|
|
if(win) {
|
|
|
|
win.loadURI(uri);
|
|
|
|
} else {
|
|
|
|
window.openDialog("chrome://zotero/content/standalone/basicViewer.xul",
|
|
|
|
"basicViewer", "chrome,resizable,centerscreen", uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-02 03:09:13 +00:00
|
|
|
/**
|
|
|
|
* Handles help menu requests
|
|
|
|
*/
|
2011-05-31 06:34:21 +00:00
|
|
|
this.openHelp = function(type) {
|
|
|
|
if(type === "troubleshooting") {
|
|
|
|
ZoteroPane.loadURI("http://www.zotero.org/support/getting_help");
|
|
|
|
} else if(type === "feedback") {
|
|
|
|
ZoteroPane.loadURI("http://forums.zotero.org/categories/");
|
|
|
|
} else {
|
|
|
|
ZoteroPane.loadURI("http://www.zotero.org/support/");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-11 14:54:51 +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
|
|
|
|
*/
|
2011-01-30 09:44:01 +00:00
|
|
|
this.onUnload = function() {
|
|
|
|
ZoteroPane.destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-31 05:32:45 +00:00
|
|
|
/** 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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-30 09:44:01 +00:00
|
|
|
window.addEventListener("load", function(e) { ZoteroStandalone.onLoad(e); }, false);
|
|
|
|
window.addEventListener("unload", function(e) { ZoteroStandalone.onUnload(e); }, false);
|