add: restore note tabs
This commit is contained in:
parent
86c77b0959
commit
75ca707edc
|
|
@ -12,6 +12,7 @@ import {
|
|||
registerWorkspaceTab,
|
||||
openWorkspaceTab,
|
||||
onTabSelect,
|
||||
restoreNoteTabs,
|
||||
} from "./modules/workspace/tab";
|
||||
import { initWorkspace } from "./modules/workspace/content";
|
||||
import { registerNotify } from "./modules/notify";
|
||||
|
|
@ -81,6 +82,8 @@ async function onMainWindowLoad(win: Window): Promise<void> {
|
|||
initTemplates();
|
||||
|
||||
patchViewItems(win);
|
||||
|
||||
restoreNoteTabs();
|
||||
}
|
||||
|
||||
async function onMainWindowUnload(win: Window): Promise<void> {
|
||||
|
|
@ -255,4 +258,5 @@ export default {
|
|||
onShowTemplateEditor,
|
||||
onCreateNoteFromTemplate,
|
||||
onCreateNoteFromMD,
|
||||
restoreNoteTabs,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -52,26 +52,32 @@ export function registerWorkspaceTab(win: Window) {
|
|||
);
|
||||
}
|
||||
|
||||
export async function openWorkspaceTab(item: Zotero.Item) {
|
||||
export async function openWorkspaceTab(
|
||||
item: Zotero.Item,
|
||||
options: { select?: boolean; index?: number } = {
|
||||
select: true,
|
||||
},
|
||||
) {
|
||||
const { select, index } = options;
|
||||
if (!item) return;
|
||||
const currentTab = Zotero_Tabs._tabs.find(
|
||||
(tab) => tab.data?.itemID == item.id,
|
||||
);
|
||||
if (currentTab) {
|
||||
Zotero_Tabs.select(currentTab.id);
|
||||
if (select) Zotero_Tabs.select(currentTab.id);
|
||||
return;
|
||||
}
|
||||
const { id, container } = Zotero_Tabs.add({
|
||||
type: TAB_TYPE,
|
||||
title: item.getNoteTitle(),
|
||||
index: 1,
|
||||
index,
|
||||
data: {
|
||||
itemID: item.id,
|
||||
},
|
||||
select: false,
|
||||
select,
|
||||
onClose: () => {},
|
||||
});
|
||||
initWorkspace(container, item);
|
||||
Zotero_Tabs.select(id);
|
||||
}
|
||||
|
||||
let contextPaneOpen: boolean | undefined = undefined;
|
||||
|
|
@ -91,3 +97,16 @@ export function onTabSelect(tabType: string) {
|
|||
}
|
||||
ZoteroContextPane.update();
|
||||
}
|
||||
|
||||
export function restoreNoteTabs() {
|
||||
const tabsCache: _ZoteroTypes.TabInstance[] =
|
||||
Zotero.Session.state.windows.find((x: any) => x.type == "pane")?.tabs;
|
||||
for (const i in tabsCache) {
|
||||
const tab = tabsCache[i];
|
||||
if (tab.type !== TAB_TYPE) continue;
|
||||
openWorkspaceTab(Zotero.Items.get(tab.data.itemID), {
|
||||
select: tab.selected,
|
||||
index: Number(i),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue