mirror of
https://github.com/zadam/trilium.git
synced 2025-01-16 20:21:43 +08:00
refactoring
This commit is contained in:
parent
14d6372bd8
commit
47f7f5f4d9
6 changed files with 13 additions and 10 deletions
|
@ -33,7 +33,7 @@ class AppContext {
|
|||
|
||||
this.components = [
|
||||
rootContainer,
|
||||
new Entrypoints(),
|
||||
new Entrypoints(this),
|
||||
new DialogEventComponent(this)
|
||||
];
|
||||
|
||||
|
|
|
@ -4,7 +4,10 @@ export default class Component {
|
|||
/** @param {AppContext} appContext */
|
||||
constructor(appContext) {
|
||||
this.componentId = `comp-${this.constructor.name}-` + utils.randomString(6);
|
||||
/** @type AppContext */
|
||||
this.appContext = appContext;
|
||||
/** @type TabManager */
|
||||
this.tabManager = appContext.tabManager;
|
||||
/** @type Component[] */
|
||||
this.children = [];
|
||||
this.initialized = Promise.resolve();
|
||||
|
|
|
@ -54,7 +54,7 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
|||
this.$widget.on("dragleave", e => e.preventDefault());
|
||||
|
||||
this.$widget.on("drop", async e => {
|
||||
const activeNote = this.appContext.tabManager.getActiveTabNote();
|
||||
const activeNote = this.tabManager.getActiveTabNote();
|
||||
|
||||
if (!activeNote) {
|
||||
return;
|
||||
|
|
|
@ -62,7 +62,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||
}
|
||||
});
|
||||
|
||||
treeBuilder.prepareTree().then(treeData => this.initFancyTree($tree, treeData));
|
||||
this.initialized = treeBuilder.prepareTree().then(treeData => this.initFancyTree($tree, treeData));
|
||||
|
||||
return $widget;
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||
|
||||
const notePath = await treeService.getNotePath(data.node);
|
||||
|
||||
const activeTabContext = this.appContext.tabManager.getActiveTabContext();
|
||||
const activeTabContext = this.tabManager.getActiveTabContext();
|
||||
await activeTabContext.setNote(notePath);
|
||||
},
|
||||
expand: (event, data) => this.setExpandedToServer(data.node.data.branchId, true),
|
||||
|
|
|
@ -68,7 +68,7 @@ export default class TabAwareWidget extends BasicWidget {
|
|||
refreshWithNote(note, notePath) {}
|
||||
|
||||
activeTabChangedListener() {
|
||||
this.tabContext = this.appContext.tabManager.getActiveTabContext();
|
||||
this.tabContext = this.tabManager.getActiveTabContext();
|
||||
|
||||
this.activeTabChanged();
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ export default class TabAwareWidget extends BasicWidget {
|
|||
|
||||
lazyLoadedListener() {
|
||||
if (!this.tabContext) { // has not been loaded yet
|
||||
this.tabContext = this.appContext.tabManager.getActiveTabContext();
|
||||
this.tabContext = this.tabManager.getActiveTabContext();
|
||||
}
|
||||
|
||||
this.refresh();
|
||||
|
|
|
@ -490,7 +490,7 @@ export default class TabRowWidget extends BasicWidget {
|
|||
this.draggabillies.push(draggabilly);
|
||||
|
||||
draggabilly.on('pointerDown', _ => {
|
||||
this.appContext.tabManager.activateTab(tabEl.getAttribute('data-tab-id'));
|
||||
this.tabManager.activateTab(tabEl.getAttribute('data-tab-id'));
|
||||
});
|
||||
|
||||
draggabilly.on('dragStart', _ => {
|
||||
|
@ -585,7 +585,7 @@ export default class TabRowWidget extends BasicWidget {
|
|||
tabNoteSwitchedListener({tabId}) {
|
||||
const $tab = this.getTabById(tabId);
|
||||
|
||||
const {note} = this.appContext.tabManager.getTabContextById(tabId);
|
||||
const {note} = this.tabManager.getTabContextById(tabId);
|
||||
|
||||
this.updateTab($tab, note);
|
||||
}
|
||||
|
@ -609,7 +609,7 @@ export default class TabRowWidget extends BasicWidget {
|
|||
}
|
||||
|
||||
async entitiesReloadedListener({loadResults}) {
|
||||
for (const tabContext of this.appContext.tabManager.getTabContexts()) {
|
||||
for (const tabContext of this.tabManager.getTabContexts()) {
|
||||
if (loadResults.isNoteReloaded(tabContext.noteId)) {
|
||||
const $tab = this.getTabById(tabContext.tabId);
|
||||
|
||||
|
@ -619,7 +619,7 @@ export default class TabRowWidget extends BasicWidget {
|
|||
}
|
||||
|
||||
treeCacheReloadedListener() {
|
||||
for (const tabContext of this.appContext.tabManager.getTabContexts()) {
|
||||
for (const tabContext of this.tabManager.getTabContexts()) {
|
||||
const $tab = this.getTabById(tabContext.tabId);
|
||||
|
||||
this.updateTab($tab, tabContext.note);
|
||||
|
|
Loading…
Reference in a new issue