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:
parent
5d442b706e
commit
578986ab1e
2 changed files with 45 additions and 50 deletions
|
@ -851,7 +851,6 @@ Zotero.Schema = new function(){
|
||||||
var enumerator = Services.wm.getEnumerator("navigator:browser");
|
var enumerator = Services.wm.getEnumerator("navigator:browser");
|
||||||
while (enumerator.hasMoreElements()) {
|
while (enumerator.hasMoreElements()) {
|
||||||
let win = enumerator.getNext();
|
let win = enumerator.getNext();
|
||||||
win.ZoteroPane.buildItemTypeSubMenu();
|
|
||||||
win.document.getElementById('zotero-editpane-item-box').buildItemTypeMenu();
|
win.document.getElementById('zotero-editpane-item-box').buildItemTypeMenu();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -271,43 +271,14 @@ var ZoteroPane = new function()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/*
|
var _lastPrimaryTypes;
|
||||||
* 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
this.updateNewItemTypes = function () {
|
this.updateNewItemTypes = function () {
|
||||||
|
var primaryTypes = Zotero.ItemTypes.getPrimaryTypes();
|
||||||
|
var primaryTypesJoined = primaryTypes.join(',');
|
||||||
|
if (_lastPrimaryTypes == primaryTypesJoined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var addMenu = document.getElementById('zotero-tb-add').firstChild;
|
var addMenu = document.getElementById('zotero-tb-add').firstChild;
|
||||||
|
|
||||||
// Remove all nodes so we can regenerate
|
// Remove all nodes so we can regenerate
|
||||||
|
@ -316,37 +287,65 @@ var ZoteroPane = new function()
|
||||||
var p = options[0].parentNode;
|
var p = options[0].parentNode;
|
||||||
p.removeChild(options[0]);
|
p.removeChild(options[0]);
|
||||||
}
|
}
|
||||||
|
var moreMenu = document.getElementById('zotero-tb-add-more');
|
||||||
|
while (moreMenu.hasChildNodes()) {
|
||||||
|
moreMenu.removeChild(moreMenu.firstChild);
|
||||||
|
}
|
||||||
|
|
||||||
var separator = addMenu.firstChild;
|
var separator = addMenu.firstChild;
|
||||||
|
|
||||||
// Sort by localized name
|
// Populate primary types from MRU
|
||||||
var t = Zotero.ItemTypes.getPrimaryTypes();
|
|
||||||
var itemTypes = [];
|
var itemTypes = [];
|
||||||
for (var i=0; i<t.length; i++) {
|
for (let type of primaryTypes) {
|
||||||
itemTypes.push({
|
itemTypes.push({
|
||||||
id: t[i].id,
|
id: type.id,
|
||||||
name: t[i].name,
|
name: type.name,
|
||||||
localized: Zotero.ItemTypes.getLocalizedString(t[i].id)
|
localized: Zotero.ItemTypes.getLocalizedString(type.id)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var collation = Zotero.getLocaleCollation();
|
var collation = Zotero.getLocaleCollation();
|
||||||
itemTypes.sort(function(a, b) {
|
itemTypes.sort(function(a, b) {
|
||||||
return collation.compareString(1, a.localized, b.localized);
|
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++) {
|
for (var i = 0; i<itemTypes.length; i++) {
|
||||||
var menuitem = document.createElement("menuitem");
|
var menuitem = document.createElement("menuitem");
|
||||||
menuitem.setAttribute("label", itemTypes[i].localized);
|
menuitem.setAttribute("label", itemTypes[i].localized);
|
||||||
menuitem.setAttribute("tooltiptext", "");
|
menuitem.setAttribute("tooltiptext", "");
|
||||||
let type = itemTypes[i].id;
|
let type = itemTypes[i].id;
|
||||||
menuitem.addEventListener("command", function() { ZoteroPane_Local.newItem(type, {}, null, true).done(); }, false);
|
menuitem.addEventListener("command", function () {
|
||||||
menuitem.className = "zotero-tb-add";
|
ZoteroPane.newItem(type, {}, null, true);
|
||||||
addMenu.insertBefore(menuitem, separator);
|
});
|
||||||
|
moreMenu.appendChild(menuitem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Called when the window closes
|
* Called when the window closes
|
||||||
*/
|
*/
|
||||||
|
@ -403,9 +402,6 @@ var ZoteroPane = new function()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!_madeVisible) {
|
|
||||||
this.buildItemTypeSubMenu();
|
|
||||||
}
|
|
||||||
_madeVisible = true;
|
_madeVisible = true;
|
||||||
|
|
||||||
this.unserializePersist();
|
this.unserializePersist();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue