Fix item types not appearing in New Item submenu

https://forums.zotero.org/discussion/96530/a-issue-about-new-item-drop-down-menu

After a type from the submenu was selected and added to the MRU, the
submenu wouldn't be updated. Not sure how long this has been going on.

Fixes #2534
This commit is contained in:
Dan Stillman 2022-04-19 23:02:55 -04:00
parent 5d442b706e
commit 578986ab1e
2 changed files with 45 additions and 50 deletions

View file

@ -851,7 +851,6 @@ Zotero.Schema = new function(){
var enumerator = Services.wm.getEnumerator("navigator:browser");
while (enumerator.hasMoreElements()) {
let win = enumerator.getNext();
win.ZoteroPane.buildItemTypeSubMenu();
win.document.getElementById('zotero-editpane-item-box').buildItemTypeMenu();
}
});

View file

@ -271,43 +271,14 @@ var ZoteroPane = new function()
};
/*
* 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<t.length; i++) {
itemTypes.push({
id: t[i].id,
name: t[i].name,
localized: Zotero.ItemTypes.getLocalizedString(t[i].id)
});
}
var collation = Zotero.getLocaleCollation();
itemTypes.sort(function(a, b) {
return collation.compareString(1, a.localized, b.localized);
});
for (var i = 0; i<itemTypes.length; i++) {
var menuitem = document.createElement("menuitem");
menuitem.setAttribute("label", itemTypes[i].localized);
menuitem.setAttribute("tooltiptext", "");
let type = itemTypes[i].id;
menuitem.addEventListener("command", function() { ZoteroPane_Local.newItem(type, {}, null, true).done(); }, false);
moreMenu.appendChild(menuitem);
}
}
var _lastPrimaryTypes;
this.updateNewItemTypes = function () {
var primaryTypes = Zotero.ItemTypes.getPrimaryTypes();
var primaryTypesJoined = primaryTypes.join(',');
if (_lastPrimaryTypes == primaryTypesJoined) {
return;
}
var addMenu = document.getElementById('zotero-tb-add').firstChild;
// Remove all nodes so we can regenerate
@ -316,37 +287,65 @@ var ZoteroPane = new function()
var p = options[0].parentNode;
p.removeChild(options[0]);
}
var moreMenu = document.getElementById('zotero-tb-add-more');
while (moreMenu.hasChildNodes()) {
moreMenu.removeChild(moreMenu.firstChild);
}
var separator = addMenu.firstChild;
// Sort by localized name
var t = Zotero.ItemTypes.getPrimaryTypes();
// Populate primary types from MRU
var itemTypes = [];
for (var i=0; i<t.length; i++) {
for (let type of primaryTypes) {
itemTypes.push({
id: t[i].id,
name: t[i].name,
localized: Zotero.ItemTypes.getLocalizedString(t[i].id)
id: type.id,
name: type.name,
localized: Zotero.ItemTypes.getLocalizedString(type.id)
});
}
var collation = Zotero.getLocaleCollation();
itemTypes.sort(function(a, b) {
return collation.compareString(1, a.localized, b.localized);
});
for (let itemType of itemTypes) {
let menuitem = document.createElement("menuitem");
menuitem.setAttribute("label", itemType.localized);
menuitem.setAttribute("tooltiptext", "");
let type = itemType.id;
menuitem.addEventListener("command", function () {
ZoteroPane.newItem(type, {}, null, true);
});
menuitem.className = "zotero-tb-add";
addMenu.insertBefore(menuitem, separator);
}
// Populate submenu with each item type not in the MRU list
itemTypes = [];
for (let type of Zotero.ItemTypes.getSecondaryTypes()) {
itemTypes.push({
id: type.id,
name: type.name,
localized: Zotero.ItemTypes.getLocalizedString(type.id)
});
}
var collation = Zotero.getLocaleCollation();
itemTypes.sort(function(a, b) {
return collation.compareString(1, a.localized, b.localized);
});
for (var i = 0; i<itemTypes.length; i++) {
var menuitem = document.createElement("menuitem");
menuitem.setAttribute("label", itemTypes[i].localized);
menuitem.setAttribute("tooltiptext", "");
let type = itemTypes[i].id;
menuitem.addEventListener("command", function() { ZoteroPane_Local.newItem(type, {}, null, true).done(); }, false);
menuitem.className = "zotero-tb-add";
addMenu.insertBefore(menuitem, separator);
menuitem.addEventListener("command", function () {
ZoteroPane.newItem(type, {}, null, true);
});
moreMenu.appendChild(menuitem);
}
}
/*
* Called when the window closes
*/
@ -403,9 +402,6 @@ var ZoteroPane = new function()
return false;
}
if(!_madeVisible) {
this.buildItemTypeSubMenu();
}
_madeVisible = true;
this.unserializePersist();