mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
50 lines
1.1 KiB
JavaScript
50 lines
1.1 KiB
JavaScript
import BasicWidget from "./basic_widget.js";
|
|
|
|
export default class TabAwareWidget extends BasicWidget {
|
|
setTabContextListener({tabContext}) {
|
|
/** @var {TabContext} */
|
|
this.tabContext = tabContext;
|
|
|
|
this.noteSwitched();
|
|
}
|
|
|
|
isTab(tabId) {
|
|
return this.tabContext && this.tabContext.tabId === tabId;
|
|
}
|
|
|
|
isNote(noteId) {
|
|
return this.tabContext && this.tabContext.note && this.tabContext.note.noteId === noteId;
|
|
}
|
|
|
|
tabNoteSwitchedListener({tabId}) {
|
|
if (this.isTab(tabId)) {
|
|
this.noteSwitched();
|
|
}
|
|
}
|
|
|
|
noteSwitched() {
|
|
this.refresh();
|
|
}
|
|
|
|
activeTabChanged() {
|
|
this.refresh();
|
|
}
|
|
|
|
refresh() {
|
|
if (this.tabContext && this.tabContext.note) {
|
|
this.toggle(true);
|
|
this.refreshWithNote(this.tabContext.note, this.tabContext.notePath);
|
|
}
|
|
else {
|
|
this.toggle(false);
|
|
}
|
|
}
|
|
|
|
refreshWithNote(note) {}
|
|
|
|
activeTabChangedListener() {
|
|
this.tabContext = this.appContext.getActiveTabContext();
|
|
|
|
this.activeTabChanged();
|
|
}
|
|
} |