diff --git a/.eslintrc.json b/.eslintrc.json index f5b189b..505dad5 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -225,7 +225,7 @@ "prefer-arrow-callback": "off", "prefer-const": "off", "prefer-destructuring": "off", - "prefer-named-capture-group": "error", + "prefer-named-capture-group": "off", "prefer-numeric-literals": "error", "prefer-object-spread": "error", "prefer-promise-reject-errors": "error", diff --git a/CHANGELOG.md b/CHANGELOG.md index 68b5bb2..5128e60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,90 @@ -* In version 3.2.0b: +* In version 4.0.1: + + Fixes for Zotero 7.1 + +* In version 4.0.0: + + + Fixes for Zotero 7.0 + + New copy item IDs function + +* In version 3.10.0: + + + Fixes for Zotero 5.0.97-beta and upcoming Zotero 6 + +* In version 3.9.0: + + + Fix Open Style Editor shortcut + + Add Open Run JavaScript window shortcut + + Add mdnotes shortcuts + + Update French translations + +* In version 3.8.1: + + + Update French translations + + Fix ZotFile Quick Extract shortcut + + Fix show file shortcut + +* In version 3.8.0: + + + Add find available PDFs shortcut + +* In version 3.7.0: + + + Add ZotFile Quick Extract shortcut + +* In version 3.6.1: + + + Update French locale + +* In version 3.6.0: + + + Add "Paste item type" function for batch item type changes + + Update French locale + + Documentation updates + +* In version 3.5.0: + + + Add "Open Zotero URI" function + + Allow arbitrary number of alt quick copy functions + + Fix "Retrieve metadata for PDF" shortcut + + Update French locale + +* In version 3.4.0: + + + Added shortcut for pushing reference to TeXstudio with Better BibTeX + + Add "Advanced search" shortcut + + Add "Locate item" shortcut + + Add "Show Locate menu" shortcut + + Add tag selector shortcuts: + - Toggle displaying automatic tags + - Toggle displaying all tags + - Deselect all tags + - Focus search box + +* In version 3.3.3: + + + Filter attachments by mode before trying to modify paths + +* In version 3.3.2: + + + Fix mishandling of attachments with paths that did not match the old path pattern in the modify attachments function. + +* In version 3.3.1: + + + Fix add tag shortcut for Zotero 5.0.78 + +* In version 3.3.0: + + + Added shortcut for ZotFile's move and rename attachment + +* In version 3.2.1: + + + Compatibility updates for Zotero 5.0.75 + +* In version 3.2.0: + + + Drop support for Zotero as a Firefox addon and for Zotero 4.x + + Update item select link to newer format used by recent version of Zotero + Add functions to copy select links and web links to collections + Add copy/paste item field functions diff --git a/Makefile b/Makefile index 4968c3c..0d203fe 100644 --- a/Makefile +++ b/Makefile @@ -3,12 +3,11 @@ BLDDIR = build LOCALES := $(shell ls i18n) INTERNAL_READMES := $(patsubst %, addon/chrome/locale/%/zutilo/README.html, $(LOCALES)) -AMO_READMES := $(patsubst %, $(BLDDIR)/amo_readme/%/README.html, $(LOCALES)) # Necessary because zip copies leading directories if run from above targets ABS_BLDDIR := $(shell realpath $(BLDDIR)) -all: xpi amo_readme +all: xpi 0x0: $(BLDDIR)/zutilo.xpi curl -F'file=@$(BLDDIR)/zutilo.xpi' https://0x0.st @@ -26,25 +25,10 @@ addon/chrome/locale/%/zutilo/README.html: $(BLDDIR)/internal_readme/$*/README.md > \ addon/chrome/locale/$*/zutilo/README.html -amo_readme: $(AMO_READMES) - -$(BLDDIR)/amo_readme/%/README.html: - @mkdir -p $(dir $@) - scripts/substitute_relative_links \ - --link-root https://www.github.com/willsALMANJ/Zutilo/blob/master/i18n/$*/readme \ - i18n/$*/readme/README.md \ - $(BLDDIR)/amo_readme/$*/README.md - pandoc -f markdown_strict -t html \ - $(BLDDIR)/amo_readme/$*/README.md > \ - $(BLDDIR)/amo_readme/$*/README.html - # Strip tags not allowed on addons.mozilla.org - sed -e 's/

//' -e 's#

#\n#' -e 's/h[1-9]>/strong>/g' -e 's#br />#\n#' \ - -i $(BLDDIR)/amo_readme/$*/README.html - clean: rm -f $(BLDDIR)/zutilo.xpi rm -f $(INTERNAL_READMES) rm -f $(AMO_READMES) rm -rf $(BLDDIR)/internal_readme/* -.PHONY: all clean xpi amo_readme +.PHONY: all clean xpi diff --git a/README.md b/README.md index 0cb2f26..33f4266 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Zutilo -Zutilo is a plugin for [Zotero](http://www.zotero.org/) (both the Firefox addon and the standalone client). +Zutilo is a plugin for [Zotero](http://www.zotero.org/). Zutilo adds several functions not available in base Zotero through extra menu items and keyboard shortcuts. Here are some of Zutilo's features: @@ -7,25 +7,33 @@ Here are some of Zutilo's features: * Select and right-click to relate several items * Copy items to the clipboard in several formats * Keyboard shortcuts for editing items and focusing and hiding different elements of the Zotero user interface -* Right-click to save link or document as an attachment to currently selected item (only for Zotero as a Firefox addon) Zutilo strives to enable whatever Zotero workflow is desired and otherwise to get out of the way. All of Zutilo's graphical elements can be disabled individually, so that unwanted features do not clutter the user interface. -**NOTE:** As of version 3.0, Zutilo is distributed from the [GitHub releases page](https://github.com/willsALMANJ/Zutilo/releases). -New updates will not be published to the location checked by previous versions of Zutilo (the Mozilla Add-ons page). -To receive new Zutilo updates, please update to the latest version of Zutilo. +> [!NOTE] +> Zutilo is largely maintained by one person (@wshanks) who does not have much time for Zutilo any more. +> @wshanks still uses Zotero but not as heavily and so has less need for the power user features of Zutilo. +> Additional help adapting to new releases of Zotero and fixing other bugs is very welcome. +> Without additional contributors, Zutilo may not be able to keep compatibility with future releases of Zotero. +> As of Zotero version 7.0, some features of Zutilo, mainly keyboard shortcuts, no longer function. +> There was also a long gap between the release of Zotero 7 and a release of Zutilo that could be installed with it. ## Installation -Download the Zutilo `zutilo.xpi` file from [Zutilo's GitHub releases page](https://github.com/willsALMANJ/Zutilo/releases). +Download the Zutilo `zutilo.xpi` file from [Zutilo's GitHub releases page](https://github.com/wshanks/Zutilo/releases). Then go to Tools->Add-ons in Zotero Standalone. Click on the gear button in the upper right area of the Add-ons Manager window that appears and choose "Install Add-on From File." Then select the downloaded `zutilo.xpi` file. +**NOTE for Firefox users:** Firefox treats `.xpi` files as Firefox add-ons and tries to install them. +Rather than clicking on the `.xpi` file, you can try right-clicking and choosing to save the link as a file. +In some cases (particularly on Linux), Firefox does not allow right-clicking and saving the `.xpi` link either. +In that case, you must download it either with a different browser or with a command-line tool like `curl` or `wget`. + ## Getting started -Zutilo can be customized via its preferences window, which can reached either via the Firefox Addons Manager or the Zotero action menu (the gear icon). +Zutilo can be customized via its preferences window, which can reached via the Zotero Addons Manager or the Tools menu. ### Zotero item menu @@ -40,18 +48,7 @@ All of the functions that can appear in the item menu can also be called by keyb Zutilo also provides some additional keyboard shortcut functions that are not available from the item menu. By default, no keyboard shortcuts are defined. A shortcut key combination can be set for each function in Zutilo's preferences. -If the key combination is already assigned for another Firefox function, a warning will be displayed. - -### Firefox specific functions - -Zutilo adds entries to the Zotero address bar icon's menu for saving items into Zotero with the opposite attachment behavior from that set in Zotero's preferences. -So if you have Zotero set to download attachments when saving an item, Zutilo will add an entry to save the item without attachments. -The extra menu items can be disabled in Zutilo's preferences. - -Zutilo adds two entries to right-click menu in Firefox, one to save the current page as an attachment (most useful when the page is a pdf) and another to save a link as an attachment (if a link was right-clicked). -These menu items appear the Zotero submenu of the Firefox right-click menu. -In Zutilo's preferences, the menu items can be set to appear in the right-click menu directly (instead of the Zotero submenu) or can be disabled. -Whether the attachment files are imported to Zotero or downloaded and linked to Zotero items can be also be set in Zutilo's preferences. +If the key combination is already assigned for another function, a warning will be displayed. ## Usage notes diff --git a/addon/bootstrap.js b/addon/bootstrap.js index f8c9362..f3b0a06 100644 --- a/addon/bootstrap.js +++ b/addon/bootstrap.js @@ -5,23 +5,12 @@ "use strict"; /* global Components, Services */ -/* global Zutilo */ +/* global Zutilo, APP_SHUTDOWN */ const {classes: Cc, utils: Cu} = Components; +var chromeHandle Cu.import("resource://gre/modules/Services.jsm"); -const BOOTSTRAP_REASONS = [ - "", // the bootstrap reason is 1 based - "APP_STARTUP", - "APP_SHUTDOWN", - "ADDON_ENABLE", - "ADDON_DISABLE", - "ADDON_INSTALL", - "ADDON_UNINSTALL", - "ADDON_UPGRADE", - "ADDON_DOWNGRADE" -]; - // eslint-disable-next-line no-unused-vars function install(data, reason) { @@ -29,8 +18,19 @@ function install(data, reason) { // eslint-disable-next-line no-unused-vars function startup(data, reason) { - Cu.import("chrome://zutilo/content/zutilo.jsm"); - Zutilo.init(); + let aomStartup = Cc["@mozilla.org/addons/addon-manager-startup;1"].getService(Ci.amIAddonManagerStartup) + let manifestURI = Services.io.newURI(data.rootURI + "manifest.json"); + chromeHandle = aomStartup.registerChrome(manifestURI, [ + ["content", "zutilo", "chrome/content/zutilo/"], + ["locale", "zutilo", "en-US", "chrome/locale/en-US/zutilo/"], + ["locale", "zutilo", "de", "chrome/locale/de/zutilo/"], + ["locale", "zutilo", "es", "chrome/locale/es/zutilo/"], + ["locale", "zutilo", "fr", "chrome/locale/fr/zutilo/"], + ["locale", "zutilo", "zh-CN", "chrome/locale/zh-CN/zutilo/"] + ]) + + Cu.import("chrome://zutilo/content/zutilo.js"); + Zutilo.init(data.rootURI, Zotero); } // eslint-disable-next-line no-unused-vars @@ -44,9 +44,6 @@ function shutdown(data, reason) { var tmpWin=windows.getNext(); tmpWin.ZutiloChrome.removeXUL(); - if (typeof tmpWin.ZutiloChrome.firefoxOverlay != 'undefined') { - tmpWin.ZutiloChrome.firefoxOverlay.unload(); - } if (typeof tmpWin.ZutiloChrome.zoteroOverlay != 'undefined') { tmpWin.ZutiloChrome.zoteroOverlay.unload(); } @@ -55,11 +52,13 @@ function shutdown(data, reason) { } Zutilo.cleanup(); + chromeHandle.destruct() + chromeHandle = null Cc["@mozilla.org/intl/stringbundle;1"]. getService(Components.interfaces.nsIStringBundleService).flushBundles(); - Cu.unload("chrome://zutilo/content/zutilo.jsm"); + Cu.unload("chrome://zutilo/content/zutilo.js"); } // eslint-disable-next-line no-unused-vars diff --git a/addon/chrome/content/zutilo/firefoxOverlay.js b/addon/chrome/content/zutilo/firefoxOverlay.js deleted file mode 100644 index d94159e..0000000 --- a/addon/chrome/content/zutilo/firefoxOverlay.js +++ /dev/null @@ -1,513 +0,0 @@ -/* 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/. */ - -'use strict'; -/* global gBrowser, window, document, Components, Services */ -/* global Zotero, Zotero_Browser */ -/* global Zutilo, ZutiloChrome */ -Components.utils.import('resource://gre/modules/Services.jsm'); -/******************************************/ -// Include core modules -/******************************************/ -Components.utils.import('chrome://zutilo/content/zutilo.jsm'); - -/******************************************/ -// Firefox overlay -/******************************************/ -ZutiloChrome.firefoxOverlay = { - warnedThisSession: false, - cleanupQueue: [], - isScraping: false, - scrapeTimeout: null, - - init: function() { - window.setTimeout(function() { - if (typeof ZutiloChrome != 'undefined') { - Zutilo.checkZoteroActiveAndCallIf(false, - ZutiloChrome.firefoxOverlay, - ZutiloChrome.firefoxOverlay.warnZoteroNotActive); - var overlayFunc = function() {this.firefoxZoteroOverlay()} - Zutilo.checkZoteroActiveAndCallIf(true, - ZutiloChrome.firefoxOverlay, - overlayFunc); - } - }, 500); - }, - - unload: function() { - for (var index = 0; index < this.cleanupQueue.length; index++) { - this.cleanupQueue[index](); - } - }, - - warnZoteroNotActive: function() { - var showWarn = Zutilo.Prefs.get('warnZoteroNotActive'); - - if (showWarn && !this.warnedThisSession) { - window.openDialog('chrome://zutilo/content/zoteroNotActive.xul', - 'zutilo-zoteroNotActive-window', 'chrome,centerscreen'); - this.warnedThisSession = true; - } - }, - - /**************************************************************************/ - // Load Firefox-specific overlay that is relevant only when Zotero is active - /**************************************************************************/ - firefoxZoteroOverlay: function() { - this.refreshContentAreaContextMenu = refreshContentAreaContextMenu; - this.scrapeThisPage = scrapeThisPage - - setupContentAreaContextMenu() - setupStatusPopup() - }, - - /**************************************************************************/ - // Attach link functions - /**************************************************************************/ - - /* Attach the file located at url to the currently selected item in Zotero. - - url: string with url to attach - processType: string mode to use for processing the attachment. If - unspecified, determine from Zutilo preferences and mimeType - Possible values.... - Zotero: use Zotero's default import and filenaming. - prompt: prompt the user for a file location, import attach with - Zotero, and then move the attachment to the file location and - change to linked file attachment - ZotFile: import using Zotero and then pass the attachment to - ZotFile.renameAttachment() - */ - attachURLToCurrentItem: function(url, processType) { - // Error check item selection and get Zotero item - var zitems = ZutiloChrome.zoteroOverlay.getSelectedItems('regular'); - if (!ZutiloChrome.zoteroOverlay.checkItemNumber(zitems, - 'regularSingle')) { - return - } - var zitem = zitems[0]; - - this.attachURLToItem(zitem, url, processType); - }, - - attachURLToItem: function(zitem, url, processType) { - var allowedProcesses = ['prompt', 'Zotero', 'promptAfterOne']; - if (allowedProcesses.indexOf(processType) == -1) { - processType = Zutilo.Prefs.get('attachmentImportProcessType'); - } - - // Prompt if there is an existing non-snapshot attachment - if (processType == 'promptAfterOne') { - var attachments = Zotero.Items.get(zitem.getAttachments(false)); - var existingAttachments = false; - // Check for existing non-snapshot attachments - for (var index = 0; index < attachments.length; index++) { - if (!(attachments[index].attachmentLinkMode == - Zotero.Attachments.LINK_MODE_IMPORTED_URL && - attachments[index].attachmentMIMEType != - 'application/pdf')) { - existingAttachments = true; - break - } - } - if (existingAttachments) { - processType = 'prompt'; - } else { - processType = 'Zotero'; - } - } - - function mimeCallback(mimeType, _hasNativeHandler) { - function zoteroImport(attachmentCallback) { - if (Zotero.version.split('.')[0] < 5) { - // XXX: Legacy 4.0 - Zotero.Attachments.importFromURL(url, zitem.id, undefined, - undefined, - undefined, mimeType, - undefined, - attachmentCallback) - } else { - Zotero.Promise.coroutine(function*() { - let attachmentItem = - yield Zotero.Attachments.importFromURL( - {url: url, - parentItemID: zitem.id, - contentType: mimeType}) - if (attachmentCallback !== null) { - attachmentCallback(attachmentItem) - } - })() - } - } - - function moveAttachment(attachmentItem) { - var nsIFilePicker = Components.interfaces.nsIFilePicker; - var fp = Components.classes['@mozilla.org/filepicker;1'] - .createInstance(nsIFilePicker); - var strName = 'zutilo.attachments.selectDestination'; - fp.init(window, - Zutilo._bundle.GetStringFromName(strName), - nsIFilePicker.modeSave); - fp.appendFilters(nsIFilePicker.filterAll); - - var importedFile = attachmentItem.getFile(); - fp.defaultString = ZutiloChrome.firefoxOverlay. - adjustZoteroExtension(url, importedFile.leafName) - - fp.open(function(result) { - if (result == nsIFilePicker.returnOK || - result == nsIFilePicker.returnReplace) { - // Move attachment file to chosen directory and - // attach as linked file. - importedFile.moveTo(fp.file.parent, - fp.file.leafName); - if (Zotero.version.split('.')[0] < 5) { - // XXX: Legacy 4.0 - Zotero.Attachments.linkFromFile(fp.file, - zitem.itemID) - } else { - Zotero.Attachments. - linkFromFile({file: fp.file, - parentItemID: zitem.itemID}) - } - } - if (Zotero.version.split('.')[0] < 5) { - // XXX: Legacy 4.0 - attachmentItem.erase() - } else { - attachmentItem.eraseTx() - } - }) - } - - // Choose process type for mimeType - if (processType == 'prompt') { - // Prompt for file name and location - zoteroImport(moveAttachment) - } else if (processType == 'Zotero') { - // Use Zotero importFromURL() - zoteroImport(function() {}); - } - } - - if (Zotero.version.split('.')[0] < 5) { - // XXX: Legacy 4.0 - Zotero.MIME.getMIMETypeFromURL(url, mimeCallback) - } else { - Zotero.MIME.getMIMETypeFromURL(url).then(function(result) { - mimeCallback(result[0], result[1]) - }) - } - }, - - adjustZoteroExtension: function(url, zoteroFileName) { - /* Zotero compresses file extensions based on MIME type (e.g. all - text files get converted to '.txt'. Here we try to put back the - original extension if it can be guessed from the URL. We have to be - conservative though because sometimes URL's are misleading (e.g. pdf's - on arxiv.org whose urls don't include the 'pdf' part) and Zotero gets - them right by looking at the MIME type. */ - var extensionPosition = url.lastIndexOf('.'); - var urlExtension = - extensionPosition == -1 ? '' : url.substr(extensionPosition + 1); - if (urlExtension.length == 3 || urlExtension.length == 4) { - var re = new RegExp('[a-z]', 'i'); - if (re.test(urlExtension[0])) { - zoteroFileName = zoteroFileName.substr(0, - zoteroFileName.lastIndexOf('.')) + '.' + urlExtension; - } - } - - return zoteroFileName - } -}; - -/************************************************************************/ -// Firefox contentAreaContextMenu -/************************************************************************/ - -function setupContentAreaContextMenu() { - var FFContAreaContMenu = document. - getElementById('contentAreaContextMenu'); - var ZoteroSubmenu = document. - getElementById('zotero-content-area-context-menu'); - - appendCACMCommandItems(FFContAreaContMenu, 'zutilo-ffcacm-', - ZoteroSubmenu.nextSibling); - - var ZoteroSubmenuPopup = document. - getElementById('zotero-context-item-from-page').parentElement; - var ZoteroSubmenuSeparator = document.createElement('menuseparator'); - var ZoteroSubmenuSeparatorID = 'zutilo-ffcacm-zoterosubmenu-separator'; - ZoteroSubmenuSeparator. - setAttribute('id', 'zutilo-ffcacm-zoterosubmenu-separator'); - ZoteroSubmenuPopup.appendChild(ZoteroSubmenuSeparator); - ZutiloChrome.XULRootElements.push(ZoteroSubmenuSeparatorID); - appendCACMCommandItems(ZoteroSubmenuPopup, - 'zutilo-ffcacm-zoterosubmenu-'); - - FFContAreaContMenu.addEventListener('popupshowing', - ZutiloChrome.firefoxOverlay.refreshContentAreaContextMenu, false); - ZutiloChrome.firefoxOverlay.cleanupQueue.push(cleanupFFCACM); -} - -// CACM = contentAreaContextMenu -function appendCACMCommandItems(parentElement, IDPrefix, nextElement) { - - var attachPageCmd = function(event) { - var processType; - if (event.shiftKey) { - processType = 'prompt'; - } else if (event.ctrlKey) { - processType = 'Zotero'; - } - ZutiloChrome.firefoxOverlay.attachURLToCurrentItem( - gBrowser.currentURI.spec, processType); - }; - - var attachLinkCmd = function(event) { - var processType; - if (event.shiftKey) { - processType = 'prompt'; - } else if (event.ctrlKey) { - processType = 'Zotero'; - } - ZutiloChrome.firefoxOverlay.attachURLToCurrentItem( - window.gContextMenu.linkURL, processType); - }; - - var commands = [attachPageCmd, attachLinkCmd]; - - for (var index = 0; index < Zutilo.ffcacmFunctions.length; index++) { - appendCACMSingleItem(parentElement, IDPrefix, - Zutilo.ffcacmFunctions[index].name, - commands[index], nextElement); - } -} - -function appendCACMSingleItem(parentElement, IDPrefix, IDSuffix, command, - nextElement) { - var menuEl = document.createElement('menuitem'); - var elementID = IDPrefix + IDSuffix; - menuEl.setAttribute('id', elementID); - menuEl.setAttribute('label', - Zutilo._bundle.GetStringFromName('zutilo.ffcacm.' + IDSuffix)); - menuEl.addEventListener('command', command, false); - parentElement.insertBefore(menuEl, nextElement); - ZutiloChrome.XULRootElements.push(elementID); -} - -function refreshContentAreaContextMenu() { - var showMenuSeparator = false; - - for (var index = 0; index < Zutilo.ffcacmFunctions.length; index++) { - var prefVal = Zutilo.Prefs.get( - Zutilo.ffcacmFunctions[index].name + 'Appearance'); - - var ffcacmMenuItem = document.getElementById( - 'zutilo-ffcacm-' + Zutilo.ffcacmFunctions[index].name); - var zoteroMenuItem = document.getElementById( - 'zutilo-ffcacm-zoterosubmenu-' + - Zutilo.ffcacmFunctions[index].name); - - var doNotShow = false; - if (Zutilo.ffcacmFunctions[index].condition == 'onLink') { - if (!window.gContextMenu.onLink) { - doNotShow = true; - } - } - - if (prefVal == 'Firefox') { - zoteroMenuItem.hidden = true; - ffcacmMenuItem.hidden = doNotShow; - } else if (prefVal == 'Zotero') { - ffcacmMenuItem.hidden = true; - zoteroMenuItem.hidden = doNotShow; - if (!doNotShow) { - showMenuSeparator = true; - } - } else { - zoteroMenuItem.hidden = true; - ffcacmMenuItem.hidden = true; - } - } - - var menuSeparator = - document.getElementById('zutilo-ffcacm-zoterosubmenu-separator'); - if (showMenuSeparator) { - menuSeparator.hidden = false; - } else { - menuSeparator.hidden = true; - } -} - -function cleanupFFCACM() { - var FFContAreaContMenu = document. - getElementById('contentAreaContextMenu'); - FFContAreaContMenu.removeEventListener('popupshowing', - ZutiloChrome.firefoxOverlay.refreshContentAreaContextMenu, false); -} - - -/**************************************************************************/ -// Status bar icon functions -/**************************************************************************/ -function getStatusPopup() { - var statusPopupEl = [] - var oldElement = document. - getElementById('zotero-status-image-context'); - // For version > 4.0.26.1 - if (oldElement) { - statusPopupEl.push(oldElement) - } else { - for (let buttonID of ['zotero-toolbar-save-button', - 'zotero-toolbar-save-button-single']) { - let statusButton = document.getElementById(buttonID) - if (statusButton) { - statusPopupEl.push(statusButton.children[0]) - } - } - } - - return statusPopupEl -} - -function setupStatusPopup() { - var statusPopupEl = getStatusPopup() - for (let menupopup of statusPopupEl) { - menupopup.addEventListener('popupshowing', statusPopupListener, false) - } - - if (statusPopupEl) { - ZutiloChrome.firefoxOverlay.cleanupQueue.push(cleanupStatusPopup) - } -} -ZutiloChrome.firefoxOverlay.setupStatusPopup = setupStatusPopup - -function cleanupStatusPopup() { - var statusPopupEl = getStatusPopup() - if (statusPopupEl) { - for (let menupopup of statusPopupEl) { - menupopup.removeEventListener('popupshowing', - statusPopupListener, false) - } - } -} - -function statusPopupListener(e) { - if (!Zutilo.Prefs.get('showStatusPopupItems')) { - return - } - - var popup = e.target; - - // Get array of relevant status popup entries that correspond to normal - // translators which might download attachment items. - var translatorEntries = [] - for (let entry of popup.children) { - if (entry.tagName == 'menuseparator') { - break - } else { - translatorEntries.push(entry) - } - } - - // Ignore the last two entries before the first menuseparator because they - // are generic web page translators. - translatorEntries.splice(translatorEntries.length - 2, 2) - if (translatorEntries.length === 0) { - return - } - - // Add menu separator and new entries - var menuSep = document.createElement('menuseparator'); - menuSep.setAttribute('id', 'zutilo-zoterostatuspopup-menusep'); - popup.appendChild(menuSep); - - // New entries should have callbacks that call doCommand on existing - // entries and watch isScraping to change associated files preference - for (let entry of translatorEntries) { - addStatusEntry(popup, entry) - } -} - -function addStatusEntry(popup, entry) { - var labelEnd - var strRoot = 'zutilo.pagescrape.statusPopup.' - if (Zotero.Prefs.get('downloadAssociatedFiles')) { - labelEnd = ' ' + Zutilo._bundle. - GetStringFromName(strRoot + 'noAttachments') - } else { - labelEnd = ' ' + Zutilo._bundle. - GetStringFromName(strRoot + 'withAttachments') - } - - var menuitem = document.createElement('menuitem') - var label = entry.label + labelEnd - menuitem.setAttribute('label', label) - menuitem.setAttribute('class', 'menuitem-iconic') - - menuitem.addEventListener('command', - function(e) { - // Must stop propagation to prevent Zotero - // from also saving item with its default - // behavior - e.stopPropagation() - scrapeThisPage('opposite', entry)}, - false); - popup.appendChild(menuitem); -} - -function scrapeThisPage(filesBehavior, entry) { - // Don't allow simultaneous scraping - if (Zotero_Browser.isScraping) { - let strRoot = 'zutilo.pagescrape.multipleExecution.' - Services.prompt.alert(null, - Zutilo._bundle. - GetStringFromName(strRoot + 'title'), - Zutilo._bundle. - GetStringFromName(strRoot + 'body')) - return - } - - // Default to default translator - if (typeof entry === 'undefined') { - entry = document.getElementById('zotero-toolbar-save-button') - } - - // Flip associated files pref - let filesBool = Zotero.Prefs.get('downloadAssociatedFiles') - if (filesBehavior == 'with') { - Zotero.Prefs.set('downloadAssociatedFiles', true) - } else if (filesBehavior == 'without') { - Zotero.Prefs.set('downloadAssociatedFiles', false) - } else { - // opposite - Zotero.Prefs.set('downloadAssociatedFiles', !filesBool) - } - - // Define clean up actions to restore previous state after scraping - function cleanupScraping() { - Zotero.Prefs.set('downloadAssociatedFiles', filesBool) - Zotero_Browser.unwatch('isScraping') - ZutiloChrome.firefoxOverlay.isScraping = false - window.clearTimeout(ZutiloChrome.firefoxOverlay.scrapeTimeout) - } - - // Watch for end of scraping so that clean up can be done - Zotero_Browser.watch('isScraping', function(id, oldval, newval) { - if (newval === false) { - cleanupScraping() - } - }) - - // Set timer to clean up if watch never triggers (due to some failure) - ZutiloChrome.firefoxOverlay.scrapeTimeout = - window.setTimeout(cleanupScraping, 60000) - - // Start translation - ZutiloChrome.firefoxOverlay.isScraping = true - entry.doCommand() -} diff --git a/addon/chrome/content/zutilo/keyconfig_adapted.js b/addon/chrome/content/zutilo/keyconfig_adapted.js index 3f2ed93..a6e4bb3 100644 --- a/addon/chrome/content/zutilo/keyconfig_adapted.js +++ b/addon/chrome/content/zutilo/keyconfig_adapted.js @@ -9,7 +9,6 @@ /* global Zutilo */ var Cc = Components.classes var Ci = Components.interfaces -Components.utils.import('resource://gre/modules/Services.jsm'); var gPrefService = Components.classes['@mozilla.org/preferences-service;1']. getService(Components.interfaces.nsIPrefService).getBranch(''); @@ -22,21 +21,20 @@ var gPlatformKeys = {}; var gVKNames = []; var gKeynames = { - 'BrowserReload();': Zutilo._bundle. - GetStringFromName('zutilo.shortcuts.reload'), - goBackKb2: Zutilo._bundle.GetStringFromName('zutilo.shortcuts.goBack'), - goForwardKb2: Zutilo._bundle.GetStringFromName('zutilo.shortcuts.goForward') + 'BrowserReload();': Zutilo.getString('zutilo.shortcuts.reload'), + goBackKb2: Zutilo.getString('zutilo.shortcuts.goBack'), + goForwardKb2: Zutilo.getString('zutilo.shortcuts.goForward') } gKeynames['BrowserReloadSkipCache();'] = gKeynames['Browser:ReloadSkipCache'] = - Zutilo._bundle.GetStringFromName('zutilo.shortcuts.reloadSkipCache'); + Zutilo.getString('zutilo.shortcuts.reloadSkipCache'); if (gPrefService.getPrefType('browser.backspace_action')) { if (gPrefService.getIntPref('browser.backspace_action') === 0) { // jscs:disable requireCamelCaseOrUpperCaseIdentifiers gKeynames.cmd_handleBackspace = - Zutilo._bundle.GetStringFromName('zutilo.shortcuts.goBack'); + Zutilo.getString('zutilo.shortcuts.goBack'); gKeynames.cmd_handleShiftBackspace = - Zutilo._bundle.GetStringFromName('zutilo.shortcuts.goForward'); + Zutilo.getString('zutilo.shortcuts.goForward'); // jscs:enable requireCamelCaseOrUpperCaseIdentifiers } } @@ -98,10 +96,10 @@ function keyconfigOnLoad() { function formatKey(key) { if (key.modifiers == 'shift,alt,control,accel' && key.keycode == 'VK_SCROLL_LOCK') { - return Zutilo._bundle.GetStringFromName('zutilo.shortcuts.disabled'); + return Zutilo.getString('zutilo.shortcuts.disabled'); } if (!key.key && !key.keycode) { - return Zutilo._bundle.GetStringFromName('zutilo.shortcuts.disabled'); + return Zutilo.getString('zutilo.shortcuts.disabled'); } var val = ''; @@ -128,8 +126,7 @@ function formatKey(key) { val += gLocaleKeys.getString(key.keycode) } catch (e) { var unrecognizedStr = - Zutilo._bundle. - GetStringFromName('zutilo.shortcuts.unrecognized'); + Zutilo.getString('zutilo.shortcuts.unrecognized'); val += unrecognizedStr.replace('$1', key.keycode); } } @@ -197,7 +194,7 @@ function applyShortcut() { // eslint-disable-next-line no-unused-vars function Disable() { - gEdit.value = Zutilo._bundle.GetStringFromName('zutilo.shortcuts.disabled'); + gEdit.value = Zutilo.getString('zutilo.shortcuts.disabled'); gEdit.key = {modifiers: '', key: '', keycode: ''}; applyShortcut(); } @@ -247,8 +244,8 @@ function noConflictingKeys(checkKey) { // OK = no conflict; cancel = conflict var strRoot = 'zutilo.shortcuts.conflicts.' noConflict = Services.prompt.confirm(window, - Zutilo._bundle.GetStringFromName(strRoot + 'promptTitle'), - Zutilo._bundle.GetStringFromName(strRoot + 'promptText') + + Zutilo.getString(strRoot + 'promptTitle'), + Zutilo.getString(strRoot + 'promptText') + nameList.join('\n')); } @@ -342,7 +339,7 @@ function getNameForKey(win, keyNode) { } if (!val) { - val = Zutilo._bundle.GetStringFromName('zutilo.shortcuts.unlabeled'); + val = Zutilo.getString('zutilo.shortcuts.unlabeled'); } return val diff --git a/addon/chrome/content/zutilo/keys.js b/addon/chrome/content/zutilo/keys.js index 59aad7e..a4f18b4 100644 --- a/addon/chrome/content/zutilo/keys.js +++ b/addon/chrome/content/zutilo/keys.js @@ -12,8 +12,7 @@ // Include core modules and built-in modules /********************************************/ Components.utils.import('resource://gre/modules/AddonManager.jsm'); -Components.utils.import('resource://gre/modules/Services.jsm'); -Components.utils.import('chrome://zutilo/content/zutilo.jsm'); +Components.utils.import('chrome://zutilo/content/zutilo.js'); /********************************************/ // Define keys object @@ -28,8 +27,7 @@ var keys = { }, keyName: function(keyLabel) { - var name = Zutilo._bundle.GetStringFromName('zutilo.shortcuts.name.' + - keyLabel) + var name = Zutilo.getString('zutilo.shortcuts.name.' + keyLabel) return name }, @@ -51,10 +49,31 @@ var keys = { }, categoryName: function(categoryLabel) { - return Zutilo._bundle.GetStringFromName('zutilo.shortcuts.category.' + - categoryLabel) + return Zutilo.getString('zutilo.shortcuts.category.' + categoryLabel) }, + refreshAlts: function() { + for (let alt in Zutilo.keys.alts) { + let deletions = [] + for (let shortcut in Zutilo.keys.shortcuts) { + if (shortcut.startsWith(alt)) { + deletions.push(shortcut) + } + } + for (let shortcut of deletions) { + delete Zutilo.keys.shortcuts[shortcut] + delete Zutilo.keys.categories[shortcut] + } + + let total = Zutilo.Prefs.get(alt + '_total') + for (let altNum = 1; altNum < total + 1; altNum++) { + Zutilo.keys.categories[alt + altNum] = Zutilo.keys.alts[alt]['category'] + Zutilo.keys.shortcuts[alt + altNum] = Zutilo.keys.alts[alt]['generator'](altNum) + } + } + }, + + alts: {}, categories: {}, shortcuts: {} }; @@ -106,22 +125,30 @@ keys.categories.copyItems = 'copying' keys.shortcuts.copyItems = function(win) { win.ZutiloChrome.zoteroOverlay.copyItems() }; -keys.categories.copyItems_alt1 = 'copying' -keys.shortcuts.copyItems_alt1 = function(win) { - win.ZutiloChrome.zoteroOverlay.copyItems_alt1() -}; -keys.categories.copyItems_alt2 = 'copying' -keys.shortcuts.copyItems_alt2 = function(win) { - win.ZutiloChrome.zoteroOverlay.copyItems_alt2() -}; +keys.alts.copyItems_alt = { + 'category': 'copying', + 'generator': function(altNum) { + return function(win) { + win.ZutiloChrome.zoteroOverlay.copyItems_alt(altNum) + } + } +} keys.categories.copyZoteroSelectLink = 'copying' keys.shortcuts.copyZoteroSelectLink = function(win) { win.ZutiloChrome.zoteroOverlay.copyZoteroSelectLink() }; +keys.categories.copyZoteroItemID = 'copying' +keys.shortcuts.copyZoteroItemID = function(win) { + win.ZutiloChrome.zoteroOverlay.copyZoteroItemID() +}; keys.categories.copyZoteroItemURI = 'copying' keys.shortcuts.copyZoteroItemURI = function(win) { win.ZutiloChrome.zoteroOverlay.copyZoteroItemURI() }; +keys.categories.openZoteroItemURI = 'other' +keys.shortcuts.openZoteroItemURI = function(win) { + win.ZutiloChrome.zoteroOverlay.openZoteroItemURI() +}; keys.categories.createBookItem = 'itemcreation' keys.shortcuts.createBookItem = function(win) { win.ZutiloChrome.zoteroOverlay.createBookItem() @@ -138,6 +165,38 @@ keys.categories.relocateChildren = 'itemediting' keys.shortcuts.relocateChildren = function(win) { win.ZutiloChrome.zoteroOverlay.relocateChildren() }; +keys.categories.copyJSON = 'copying' +keys.shortcuts.copyJSON = function(win) { + win.ZutiloChrome.zoteroOverlay.copyJSON() +} +keys.categories.pasteJSONIntoEmptyFields = 'itemediting' +keys.shortcuts.pasteJSONIntoEmptyFields = function(win) { + win.ZutiloChrome.zoteroOverlay.pasteJSONIntoEmptyFields() +} +keys.categories.pasteJSONFromNonEmptyFields = 'itemediting' +keys.shortcuts.pasteJSONFromNonEmptyFields = function(win) { + win.ZutiloChrome.zoteroOverlay.pasteJSONFromNonEmptyFields() +} +keys.categories.pasteJSONAll = 'itemediting' +keys.shortcuts.pasteJSONAll = function(win) { + win.ZutiloChrome.zoteroOverlay.pasteJSONAll() +} +keys.categories.pasteJSONItemType = 'itemediting' +keys.shortcuts.pasteJSONItemType = function(win) { + win.ZutiloChrome.zoteroOverlay.pasteJSONItemType() +} + +/********************************************/ +// Zutilo's Zotero collection menu functions +/********************************************/ +keys.categories.copyZoteroCollectionSelectLink = 'copying' +keys.shortcuts.copyZoteroCollectionSelectLink = function(win) { + win.ZutiloChrome.zoteroOverlay.copyZoteroCollectionSelectLink() +} +keys.categories.copyZoteroCollectionURI = 'copying' +keys.shortcuts.copyZoteroCollectionURI = function(win) { + win.ZutiloChrome.zoteroOverlay.copyZoteroCollectionURI() +} /***********************************************/ // Zutilo's Zotero item pane editing functions @@ -193,7 +252,7 @@ keys.shortcuts.attachLinkFile = function(win) { keys.categories.recognizeSelected = 'other' keys.shortcuts.recognizeSelected = function(win) { // jscs: disable requireCamelCaseOrUpperCaseIdentifiers - win.Zotero_RecognizePDF.recognizeSelected() + win.ZoteroPane_Local.recognizeSelected() // jscs: enable requireCamelCaseOrUpperCaseIdentifiers }; keys.categories.createParentItemsFromSelected = 'itemcreation' @@ -209,6 +268,15 @@ keys.shortcuts.renameSelectedAttachmentsFromParents = function(win) { // jscs: enable requireCamelCaseOrUpperCaseIdentifiers }; +keys.categories.findPDF = 'attachments' +keys.shortcuts.findPDF = function(win) +{ + // jscs: disable requireCamelCaseOrUpperCaseIdentifiers + let items = win.ZoteroPane_Local.getSelectedItems(); + win.Zotero.Attachments.addAvailablePDFs(items); + // jscs: enable requireCamelCaseOrUpperCaseIdentifiers +}; + keys.categories.attachURI = 'attachments' keys.shortcuts.attachURI = function(win) { // jscs: disable requireCamelCaseOrUpperCaseIdentifiers @@ -231,7 +299,7 @@ keys.shortcuts.showFile = function(win) { var _getBestFile = win.Zotero.Promise.coroutine(function* (item) { if(item.isAttachment()) { - if(item.attachmentLinkMode === Zotero.Attachments.LINK_MODE_LINKED_URL) return false; + if(item.attachmentLinkMode === win.Zotero.Attachments.LINK_MODE_LINKED_URL) return false; return item; } else { return yield item.getBestAttachment(); @@ -252,28 +320,34 @@ keys.shortcuts.showFile = function(win) { // Zotero functions (i.e. not Zutilo functions) // Focus selection /***********************************************/ +keys.categories.advancedSearch = 'uinavigation' +keys.shortcuts.advancedSearch = function(win) { + win.ZoteroPane_Local.openAdvancedSearchWindow() +}; + keys.categories.duplicateItem = 'itemcreation' keys.shortcuts.duplicateItem = function(win) { win.ZoteroPane.duplicateSelectedItem(); }; +keys.categories.openRunJSWindow = 'uinavigation' +keys.shortcuts.openRunJSWindow = function(win) { + win.openRunJSWindow(); +} + keys.categories.openStyleEditor = 'uinavigation' -keys.shortcuts.openStyleEditor = function(_win) { - var prefs_context = {} - Services.scriptloader. - loadSubScript('chrome://zotero/content/include.js', prefs_context) - Services.scriptloader. - loadSubScript('chrome://zotero/content/preferences/preferences.js', - prefs_context) - prefs_context.Zotero_Preferences. - openInViewer('chrome://zotero/content/tools/csledit.xul', true) +keys.shortcuts.openStyleEditor = function(win) { + win.openStyleEditor(); } keys.categories.generateReport = 'other' keys.shortcuts.generateReport = function(win) { let context = win.ZoteroPane.document.defaultView - if (context.document.activeElement.id == "zotero-collections-tree") { - context.Zotero_Report_Interface.loadCollectionReport() + // Zotero >=6 + if (context.document.activeElement.id == win.ZoteroPane.collectionsView.id + // Zotero <=5 + || context.document.activeElement.id == "zotero-collections-tree") { + context.Zotero_Report_Interface.loadCollectionReport() } else { // "zotero-items-tree" whether it is the active element or not let zitems = win.ZoteroPane.getSelectedItems() @@ -287,11 +361,33 @@ keys.categories.focusZoteroCollectionsTree = 'uinavigation' keys.shortcuts.focusZoteroCollectionsTree = function(win) { win.ZutiloChrome.zoteroOverlay. updatePaneVisibility('zotero-collections', 'show'); - win.document.getElementById('zotero-collections-tree').focus(); + // Zotero >=6 + if (win.ZoteroPane.collectionsView.focus) { + win.ZoteroPane.collectionsView.focus(); + } + // Zotero 5.0.97-beta.39 + else if (win.document.getElementById('collection-tree')) { + win.document.getElementById('collection-tree').focus(); + } + // Zotero <=5 + else { + win.document.getElementById('zotero-collections-tree').focus(); + } }; keys.categories.focusZoteroItemsTree = 'uinavigation' keys.shortcuts.focusZoteroItemsTree = function(win) { - win.document.getElementById('zotero-items-tree').focus(); + // Zotero >=6 + if (win.ZoteroPane.itemsView.focus) { + win.ZoteroPane.itemsView.focus(); + } + // Zotero 5.0.97-beta.39 + else if (win.ZoteroPane.itemsView.tree && win.ZoteroPane.itemsView.tree.focus) { + win.ZoteroPane.itemsView.tree.focus(); + } + // Zotero <=5 + else { + win.document.getElementById('zotero-items-tree').focus(); + } }; keys.categories.advanceTabboxTab = 'uinavigation' keys.shortcuts.advanceTabboxTab = function(win) { @@ -326,6 +422,37 @@ keys.shortcuts.selectTabboxTab3 = function(win) { win.document.getElementById('zotero-view-tabbox').tabs.selectedIndex = 3; }; +keys.categories.locateMenu = 'uinavigation' +keys.shortcuts.locateMenu = function(win) { + win.document.getElementById('zotero-tb-locate-menu').showPopup(); +}; + +keys.categories.locateItem = 'uinavigation' +keys.shortcuts.locateItem = function(win) { + let label = Zutilo.Prefs.get("locateItemEngine") + win.Zotero_LocateMenu.locateItem({"target": {"label": label}}) +}; + +keys.categories.toggleAutomaticTags = 'uinavigation' +keys.shortcuts.toggleAutomaticTags = function(win) { + win.ZoteroPane.tagSelector.toggleShowAutomatic() +}; + +keys.categories.toggleAllTags = 'uinavigation' +keys.shortcuts.toggleAllTags = function(win) { + win.ZoteroPane.tagSelector.toggleDisplayAllTags() +}; + +keys.categories.deselectTags = 'uinavigation' +keys.shortcuts.deselectTags = function(win) { + win.ZoteroPane.tagSelector.deselectAll() +}; + +keys.categories.focusTagSelector = 'uinavigation' +keys.shortcuts.focusTagSelector = function(win) { + win.ZoteroPane.tagSelector.searchBoxRef.current.focus() +}; + /***********************************************/ // Zotero functions (i.e. not Zutilo functions) // Hide/show left/right pane @@ -353,67 +480,6 @@ keys.shortcuts.toggleZoteroItemPaneStickySplitter = function(win) { 'toggle', true) }; -/********************************************/ -// Firefox only shortcuts -/********************************************/ -if (Zutilo.appName == 'Firefox') { - - /********************************************/ - // Zutilo's Firefox scraping functions - /********************************************/ - keys.categories.attachPage = 'attachments' - keys.shortcuts.attachPage = function(win) { - win.ZutiloChrome.firefoxOverlay.attachURLToCurrentItem( - win.content.location.href) - }; - - keys.categories.saveItemZutilo = 'itemcreation' - keys.shortcuts.saveItemZutilo = function(win) { - win.ZutiloChrome.firefoxOverlay.scrapeThisPage('opposite') - }; - - keys.categories.saveItemWithAttachments = 'itemcreation' - keys.shortcuts.saveItemWithAttachments = function(win) { - win.ZutiloChrome.firefoxOverlay.scrapeThisPage('with') - }; - - keys.categories.saveItemWithoutAttachments = 'itemcreation' - keys.shortcuts.saveItemWithoutAttachments = function(win) { - win.ZutiloChrome.firefoxOverlay.scrapeThisPage('without') - }; - - /***********************************************/ - // Zotero functions (i.e. not Zutilo functions) - /***********************************************/ - keys.categories.toggleZotero = 'uinavigation' - keys.shortcuts.toggleZotero = function(win) { - win.ZoteroOverlay.toggleDisplay() - }; - - keys.categories.focusZotero = 'uinavigation' - keys.shortcuts.focusZotero = function(win) { - win.ZoteroOverlay.toggleDisplay(true) - }; - - keys.categories.hideZotero = 'uinavigation' - keys.shortcuts.hideZotero = function(win) { - win.ZoteroOverlay.toggleDisplay(false) - }; - - keys.categories.saveItemZotero = 'itemcreation' - keys.shortcuts.saveItemZotero = function(win) { - // jscs: disable requireCamelCaseOrUpperCaseIdentifiers - win.Zotero_Browser.scrapeThisPage() - // jscs: enable requireCamelCaseOrUpperCaseIdentifiers - }; - - keys.categories.websiteItem = 'itemcreation' - keys.shortcuts.websiteItem = function(win) { - win.ZoteroPane.addItemFromPage() - }; - -} - AddonManager.getAddonByID('better-bibtex@iris-advies.com', function(aAddon) { if (aAddon === null || !aAddon.isActive) { return @@ -436,6 +502,12 @@ AddonManager.getAddonByID('better-bibtex@iris-advies.com', function(aAddon) { win.Zotero.BetterBibTeX.ready.then(function() { win.Zotero.BetterBibTeX.KeyManager.refresh('selected', true)}) } + + keys.categories.BBTtoTeXstudio = 'bbt' + keys.shortcuts.BBTtoTeXstudio = function(win) { + win.Zotero.BetterBibTeX.ready.then(function() { + win.Zotero.BetterBibTeX.ZoteroPane.toTeXstudio()}) + } // Call setDefaults again so it generates defaults for these shortcuts // created in the getAddonByID callback. // TODO: Only add defaults for the shortcuts generated here. @@ -452,5 +524,42 @@ AddonManager.getAddonByID('zotfile@columbia.edu', function(aAddon) { win.Zotero.ZotFile.attachFileFromSourceDirectory() } + keys.categories.ZotFileRename = 'ZotFile' + keys.shortcuts.ZotFileRename = function(win) { + win.Zotero.ZotFile.renameSelectedAttachments() + } + + keys.categories.ZotFileExtractAnnotations = 'ZotFile' + keys.shortcuts.ZotFileExtractAnnotations = function(win) { + win.Zotero.ZotFile.pdfAnnotations.getAnnotations() + } + + Zutilo.Prefs.setDefaults() +}) + +AddonManager.getAddonByID('mdnotes@mdnotes.github.io', function (aAddon) { + if (aAddon === null || !aAddon.isActive) { + return + } + + keys.categories.MdnotesBatchExport = 'mdnotes' + keys.shortcuts.MdnotesBatchExport = function(win) { + win.Zotero.Mdnotes.batchExportMenu() + } + + keys.categories.MdnotesExport = 'mdnotes' + keys.shortcuts.MdnotesExport = function(win) { + win.Zotero.Mdnotes.exportToMarkdownMenu() + } + + keys.categories.MdnotesCreateStandaloneNote = 'mdnotes' + keys.shortcuts.MdnotesCreateStandaloneNote = function(win) { + win.Zotero.Mdnotes.createNoteFileMenu(true) + } + + keys.categories.MdnotesCreateMdNote = 'mdnotes' + keys.shortcuts.MdnotesCreateMdNote = function(win) { + win.Zotero.Mdnotes.createNoteFileMenu(false) + } Zutilo.Prefs.setDefaults() }) diff --git a/addon/chrome/content/zutilo/preferences.js b/addon/chrome/content/zutilo/preferences.js index df56750..e9bb8e1 100644 --- a/addon/chrome/content/zutilo/preferences.js +++ b/addon/chrome/content/zutilo/preferences.js @@ -6,67 +6,48 @@ 'use strict'; /* global window, document, Components */ /* global keyconfigOnLoad, Zutilo */ -Components.utils.import('chrome://zutilo/content/zutilo.jsm'); +Components.utils.import('chrome://zutilo/content/zutilo.js'); // eslint-disable-next-line no-unused-vars function initializePrefWindow() { - if (Zutilo.appName == 'Firefox') { - // Hide Zotero Standalone specific preference window elements - document.getElementById('general-standalone-label'). - setAttribute('hidden', true); - } else { - // Hide Firefox specific preference window elements - document.getElementById('general-checkbox-zoteroNotActive'). - setAttribute('hidden', true); - document.getElementById('zutilo-prefpane-ui-browser-menus'). - setAttribute('hidden', true); - } - - keyconfigOnLoad(); + // keyconfigOnLoad(); } // eslint-disable-next-line no-unused-vars function buildMenuPrefs() { for (const menuName of ['item', 'collection']) { for (const functionName of Zutilo._menuFunctions[menuName]) { - addMenuPreference(menuName, functionName); addMenuRadiogroup(menuName, functionName); } } } -function addMenuPreference(menuName, menuFunction) { - var newPref = document.createElement('preference'); - newPref.setAttribute('id', `pref-${menuName}menu-${menuFunction}`); - newPref.setAttribute('name', `extensions.zutilo.${menuName}menu.${menuFunction}`); - newPref.setAttribute('type', 'string'); - - var zutiloPrefs = document.getElementById('zutilo-prefpane-ui-preferences'); - zutiloPrefs.appendChild(newPref); -} - function addMenuRadiogroup(menuName, menuFunction) { - var newRow = document.createElement('row'); + var newRow = document.createXULElement('groupbox'); - var newHbox = document.createElement('hbox'); + var newHbox = document.createXULElement('hbox'); newHbox.setAttribute('align', 'center'); - var newLabel = document.createElement('label'); - newLabel.setAttribute('value', Zutilo._bundle.GetStringFromName( - `zutilo.preferences.${menuName}menu.${menuFunction}`)); + var newLabel = document.createXULElement('label'); + newLabel.setAttribute( + 'value', + Zutilo.getString(`zutilo.preferences.${menuName}menu.${menuFunction}`) + ) newHbox.appendChild(newLabel); newRow.appendChild(newHbox); - var newRadiogroup = document.createElement('radiogroup'); + var newRadiogroup = document.createXULElement('radiogroup'); newRadiogroup.setAttribute('orient', 'horizontal'); newRadiogroup.setAttribute('align', 'center'); newRadiogroup.setAttribute('preference', - `pref-${menuName}menu-${menuFunction}`); + `extensions.zutilo.${menuName}menu.${menuFunction}`); var newRadio; for (const label of ['Zotero', 'Zutilo', 'Hide']) { - newRadio = document.createElement('radio'); - newRadio.setAttribute('label', Zutilo._bundle.GetStringFromName( - `zutilo.preferences.${menuName}menu.${label}`)); + newRadio = document.createXULElement('radio'); + newRadio.setAttribute( + 'label', + Zutilo.getString(`zutilo.preferences.${menuName}menu.${label}`) + ) newRadio.setAttribute('value', label); newRadiogroup.appendChild(newRadio); } diff --git a/addon/chrome/content/zutilo/preferences.xhtml b/addon/chrome/content/zutilo/preferences.xhtml new file mode 100644 index 0000000..6f3dc78 --- /dev/null +++ b/addon/chrome/content/zutilo/preferences.xhtml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +