Update new item type MRU menu for global schema
And fix a Zotero 5 regression in which the MRU menu wasn't updated when changing the item type after using the new-item keyboard shortcut
This commit is contained in:
parent
c3fd958ed7
commit
5779b60418
3 changed files with 32 additions and 28 deletions
|
@ -1106,6 +1106,11 @@
|
|||
<parameter name="menu"/>
|
||||
<body><![CDATA[
|
||||
return (async function () {
|
||||
var functionsToRun = [];
|
||||
if (this.eventHandlers.itemtypechange && this.eventHandlers.itemtypechange.length) {
|
||||
functionsToRun = [...this.eventHandlers.itemtypechange];
|
||||
}
|
||||
|
||||
if (itemTypeID == this.item.itemTypeID) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1178,9 +1183,7 @@
|
|||
this.refresh();
|
||||
}
|
||||
|
||||
if (this.eventHandlers['itemtypechange'] && this.eventHandlers['itemtypechange'].length) {
|
||||
this.eventHandlers['itemtypechange'].forEach(f => f.bind(this)());
|
||||
}
|
||||
functionsToRun.forEach(f => f.bind(this)());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -351,6 +351,7 @@ Zotero.ItemTypes = new function() {
|
|||
this._table = 'itemTypesCombined';
|
||||
this._hasCustom = true;
|
||||
|
||||
var _primaryTypeNames = ['book', 'bookSection', 'journalArticle', 'newspaperArticle', 'document'];
|
||||
var _primaryTypes;
|
||||
var _secondaryTypes;
|
||||
var _hiddenTypes;
|
||||
|
@ -364,12 +365,14 @@ Zotero.ItemTypes = new function() {
|
|||
this.init = Zotero.Promise.coroutine(function* () {
|
||||
yield this.constructor.prototype.init.apply(this);
|
||||
|
||||
// TODO: get rid of ' AND itemTypeID!=5' and just remove display=2
|
||||
// from magazineArticle in system.sql
|
||||
_primaryTypes = yield this._getTypesFromDB('WHERE (display=2 AND itemTypeID!=5) LIMIT ' + _numPrimary);
|
||||
_primaryTypes = yield this._getTypesFromDB(
|
||||
`WHERE typeName IN ('${_primaryTypeNames.join("', '")}')`
|
||||
);
|
||||
|
||||
// Secondary types
|
||||
_secondaryTypes = yield this._getTypesFromDB('WHERE display IN (1,2)');
|
||||
_secondaryTypes = yield this._getTypesFromDB(
|
||||
`WHERE display != 0 AND display NOT IN ('${_primaryTypeNames.join("', '")}')`
|
||||
);
|
||||
|
||||
// Hidden types
|
||||
_hiddenTypes = yield this._getTypesFromDB('WHERE display=0')
|
||||
|
@ -397,17 +400,17 @@ Zotero.ItemTypes = new function() {
|
|||
mru = new Set(
|
||||
mru.split(',')
|
||||
.slice(0, _numPrimary)
|
||||
.map(id => parseInt(id))
|
||||
.map(name => this.getName(name))
|
||||
// Ignore 'webpage' item type
|
||||
.filter(id => !isNaN(id) && id != 13)
|
||||
.filter(name => name && name != 'webpage')
|
||||
);
|
||||
|
||||
// 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);
|
||||
mru.add(_primaryTypes[i].name);
|
||||
}
|
||||
|
||||
return Array.from(mru).map(id => ({ id, name: this.getName(id) }));
|
||||
return Array.from(mru).map(name => ({ id: this.getID(name), name }));
|
||||
}
|
||||
|
||||
return _primaryTypes;
|
||||
|
|
|
@ -702,22 +702,20 @@ var ZoteroPane = new function()
|
|||
document.getElementById('zotero-tb-search').select();
|
||||
break;
|
||||
case 'newItem':
|
||||
Zotero.Promise.coroutine(function* () {
|
||||
// Default to most recent item type from here or the
|
||||
// New Type menu
|
||||
(async function () {
|
||||
// Default to most recent item type from here or the New Type menu,
|
||||
// or fall back to 'book'
|
||||
var mru = Zotero.Prefs.get('newItemTypeMRU');
|
||||
// Or fall back to 'book'
|
||||
var typeID = mru ? mru.split(',')[0] : 2;
|
||||
yield ZoteroPane_Local.newItem(typeID);
|
||||
var type = mru ? mru.split(',')[0] : 'book';
|
||||
await ZoteroPane.newItem(Zotero.ItemTypes.getID(type));
|
||||
let itemBox = document.getElementById('zotero-editpane-item-box');
|
||||
var menu = itemBox.itemTypeMenu;
|
||||
var self = this;
|
||||
// If the new item's type is changed immediately, update the MRU
|
||||
var handleTypeChange = function () {
|
||||
self.addItemTypeToNewItemTypeMRU(this.itemTypeMenu.value);
|
||||
this.addItemTypeToNewItemTypeMRU(Zotero.ItemTypes.getName(menu.value));
|
||||
itemBox.removeHandler('itemtypechange', handleTypeChange);
|
||||
};
|
||||
// Only update the MRU when the menu is opened for the
|
||||
// keyboard shortcut, not on subsequent opens
|
||||
}.bind(this);
|
||||
// Don't update the MRU on subsequent opens of the item type menu
|
||||
var removeTypeChangeHandler = function () {
|
||||
itemBox.removeHandler('itemtypechange', handleTypeChange);
|
||||
itemBox.itemTypeMenu.firstChild.removeEventListener('popuphiding', removeTypeChangeHandler);
|
||||
|
@ -729,7 +727,7 @@ var ZoteroPane = new function()
|
|||
|
||||
menu.focus();
|
||||
document.getElementById('zotero-editpane-item-box').itemTypeMenu.menupopup.openPopup(menu, "before_start", 0, 0);
|
||||
})();
|
||||
}.bind(this)());
|
||||
break;
|
||||
case 'newNote':
|
||||
// If a regular item is selected, use that as the parent.
|
||||
|
@ -836,7 +834,7 @@ var ZoteroPane = new function()
|
|||
|
||||
if (manual) {
|
||||
// Update most-recently-used list for New Item menu
|
||||
this.addItemTypeToNewItemTypeMRU(typeID);
|
||||
this.addItemTypeToNewItemTypeMRU(Zotero.ItemTypes.getName(typeID));
|
||||
|
||||
// Focus the title field
|
||||
document.getElementById('zotero-editpane-item-box').focusFirstField();
|
||||
|
@ -846,18 +844,18 @@ var ZoteroPane = new function()
|
|||
});
|
||||
|
||||
|
||||
this.addItemTypeToNewItemTypeMRU = function (itemTypeID) {
|
||||
this.addItemTypeToNewItemTypeMRU = function (itemType) {
|
||||
var mru = Zotero.Prefs.get('newItemTypeMRU');
|
||||
if (mru) {
|
||||
var mru = mru.split(',');
|
||||
var pos = mru.indexOf(itemTypeID + '');
|
||||
var pos = mru.indexOf(itemType);
|
||||
if (pos != -1) {
|
||||
mru.splice(pos, 1);
|
||||
}
|
||||
mru.unshift(itemTypeID);
|
||||
mru.unshift(itemType);
|
||||
}
|
||||
else {
|
||||
var mru = [itemTypeID + ''];
|
||||
var mru = [itemType];
|
||||
}
|
||||
Zotero.Prefs.set('newItemTypeMRU', mru.slice(0, 5).join(','));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue