refactor: standardize showInLibrary as a ZoteroPane function

This commit is contained in:
Ramon Mi 2026-04-08 14:07:54 +08:00
parent db39f313a6
commit f974700fac
3 changed files with 25 additions and 12 deletions

View file

@ -240,16 +240,6 @@ const ZoteroStandalone = new function () {
this.onUpdateCustomMenus(event, 'edit');
};
this.showNoteInLibrary = function () {
let win = Zotero.getMainWindow();
let noteEditor = Zotero.Notes.getByTabID(Zotero_Tabs.selectedID);
if (!noteEditor?.itemID) {
return;
}
win.ZoteroPane.selectItems([noteEditor.itemID]);
win.focus();
};
/**
* Builds new item menu

View file

@ -5397,6 +5397,30 @@ var ZoteroPane = new function () {
}
this.showInLibrary = function () {
switch (Zotero_Tabs.selectedType) {
case 'reader': {
let reader = Zotero.Reader.getByTabID(Zotero_Tabs.selectedID);
if (reader) {
let item = Zotero.Items.get(reader.itemID);
let itemID = item.parentID || item.id;
return ZoteroPane.selectItems([itemID]);
}
return;
}
case 'note': {
let tab = Zotero_Tabs.getTabInfo(Zotero_Tabs.selectedID);
if (tab.data.itemID) {
return ZoteroPane.selectItems([tab.data.itemID]);
}
return;
}
default:
return;
}
};
function viewSelectedAttachment(event, noLocateOnMissing)
{
if (this.itemsView && this.itemsView.selection.count == 1) {

View file

@ -324,8 +324,7 @@
oncommand="ZoteroStandalone.currentReader.export()"/>
<menuseparator class="menu-type-reader pdf"/>
<menuitem id="menu_print" data-l10n-id="menu-print" class="menu-type-reader" oncommand="ZoteroStandalone.currentReader.print()"/>
<menuitem id="menu_showInLibrary" label="&zotero.items.menu.showInLibrary;" class="menu-type-reader" oncommand="ZoteroStandalone.currentReader.showInLibrary()"/>
<menuitem id="menu_showInLibrary_note" label="&zotero.items.menu.showInLibrary;" class="menu-type-note" oncommand="ZoteroStandalone.showNoteInLibrary()"/>
<menuitem id="menu_showInLibrary" label="&zotero.items.menu.showInLibrary;" class="menu-type-reader menu-type-note" oncommand="ZoteroPane.showInLibrary()"/>
<menuseparator/>
<menuitem id="menu_close" class="menu-type-library" label="&closeCmd.label;" key="key_close"
accesskey="&closeCmd.accesskey;" command="cmd_close"/>