/* ***** 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 . ***** END LICENSE BLOCK ***** */ /* * This object contains the various functions for the interface */ var ZoteroPane = new function() { var _unserialized = false; this.collectionsView = false; this.itemsView = false; this.progressWindow = false; this._listeners = {}; this.__defineGetter__('loaded', function () { return _loaded; }); var _lastSelectedItems = []; //Privileged methods this.destroy = destroy; this.isShowing = isShowing; this.isFullScreen = isFullScreen; this.handleKeyDown = handleKeyDown; this.handleKeyUp = handleKeyUp; this.setHighlightedRowsCallback = setHighlightedRowsCallback; this.handleKeyPress = handleKeyPress; this.getSelectedCollection = getSelectedCollection; this.getSelectedSavedSearch = getSelectedSavedSearch; this.getSelectedItems = getSelectedItems; this.getSortedItems = getSortedItems; this.getSortField = getSortField; this.getSortDirection = getSortDirection; this.setItemsPaneMessage = setItemsPaneMessage; this.clearItemsPaneMessage = clearItemsPaneMessage; this.contextPopupShowing = contextPopupShowing; this.viewSelectedAttachment = viewSelectedAttachment; this.reportErrors = reportErrors; this.displayErrorMessage = displayErrorMessage; this.document = document; const COLLECTIONS_HEIGHT = 32; // minimum height of the collections pane and toolbar var self = this, _loaded = false, _madeVisible = false, titlebarcolorState, titleState, observerService, _reloadFunctions = [], _beforeReloadFunctions = []; /** * Called when the window containing Zotero pane is open */ this.init = function () { Zotero.debug("Initializing Zotero pane"); // For now, keep actions menu in the DOM and show it in Firefox for development if (!Zotero.isStandalone) { document.getElementById('zotero-tb-actions-menu-separator').hidden = false; document.getElementById('zotero-tb-actions-menu').hidden = false; } // Set "Report Errors..." label via property rather than DTD entity, // since we need to reference it in script elsewhere document.getElementById('zotero-tb-actions-reportErrors').setAttribute('label', Zotero.getString('errorReport.reportErrors')); // Set key down handler document.getElementById('appcontent').addEventListener('keydown', ZoteroPane_Local.handleKeyDown, true); // Hide or show the PDF recognizer button Zotero.RecognizePDF.addListener('empty', function (row) { document.getElementById('zotero-tb-recognize').hidden = true; }); Zotero.RecognizePDF.addListener('nonempty', function (row) { document.getElementById('zotero-tb-recognize').hidden = false; }); _loaded = true; var zp = document.getElementById('zotero-pane'); Zotero.setFontSize(zp); ZoteroPane_Local.updateLayout(); ZoteroPane_Local.updateToolbarPosition(); this.updateWindow(); window.addEventListener("resize", () => { this.updateWindow(); this.updateToolbarPosition(); }); window.setTimeout(ZoteroPane_Local.updateToolbarPosition, 0); Zotero.updateQuickSearchBox(document); if (Zotero.isMac) { //document.getElementById('zotero-tb-actions-zeroconf-update').setAttribute('hidden', false); document.getElementById('zotero-pane-stack').setAttribute('platform', 'mac'); } else if(Zotero.isWin) { document.getElementById('zotero-pane-stack').setAttribute('platform', 'win'); } // Set the sync tooltip label Components.utils.import("resource://zotero/config.js"); document.getElementById('zotero-tb-sync-label').value = Zotero.getString( 'sync.syncWith', ZOTERO_CONFIG.DOMAIN_NAME ); if (Zotero.isStandalone) { document.getElementById('zotero-tb-feed-add-fromPage').hidden = true; document.getElementById('zotero-tb-feed-add-fromPage-menu').hidden = true; } // register an observer for Zotero reload observerService = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService); observerService.addObserver(_reloadObserver, "zotero-reloaded", false); observerService.addObserver(_reloadObserver, "zotero-before-reload", false); this.addBeforeReloadListener(function(newMode) { if(newMode == "connector") { ZoteroPane_Local.setItemsPaneMessage(Zotero.getString('connector.standaloneOpen')); } return; }); this.addReloadListener(_loadPane); // continue loading pane _loadPane(); }; /** * Called on window load or when pane has been reloaded after switching into or out of connector * mode */ function _loadPane() { if(!Zotero || !Zotero.initialized || Zotero.isConnector) return; // Set flags for hi-res displays Zotero.hiDPI = window.devicePixelRatio > 1; Zotero.hiDPISuffix = Zotero.hiDPI ? "@2x" : ""; ZoteroPane_Local.setItemsPaneMessage(Zotero.getString('pane.items.loading')); // Add a default progress window ZoteroPane_Local.progressWindow = new Zotero.ProgressWindow({ window }); //Initialize collections view ZoteroPane_Local.collectionsView = new Zotero.CollectionTreeView(); // Handle an error in setTree()/refresh() ZoteroPane_Local.collectionsView.onError = function (e) { ZoteroPane_Local.displayErrorMessage(); }; var collectionsTree = document.getElementById('zotero-collections-tree'); collectionsTree.view = ZoteroPane_Local.collectionsView; collectionsTree.controllers.appendController(new Zotero.CollectionTreeCommandController(collectionsTree)); collectionsTree.addEventListener("mousedown", ZoteroPane_Local.onTreeMouseDown, true); collectionsTree.addEventListener("click", ZoteroPane_Local.onTreeClick, true); // Clear items view, so that the load registers as a new selected collection when switching // between modes ZoteroPane_Local.itemsView = null; var itemsTree = document.getElementById('zotero-items-tree'); itemsTree.controllers.appendController(new Zotero.ItemTreeCommandController(itemsTree)); itemsTree.addEventListener("mousedown", ZoteroPane_Local.onTreeMouseDown, true); itemsTree.addEventListener("click", ZoteroPane_Local.onTreeClick, true); var menu = document.getElementById("contentAreaContextMenu"); menu.addEventListener("popupshowing", ZoteroPane_Local.contextPopupShowing, false); var tagSelector = document.getElementById('zotero-tag-selector'); tagSelector.onchange = function () { return ZoteroPane_Local.updateTagFilter(); }; Zotero.Keys.windowInit(document); if (Zotero.restoreFromServer) { Zotero.restoreFromServer = false; setTimeout(function () { 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 Restore", "The local Zotero database has been cleared." + " " + "Would you like to restore from the Zotero server now?", buttonFlags, "Sync Now", null, null, null, {} ); if (index == 0) { Zotero.Sync.Server.sync({ onSuccess: function () { Zotero.Sync.Runner.updateIcons(); ps.alert( null, "Restore Completed", "The local Zotero database has been successfully restored." ); }, onError: function (msg) { ps.alert( null, "Restore Failed", "An error occurred while restoring from the server:\n\n" + msg ); Zotero.Sync.Runner.error(msg); } }); } }, 1000); } // If the database was initialized or there are no sync credentials and // Zotero hasn't been run before in this profile, display the start page // -- this way the page won't be displayed when they sync their DB to // another profile or if the DB is initialized erroneously (e.g. while // switching data directory locations) else if (Zotero.Prefs.get('firstRun2')) { if (Zotero.Schema.dbInitialized || !Zotero.Sync.Server.enabled) { setTimeout(function () { ZoteroPane_Local.loadURI(ZOTERO_CONFIG.START_URL); }, 400); } Zotero.Prefs.set('firstRun2', false); try { Zotero.Prefs.clear('firstRun'); } catch (e) {} } if (Zotero.openPane) { Zotero.openPane = false; setTimeout(function () { ZoteroPane_Local.show(); }, 0); } // TEMP: Clean up extra files from Mendeley imports <5.0.51 setTimeout(async function () { var needsCleanup = await Zotero.DB.valueQueryAsync( "SELECT COUNT(*) FROM settings WHERE setting='mImport' AND key='cleanup'" ) if (!needsCleanup) return; Components.utils.import("chrome://zotero/content/import/mendeley/mendeleyImport.js"); var importer = new Zotero_Import_Mendeley(); importer.deleteNonPrimaryFiles(); }, 10000) } /* * Create the New Item (+) submenu with each item type */ this.buildItemTypeSubMenu = function () { var moreMenu = document.getElementById('zotero-tb-add-more'); while (moreMenu.hasChildNodes()) { moreMenu.removeChild(moreMenu.firstChild); } // Sort by localized name var t = Zotero.ItemTypes.getSecondaryTypes(); var itemTypes = []; for (var i=0; i