From 7fd3a8c5d11db69f74434eade403e8aaaa1c6d78 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 29 Dec 2016 07:01:52 -0500 Subject: [PATCH] Fix New Item MRU list, which apparently has only ever updated on startup --- .../content/zotero/standalone/standalone.js | 4 +- .../content/zotero/xpcom/data/cachedTypes.js | 54 ++++++++----------- chrome/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 index 2033908541..5e45327ec9 100644 --- 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 index e34b6089f6..53f6f3b947 100644 --- 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 '?').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 index f412adb73b..46992e5318 100644 --- a/chrome/content/zotero/zoteroPane.xul +++ b/chrome/content/zotero/zoteroPane.xul @@ -146,7 +146,6 @@ -