Don't initialize tag selector if closed at startup (React regression)

Even after cdf9d7ff32, the tag selector was still being initialized if
it was closed at startup, which meant that keeping it closed didn't fix
performance problems in large libraries. This hopefully finally brings
the tag selector in line with pre-Reactification behavior.

This also moves initIntlStrings() logic to Zotero.Intl so that strings
are accessible from React components in separate windows, and it moves
container initialization to ZoteroPane since most of what it does will
need to interact with ZoteroPane anyway.
This commit is contained in:
Dan Stillman 2019-03-17 05:05:04 -04:00
parent c44b864923
commit 3463e3b5ab
7 changed files with 51 additions and 83 deletions

View file

@ -1,56 +0,0 @@
/*
***** BEGIN LICENSE BLOCK *****
Copyright © 2018 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 *****
*/
'use strict';
const { defineMessages } = require('react-intl');
ZoteroPane.Containers = {
async init() {
await this.initIntlStrings();
},
loadPane() {
ZoteroPane.initTagSelector();
},
async initIntlStrings() {
this.intlMessages = {};
const intlFiles = ['zotero.dtd'];
for (let intlFile of intlFiles) {
let localeXML = await Zotero.File.getContentsFromURLAsync(`chrome://zotero/locale/${intlFile}`);
let regexp = /<!ENTITY ([^\s]+)\s+"([^"]+)/g;
let regexpResult;
while (regexpResult = regexp.exec(localeXML)) {
this.intlMessages[regexpResult[1]] = regexpResult[2];
}
}
},
destroy() {
ZoteroPane.tagSelector.uninit();
}
}

View file

@ -29,6 +29,5 @@
<overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script src="chrome://zotero/content/include.js"></script>
<script src="containers.js"></script>
<script src="tagSelector.js"></script>
</overlay>

View file

@ -457,7 +457,7 @@ Zotero.TagSelector = class TagSelectorContainer extends React.Component {
static init(domEl, opts) {
var ref;
let elem = (
<IntlProvider locale={Zotero.locale} messages={ZoteroPane.Containers.intlMessages}>
<IntlProvider locale={Zotero.locale} messages={Zotero.Intl.strings}>
<TagSelectorContainer ref={c => ref = c } {...opts} />
</IntlProvider>
);

View file

@ -84,7 +84,6 @@ var ZoteroOverlay = new function()
throw new Error("Skipping loading");
}
ZoteroPane.Containers.init();
ZoteroPane.init();
// Clear old Zotero icon pref

View file

@ -64,7 +64,6 @@ const ZoteroStandalone = new function() {
ZoteroStandalone.DebugOutput.init();
Zotero.hideZoteroPaneOverlays();
await ZoteroPane.Containers.init();
ZoteroPane.init();
ZoteroPane.makeVisible();

View file

@ -49,6 +49,17 @@ Zotero.Intl = new function () {
// Set the locale direction to Zotero.dir
Zotero.dir = Zotero.Locale.defaultScriptDirection(Zotero.locale);
Zotero.rtl = (Zotero.dir === 'rtl');
this.strings = {};
const intlFiles = ['zotero.dtd'];
for (let intlFile of intlFiles) {
let localeXML = Zotero.File.getContentsFromURL(`chrome://zotero/locale/${intlFile}`);
let regexp = /<!ENTITY ([^\s]+)\s+"([^"]+)/g;
let regexpResult;
while (regexpResult = regexp.exec(localeXML)) {
this.strings[regexpResult[1]] = regexpResult[2];
}
}
};

View file

@ -143,8 +143,6 @@ var ZoteroPane = new function()
Zotero.hiDPI = window.devicePixelRatio > 1;
Zotero.hiDPISuffix = Zotero.hiDPI ? "@2x" : "";
ZoteroPane_Local.Containers.loadPane();
ZoteroPane_Local.setItemsPaneMessage(Zotero.getString('pane.items.loading'));
// Add a default progress window
@ -257,6 +255,16 @@ var ZoteroPane = new function()
}
this.initContainers = function () {
this.initTagSelector();
};
this.uninitContainers = function () {
this.tagSelector.uninit();
};
/*
* Create the New Item (+) submenu with each item type
*/
@ -346,7 +354,7 @@ var ZoteroPane = new function()
this.serializePersist();
}
ZoteroPane_Local.Containers.destroy();
ZoteroPane_Local.Containers.uninit();
if(this.collectionsView) this.collectionsView.unregister();
if(this.itemsView) this.itemsView.unregister();
@ -389,6 +397,7 @@ var ZoteroPane = new function()
this.unserializePersist();
this.updateLayout();
this.updateToolbarPosition();
this.initContainers();
// restore saved row selection (for tab switching)
// TODO: Remove now that no tab mode?
@ -1089,18 +1098,30 @@ var ZoteroPane = new function()
this.initTagSelector = function () {
this.tagSelector = Zotero.TagSelector.init(
document.getElementById('zotero-tag-selector'),
{
onSelection: this.updateTagFilter.bind(this)
}
);
var container = document.getElementById('zotero-tag-selector-container');
if (!container.hasAttribute('collapsed') || container.getAttribute('collapsed') == 'false') {
this.tagSelector = Zotero.TagSelector.init(
document.getElementById('zotero-tag-selector'),
{
onSelection: this.updateTagFilter.bind(this)
}
);
}
};
/*
* Sets the tag filter on the items view
*/
this.updateTagFilter = Zotero.Promise.coroutine(function* () {
if (this.itemsView) {
yield this.itemsView.setFilter('tags', ZoteroPane_Local.tagSelector.getTagSelection());
}
});
this.toggleTagSelector = Zotero.Promise.coroutine(function* () {
var container = document.getElementById('zotero-tag-selector-container');
var showing = container.getAttribute('collapsed') == 'true';
container.setAttribute('collapsed', !showing);
@ -1117,21 +1138,12 @@ var ZoteroPane = new function()
}
});
/*
* Sets the tag filter on the items view
*/
this.updateTagFilter = Zotero.Promise.coroutine(function* () {
if (this.itemsView) {
yield this.itemsView.setFilter('tags', ZoteroPane_Local.tagSelector.getTagSelection());
}
});
this.tagSelectorShown = function () {
var collectionTreeRow = this.getCollectionTreeRow();
if (!collectionTreeRow) return;
var tagSelector = document.getElementById('zotero-tag-selector');
return !tagSelector.getAttribute('collapsed')
var tagSelector = document.getElementById('zotero-tag-selector-container');
return !tagSelector.hasAttribute('collapsed')
|| tagSelector.getAttribute('collapsed') == 'false';
};
@ -1195,7 +1207,9 @@ var ZoteroPane = new function()
// Clear quick search and tag selector when switching views
document.getElementById('zotero-tb-search').value = "";
ZoteroPane.tagSelector.clearTagSelection();
if (ZoteroPane.tagSelector) {
ZoteroPane.tagSelector.clearTagSelection();
}
// Not necessary with seltype="cell", which calls nsITreeView::isSelectable()
/*if (collectionTreeRow.isSeparator()) {
@ -1204,7 +1218,9 @@ var ZoteroPane = new function()
}*/
collectionTreeRow.setSearch('');
collectionTreeRow.setTags(ZoteroPane_Local.tagSelector.getTagSelection());
if (ZoteroPane.tagSelector) {
collectionTreeRow.setTags(ZoteroPane.tagSelector.getTagSelection());
}
this._updateToolbarIconsForRow(collectionTreeRow);