www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit 7fd3a8c5d11db69f74434eade403e8aaaa1c6d78
parent 8a9986da475f4f50c21cd5cc2e56530fd51a6c95
Author: Dan Stillman <dstillman@zotero.org>
Date:   Thu, 29 Dec 2016 07:01:52 -0500

Fix New Item MRU list, which apparently has only ever updated on startup

Diffstat:
Mchrome/content/zotero/standalone/standalone.js | 4+++-
Mchrome/content/zotero/xpcom/data/cachedTypes.js | 54+++++++++++++++++++++++-------------------------------
Mchrome/content/zotero/zoteroPane.xul | 1-
3 files changed, 26 insertions(+), 33 deletions(-)

diff --git a/chrome/content/zotero/standalone/standalone.js b/chrome/content/zotero/standalone/standalone.js @@ -107,7 +107,9 @@ const ZoteroStandalone = new function() { menuitem.setAttribute("label", itemTypes[i].localized); menuitem.setAttribute("tooltiptext", ""); let type = itemTypes[i].id; - menuitem.addEventListener("command", function() { ZoteroPane_Local.newItem(type); }, false); + menuitem.addEventListener("command", function() { + ZoteroPane_Local.newItem(type, null, null, true); + }, false); menuitem.className = "zotero-tb-add"; addMenu.appendChild(menuitem); } diff --git a/chrome/content/zotero/xpcom/data/cachedTypes.js b/chrome/content/zotero/xpcom/data/cachedTypes.js @@ -345,6 +345,8 @@ Zotero.ItemTypes = new function() { var _secondaryTypes; var _hiddenTypes; + var _numPrimary = 5; + var _customImages = {}; var _customLabels = {}; @@ -352,39 +354,9 @@ Zotero.ItemTypes = new function() { this.init = Zotero.Promise.coroutine(function* () { yield this.constructor.prototype.init.apply(this); - // Primary types - var limit = 5; - // TODO: get rid of ' AND itemTypeID!=5' and just remove display=2 // from magazineArticle in system.sql - var sql = 'WHERE (display=2 AND itemTypeID!=5) '; - - var mru = Zotero.Prefs.get('newItemTypeMRU'); - if (mru) { - var params = []; - mru = mru.split(',').slice(0, limit); - for (var i=0, len=mru.length; i<len; i++) { - var id = parseInt(mru[i]); - if (!isNaN(id) && id != 13) { // ignore 'webpage' item type - params.push(id); - } - } - if (params.length) { - sql += 'OR id IN ' - + '(' + params.map(() => '?').join() + ') ' - + 'ORDER BY id NOT IN ' - + '(' + params.map(() => '?').join() + ') '; - params = params.concat(params); - } - else { - params = false; - } - } - else { - params = false; - } - sql += 'LIMIT ' + limit; - _primaryTypes = yield this._getTypesFromDB(sql, params); + _primaryTypes = yield this._getTypesFromDB('WHERE (display=2 AND itemTypeID!=5) LIMIT ' + _numPrimary); // Secondary types _secondaryTypes = yield this._getTypesFromDB('WHERE display IN (1,2)'); @@ -408,6 +380,26 @@ Zotero.ItemTypes = new function() { if (!_primaryTypes) { throw new Zotero.Exception.UnloadedDataException("Primary item type data not yet loaded"); } + + var mru = Zotero.Prefs.get('newItemTypeMRU'); + if (mru && mru.length) { + // Get types from the MRU list + mru = new Set( + mru.split(',') + .slice(0, _numPrimary) + .map(id => parseInt(id)) + // Ignore 'webpage' item type + .filter(id => !isNaN(id) && id != 13) + ); + + // Add types from defaults until we reach our limit + for (let i = 0; i < _primaryTypes.length && mru.size < _numPrimary; i++) { + mru.add(_primaryTypes[i].id); + } + + return Array.from(mru).map(id => ({ id, name: this.getName(id) })); + } + return _primaryTypes; } diff --git a/chrome/content/zotero/zoteroPane.xul b/chrome/content/zotero/zoteroPane.xul @@ -146,7 +146,6 @@ <hbox id="zotero-items-toolbar" align="center"> <toolbarbutton id="zotero-tb-add" class="zotero-tb-button" tooltiptext="&zotero.toolbar.newItem.label;" type="menu"> - <!-- New Item drop-down built in overlay.js::onLoad() --> <menupopup onpopupshowing="ZoteroPane_Local.updateNewItemTypes()"> <menuseparator/> <menuitem label="&zotero.toolbar.attachment.linked;" oncommand="ZoteroPane_Local.addAttachmentFromDialog(true);" tooltiptext=""/>