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