2020-01-12 19:05:09 +01:00
|
|
|
import BasicWidget from "./basic_widget.js";
|
|
|
|
|
|
|
|
export default class TabAwareWidget extends BasicWidget {
|
2020-01-18 19:46:30 +01:00
|
|
|
setTabContextListener({tabContext}) {
|
2020-01-12 19:05:09 +01:00
|
|
|
/** @var {TabContext} */
|
2020-01-16 22:44:36 +01:00
|
|
|
this.tabContext = tabContext;
|
2020-01-18 18:01:16 +01:00
|
|
|
|
2020-01-18 19:46:30 +01:00
|
|
|
this.noteSwitched();
|
2020-01-12 19:05:09 +01:00
|
|
|
}
|
|
|
|
|
2020-01-19 20:18:02 +01:00
|
|
|
isTab(tabId) {
|
|
|
|
return this.tabContext && this.tabContext.tabId === tabId;
|
|
|
|
}
|
|
|
|
|
|
|
|
isNote(noteId) {
|
2020-01-27 22:58:03 +01:00
|
|
|
return this.noteId === noteId;
|
|
|
|
}
|
|
|
|
|
|
|
|
get note() {
|
|
|
|
return this.tabContext && this.tabContext.note;
|
|
|
|
}
|
|
|
|
|
|
|
|
get noteId() {
|
|
|
|
return this.note && this.note.noteId;
|
2020-01-19 20:18:02 +01:00
|
|
|
}
|
|
|
|
|
2020-01-28 21:54:28 +01:00
|
|
|
get notePath() {
|
|
|
|
return this.tabContext && this.tabContext.notePath;
|
|
|
|
}
|
|
|
|
|
2020-01-18 18:01:16 +01:00
|
|
|
tabNoteSwitchedListener({tabId}) {
|
2020-01-19 20:18:02 +01:00
|
|
|
if (this.isTab(tabId)) {
|
2020-01-18 18:01:16 +01:00
|
|
|
this.noteSwitched();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-18 19:46:30 +01:00
|
|
|
noteSwitched() {
|
|
|
|
this.refresh();
|
|
|
|
}
|
2020-01-18 18:01:16 +01:00
|
|
|
|
2020-01-18 19:46:30 +01:00
|
|
|
activeTabChanged() {
|
|
|
|
this.refresh();
|
|
|
|
}
|
|
|
|
|
2020-01-19 11:37:24 +01:00
|
|
|
refresh() {
|
2020-01-28 21:54:28 +01:00
|
|
|
if (this.note) {
|
2020-01-19 11:37:24 +01:00
|
|
|
this.toggle(true);
|
2020-01-28 21:54:28 +01:00
|
|
|
this.refreshWithNote(this.note, this.notePath);
|
2020-01-19 11:37:24 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.toggle(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-28 21:54:28 +01:00
|
|
|
refreshWithNote(note, notePath) {}
|
2020-01-12 19:05:09 +01:00
|
|
|
|
|
|
|
activeTabChangedListener() {
|
|
|
|
this.tabContext = this.appContext.getActiveTabContext();
|
|
|
|
|
|
|
|
this.activeTabChanged();
|
|
|
|
}
|
2020-02-01 22:29:32 +01:00
|
|
|
|
|
|
|
treeCacheReloadedListener() {
|
|
|
|
this.refresh();
|
|
|
|
}
|
2020-01-12 19:05:09 +01:00
|
|
|
}
|