mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 02:02:29 +08:00
68 lines
1.4 KiB
JavaScript
68 lines
1.4 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.noteId === noteId;
|
|
}
|
|
|
|
get note() {
|
|
return this.tabContext && this.tabContext.note;
|
|
}
|
|
|
|
get noteId() {
|
|
return this.note && this.note.noteId;
|
|
}
|
|
|
|
get notePath() {
|
|
return this.tabContext && this.tabContext.notePath;
|
|
}
|
|
|
|
tabNoteSwitchedListener({tabId}) {
|
|
if (this.isTab(tabId)) {
|
|
this.noteSwitched();
|
|
}
|
|
}
|
|
|
|
noteSwitched() {
|
|
this.refresh();
|
|
}
|
|
|
|
activeTabChanged() {
|
|
this.refresh();
|
|
}
|
|
|
|
refresh() {
|
|
if (this.note) {
|
|
this.toggle(true);
|
|
this.refreshWithNote(this.note, this.notePath);
|
|
}
|
|
else {
|
|
this.toggle(false);
|
|
}
|
|
}
|
|
|
|
refreshWithNote(note, notePath) {}
|
|
|
|
activeTabChangedListener() {
|
|
this.tabContext = this.appContext.getActiveTabContext();
|
|
|
|
this.activeTabChanged();
|
|
}
|
|
|
|
entitiesReloadedListener({loadResults}) {
|
|
if (loadResults.isNoteReloaded(this.noteId, this.componentId)) {
|
|
this.refreshWithNote(this.note, this.notePath);
|
|
}
|
|
}
|
|
} |