-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
98 changed files
with
2,796 additions
and
2,176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
build | ||
build | ||
run.cmd | ||
run7.cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,25 @@ | ||
/* Copyright 2012 Will Shanks. | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
if (typeof Zotero == "undefined") { | ||
var Zotero; | ||
var Zotero_Tabs; | ||
if (typeof Zotero == 'undefined') { | ||
var Zotero; | ||
} | ||
|
||
var chromeHandle; | ||
var Zotero_Tabs; | ||
var ZeNotes; | ||
var Menu; | ||
var Data; | ||
var Database; | ||
var Ui; | ||
var Format; | ||
var Utils | ||
|
||
const ANNOTATION = 1; | ||
const ATTACHMENT = 3; | ||
const NOTE = 28; | ||
|
||
let mainWindowListener; | ||
|
||
function log(msg) { | ||
Zotero.debug("ZeNotes: " + msg); | ||
} | ||
|
||
// In Zotero 6, bootstrap methods are called before Zotero is initialized, and using include.js | ||
// to get the Zotero XPCOM service would risk breaking Zotero startup. Instead, wait for the main | ||
|
@@ -17,115 +28,228 @@ var chromeHandle; | |
// In Zotero 7, bootstrap methods are not called until Zotero is initialized, and the 'Zotero' is | ||
// automatically made available. | ||
async function waitForZotero() { | ||
if (typeof Zotero != "undefined") { | ||
await Zotero.initializationPromise; | ||
} | ||
|
||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); | ||
var windows = Services.wm.getEnumerator("navigator:browser"); | ||
var found = false; | ||
while (windows.hasMoreElements()) { | ||
let win = windows.getNext(); | ||
if (win.Zotero) { | ||
Zotero = win.Zotero; | ||
Zotero_Tabs = win.Zotero_Tabs; | ||
found = true; | ||
break; | ||
} | ||
} | ||
if (!found) { | ||
await new Promise((resolve) => { | ||
var listener = { | ||
onOpenWindow: function (aWindow) { | ||
// Wait for the window to finish loading | ||
let domWindow = aWindow | ||
.QueryInterface(Ci.nsIInterfaceRequestor) | ||
.getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow); | ||
domWindow.addEventListener( | ||
"load", | ||
function () { | ||
domWindow.removeEventListener("load", arguments.callee, false); | ||
if (domWindow.Zotero) { | ||
Services.wm.removeListener(listener); | ||
Zotero = domWindow.Zotero; | ||
Zotero_Tabs = domWindow.Zotero_Tabs; | ||
resolve(); | ||
} | ||
}, | ||
false | ||
); | ||
}, | ||
}; | ||
Services.wm.addListener(listener); | ||
}); | ||
} | ||
await Zotero.initializationPromise; | ||
if (typeof Zotero != 'undefined') { | ||
await Zotero.initializationPromise; | ||
return; | ||
} | ||
|
||
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); | ||
var windows = Services.wm.getEnumerator('navigator:browser'); | ||
var found = false; | ||
while (windows.hasMoreElements()) { | ||
let win = windows.getNext(); | ||
if (win.Zotero) { | ||
Zotero = win.Zotero; | ||
found = true; | ||
break; | ||
} | ||
} | ||
if (!found) { | ||
await new Promise((resolve) => { | ||
var listener = { | ||
onOpenWindow: function (aWindow) { | ||
// Wait for the window to finish loading | ||
let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor) | ||
.getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow); | ||
domWindow.addEventListener("load", function () { | ||
domWindow.removeEventListener("load", arguments.callee, false); | ||
if (domWindow.Zotero) { | ||
Services.wm.removeListener(listener); | ||
Zotero = domWindow.Zotero; | ||
resolve(); | ||
} | ||
}, false); | ||
} | ||
}; | ||
Services.wm.addListener(listener); | ||
}); | ||
} | ||
await Zotero.initializationPromise; | ||
} | ||
|
||
function install(data, reason) {} | ||
|
||
async function startup({ id, version, resourceURI, rootURI }, reason) { | ||
await waitForZotero(); | ||
|
||
// String 'rootURI' introduced in Zotero 7 | ||
if (!rootURI) { | ||
rootURI = resourceURI.spec; | ||
} | ||
|
||
const window = Zotero.getMainWindow(); | ||
|
||
// Global variables for plugin code | ||
const ctx = { | ||
Zotero, | ||
Zotero_Tabs: Zotero_Tabs, | ||
rootURI, | ||
window, | ||
document: window.document, | ||
ZoteroPane: Zotero.getActiveZoteroPane(), | ||
}; | ||
|
||
Services.scriptloader.loadSubScript( | ||
`chrome://zenotes/content/zenotes.js`, | ||
ctx | ||
); | ||
|
||
Zotero.ZeNotes.initdisplay(); | ||
|
||
if (Zotero.platformMajorVersion >= 102) | ||
{ | ||
var aomStartup = Components.classes[ | ||
"@mozilla.org/addons/addon-manager-startup;1" | ||
].getService(Components.interfaces.amIAddonManagerStartup); | ||
var manifestURI = Services.io.newURI(rootURI + "manifest.json"); | ||
chromeHandle = aomStartup.registerChrome(manifestURI, [ | ||
["content", "__addonRef__", rootURI + "chrome/content/"], | ||
["locale", "__addonRef__", "en-US", rootURI + "chrome/locale/en-US/"], | ||
["locale", "__addonRef__", "ja-JA", rootURI + "chrome/locale/ja-JA/"], | ||
// Adds main window open/close listeners in Zotero 6 | ||
function listenForMainWindowEvents() { | ||
mainWindowListener = { | ||
onOpenWindow: function (aWindow) { | ||
let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor) | ||
.getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow); | ||
async function onload() { | ||
domWindow.removeEventListener("load", onload, false); | ||
if (domWindow.location.href !== "chrome://zotero/content/standalone/standalone.xul") { | ||
return; | ||
} | ||
onMainWindowLoad({ window: domWindow }); | ||
} | ||
domWindow.addEventListener("load", onload, false); | ||
}, | ||
onCloseWindow: async function (aWindow) { | ||
let domWindow = aWindow.QueryInterface(Ci.nsIInterfaceRequestor) | ||
.getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow); | ||
if (domWindow.location.href !== "chrome://zotero/content/standalone/standalone.xul") { | ||
return; | ||
} | ||
onMainWindowUnload({ window: domWindow }); | ||
}, | ||
}; | ||
Services.wm.addListener(mainWindowListener); | ||
} | ||
|
||
function removeMainWindowListener() { | ||
if (mainWindowListener) { | ||
Services.wm.removeListener(mainWindowListener); | ||
} | ||
} | ||
|
||
// Loads default preferences from prefs.js in Zotero 6 | ||
function setDefaultPrefs(rootURI) { | ||
var branch = Services.prefs.getDefaultBranch(""); | ||
var obj = { | ||
pref(pref, value) { | ||
switch (typeof value) { | ||
case 'boolean': | ||
branch.setBoolPref(pref, value); | ||
break; | ||
case 'string': | ||
branch.setStringPref(pref, value); | ||
break; | ||
case 'number': | ||
branch.setIntPref(pref, value); | ||
break; | ||
default: | ||
Zotero.logError(`Invalid type '${typeof(value)}' for pref '${pref}'`); | ||
} | ||
} | ||
}; | ||
Services.scriptloader.loadSubScript(rootURI + "prefs.js", obj); | ||
} | ||
|
||
function registerchrome(rootURI){ | ||
var aomStartup = Cc["@mozilla.org/addons/addon-manager-startup;1"].getService(Ci.amIAddonManagerStartup); | ||
|
||
var manifestURI = Services.io.newURI(rootURI + "manifest.json"); | ||
chromeHandle = aomStartup.registerChrome(manifestURI, [ | ||
["content", "ze-notes", "pages/"], | ||
["assets", "ze-notes", "assets/"], | ||
]); | ||
} | ||
} | ||
|
||
function shutdown({ id, version, resourceURI, rootURI }, reason) { | ||
if (reason === APP_SHUTDOWN) { | ||
return; | ||
} | ||
if (typeof Zotero === "undefined") { | ||
Zotero = Components.classes["@zotero.org/Zotero;1"].getService( | ||
Components.interfaces.nsISupports | ||
).wrappedJSObject; | ||
} | ||
Zotero.AddonTemplate.events.onUnInit(Zotero); | ||
|
||
Cc["@mozilla.org/intl/stringbundle;1"] | ||
.getService(Components.interfaces.nsIStringBundleService) | ||
.flushBundles(); | ||
|
||
Cu.unload(`chrome://zenotes/content/zenotes.js`); | ||
|
||
if (chromeHandle) { | ||
chromeHandle.destruct(); | ||
chromeHandle = null; | ||
} | ||
function initPreferences(rootURI) { | ||
|
||
/* already done in chrome.manifest | ||
Keep for the day it becomes obsolete | ||
registerchrome(rootURI); | ||
*/ | ||
|
||
if (Zotero.platformMajorVersion < 102) { | ||
/* | ||
Try to implement native preference in Zotero 6 | ||
*/ | ||
} | ||
else | ||
{ | ||
registerchrome(rootURI); | ||
Zotero.PreferencePanes.register({ | ||
pluginID: '[email protected]', | ||
id: '[email protected]', | ||
stylesheets: [ | ||
rootURI + 'pages/settings/preferences.css', | ||
rootURI + 'pages/lib/fontawesome/6.1.1/css/all.min.css', | ||
], | ||
src: rootURI + 'pages/settings/preferences.xhtml', | ||
scripts: [ | ||
rootURI + 'pages/settings/zntable.js', | ||
rootURI + 'pages/settings/preferences.js', | ||
], | ||
image: rootURI+"/assets/zenotes-settings.png" | ||
}); | ||
} | ||
} | ||
|
||
function uninstall(data, reason) {} | ||
async function install() { | ||
await waitForZotero(); | ||
log("Installed ZeNotes"); | ||
} | ||
|
||
async function startup({ id, version, resourceURI, rootURI = resourceURI.spec }) { | ||
await waitForZotero(); | ||
log("Starting Ze-Notes"); | ||
|
||
initPreferences(rootURI); | ||
Zotero.createXULElement = function(doc, tag) { | ||
let XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; | ||
return doc.createElementNS(XUL_NS, tag); | ||
} | ||
|
||
// 'Services' may not be available in Zotero 6 | ||
if (typeof Services == 'undefined') { | ||
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); | ||
} | ||
|
||
if (Zotero.platformMajorVersion < 102) { | ||
// Listen for window load/unload events in Zotero 6, since onMainWindowLoad/Unload don't | ||
// get called | ||
listenForMainWindowEvents(); | ||
// Read prefs from prefs.js in Zotero 6 | ||
setDefaultPrefs(rootURI); | ||
} | ||
|
||
Services.scriptloader.loadSubScript(rootURI + 'core/utils.js'); | ||
Services.scriptloader.loadSubScript(rootURI + 'core/zenotes.js'); | ||
Services.scriptloader.loadSubScript(rootURI + 'core/ui.js'); | ||
Services.scriptloader.loadSubScript(rootURI + 'core/menu.js'); | ||
|
||
Services.scriptloader.loadSubScript(rootURI + 'core/data.js'); | ||
Services.scriptloader.loadSubScript(rootURI + 'core/database.js'); | ||
Services.scriptloader.loadSubScript(rootURI + 'core/prefs.js'); | ||
Services.scriptloader.loadSubScript(rootURI + 'core/format.js'); | ||
|
||
ZeNotes.init({ id, version, rootURI }); | ||
Zotero.ZeNotes = ZeNotes; | ||
ZeNotes.addToAllWindows(); | ||
|
||
Zotero_Tabs = Zotero.getMainWindow().Zotero_Tabs; | ||
Menu.addToAllWindows(); | ||
ZeNotes.Ui = Ui; | ||
ZeNotes.Menu = Menu; | ||
ZeNotes.Utils = Utils; | ||
|
||
ZeNotes.Data = Data; | ||
ZeNotes.Database = Database; | ||
ZeNotes.Prefs = Prefs; | ||
ZeNotes.Format = Format; | ||
Database.create(); | ||
await ZeNotes.main(); | ||
} | ||
|
||
function onMainWindowLoad({ window }) { | ||
ZeNotes.addToWindow(window); | ||
} | ||
|
||
function onMainWindowUnload({ window }) { | ||
ZeNotes.removeFromWindow(window); | ||
} | ||
|
||
function shutdown() { | ||
log("Shutting down 1.2"); | ||
|
||
if (Zotero.platformMajorVersion < 102) { | ||
removeMainWindowListener(); | ||
} | ||
else | ||
{ | ||
chromeHandle.destruct(); | ||
} | ||
|
||
ZeNotes.removeFromAllWindows(); | ||
ZeNotes = undefined; | ||
} | ||
|
||
function uninstall() { | ||
// `Zotero` object isn't available in `uninstall()` in Zotero 6, so log manually | ||
if (typeof Zotero == 'undefined') { | ||
dump("ZeNotes: Uninstalled\n\n"); | ||
return; | ||
} | ||
|
||
log("Uninstalled 1.2"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
content zenotes chrome/content/zenotes/ | ||
locale zenotes en-US chrome/locale/en-US/zenotes/ | ||
#add later | ||
#locale zenotes ja-JP chrome/locale/ja-JP/zenotes/ | ||
skin zenotes default chrome/skin/default/zenotes/ | ||
|
||
#overlay chrome://zotero/content/zoteroPane.xul chrome://zenotes/content/overlay.xul | ||
locale Ze-Notes en-US chrome/locale/en-US/ | ||
content Ze-Notes pages/ | ||
skin Ze-Notes chrome/skin/ |
Oops, something went wrong.