mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
refactored TabContext => NoteContext
This commit is contained in:
parent
98dfc77195
commit
5b220adc31
@ -224,7 +224,7 @@ export default class Entrypoints extends Component {
|
||||
this.hideAllTooltips();
|
||||
}
|
||||
|
||||
activeTabChangedEvent() {
|
||||
activeContextChangedEvent() {
|
||||
this.hideAllTooltips();
|
||||
}
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ export default class TabManager extends Component {
|
||||
this.activeNtxId = ntxId;
|
||||
|
||||
if (triggerEvent) {
|
||||
this.triggerEvent('activeTabChanged', {
|
||||
this.triggerEvent('activeContextChanged', {
|
||||
noteContext: this.getNoteContextById(ntxId)
|
||||
});
|
||||
}
|
||||
|
@ -5,8 +5,6 @@ export default class PaneContainer extends FlexContainer {
|
||||
constructor(widgetFactory) {
|
||||
super('row');
|
||||
|
||||
this.counter = 0;
|
||||
|
||||
this.widgetFactory = widgetFactory;
|
||||
this.widgets = {};
|
||||
|
||||
@ -25,13 +23,13 @@ export default class PaneContainer extends FlexContainer {
|
||||
|
||||
this.$widget.append($renderedWidget);
|
||||
|
||||
widget.toggleExt(false);
|
||||
|
||||
this.widgets[noteContext.ntxId] = widget;
|
||||
|
||||
await widget.handleEvent('setNoteContext', { noteContext });
|
||||
|
||||
this.child(widget);
|
||||
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
async openNewPaneCommand() {
|
||||
@ -42,6 +40,14 @@ export default class PaneContainer extends FlexContainer {
|
||||
await noteContext.setEmpty();
|
||||
}
|
||||
|
||||
activeContextChangedEvent() {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
noteSwitchedAndActivatedEvent() {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
async refresh() {
|
||||
this.toggleExt(true);
|
||||
}
|
||||
@ -57,10 +63,6 @@ export default class PaneContainer extends FlexContainer {
|
||||
|
||||
const widget = this.widgets[ntxId];
|
||||
widget.toggleExt(show && activeNtxId && [noteContext.ntxId, noteContext.mainNtxId].includes(activeNtxId));
|
||||
|
||||
if (!widget.hasBeenAlreadyShown) {
|
||||
widget.handleEvent('activeTabChanged', {noteContext});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,58 +80,42 @@ export default class PaneContainer extends FlexContainer {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
const promises = [];
|
||||
if (widget.hasBeenAlreadyShown
|
||||
|| name === 'noteSwitchedAndActivated'
|
||||
|| appContext.tabManager.getActiveMainContext() === data.noteContext.getMainContext()
|
||||
) {
|
||||
widget.hasBeenAlreadyShown = true;
|
||||
|
||||
if (appContext.tabManager.getActiveMainContext() === data.noteContext.getMainContext()) {
|
||||
promises.push(widget.handleEvent('activeTabChanged', data));
|
||||
return [
|
||||
widget.handleEvent('noteSwitched', data),
|
||||
this.refreshNotShown(data)
|
||||
];
|
||||
}
|
||||
|
||||
for (const subNoteContext of data.noteContext.getMainContext().getSubContexts()) {
|
||||
const subWidget = this.widgets[subNoteContext.ntxId];
|
||||
|
||||
if (!subWidget) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (subNoteContext !== data.noteContext && !subWidget.hasBeenAlreadyShown) {
|
||||
promises.push(widget.handleEvent('activeTabChanged', {noteContext: subNoteContext}));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (subNoteContext === data.noteContext && (subWidget.hasBeenAlreadyShown || name === 'noteSwitchedAndActivated')) {
|
||||
subWidget.hasBeenAlreadyShown = true;
|
||||
|
||||
promises.push(widget.handleEvent('noteSwitched', data));
|
||||
}
|
||||
else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
if (name === 'noteSwitchedAndActivated') {
|
||||
this.toggleExt(true);
|
||||
}
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
if (name === 'activeTabChanged') {
|
||||
const promises = [];
|
||||
|
||||
for (const subNoteContext of data.noteContext.getMainContext().getSubContexts()) {
|
||||
console.log("subNoteContext", subNoteContext);
|
||||
|
||||
const widget = this.widgets[subNoteContext.ntxId];
|
||||
|
||||
if (!widget.hasBeenAlreadyShown) {
|
||||
widget.hasBeenAlreadyShown = true;
|
||||
|
||||
promises.push(widget.handleEvent(name, {noteContext: subNoteContext}));
|
||||
}
|
||||
}
|
||||
|
||||
this.toggleExt(true);
|
||||
|
||||
return Promise.all(promises);
|
||||
if (name === 'activeContextChanged') {
|
||||
return this.refreshNotShown(data);
|
||||
} else {
|
||||
return super.handleEventInChildren(name, data);
|
||||
}
|
||||
}
|
||||
|
||||
refreshNotShown(data) {
|
||||
const promises = [];
|
||||
|
||||
for (const subContext of data.noteContext.getMainContext().getSubContexts()) {
|
||||
const widget = this.widgets[subContext.ntxId];
|
||||
|
||||
if (!widget.hasBeenAlreadyShown) {
|
||||
widget.hasBeenAlreadyShown = true;
|
||||
|
||||
promises.push(widget.handleEvent('activeContextChanged', {noteContext: subContext}));
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.all(promises);
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ export default class RootContainer extends FlexContainer {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
activeTabChangedEvent() {
|
||||
activeContextChangedEvent() {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
|
@ -66,13 +66,13 @@ export default class NoteContextAwareWidget extends BasicWidget {
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
async activeTabChangedEvent({noteContext}) {
|
||||
async activeContextChangedEvent({noteContext}) {
|
||||
this.noteContext = noteContext;
|
||||
|
||||
await this.activeTabChanged();
|
||||
await this.activeContextChanged();
|
||||
}
|
||||
|
||||
async activeTabChanged() {
|
||||
async activeContextChanged() {
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
|
@ -67,11 +67,7 @@ export default class NoteContextCachingWidget extends NoteContextAwareWidget {
|
||||
handleEventInChildren(name, data) {
|
||||
if (['noteSwitched', 'noteSwitchedAndActivated'].includes(name)) {
|
||||
// this event is propagated only to the widgets of a particular tab
|
||||
let widget = this.widgets[data.noteContext.ntxId];
|
||||
|
||||
if (!widget) {
|
||||
widget = this.widgets[data.noteContext.mainNtxId];
|
||||
}
|
||||
const widget = this.widgets[data.noteContext.ntxId];
|
||||
|
||||
if (widget && (widget.hasBeenAlreadyShown || name === 'noteSwitchedAndActivated')) {
|
||||
widget.hasBeenAlreadyShown = true;
|
||||
@ -83,12 +79,8 @@ export default class NoteContextCachingWidget extends NoteContextAwareWidget {
|
||||
}
|
||||
}
|
||||
|
||||
if (name === 'activeTabChanged') {
|
||||
let widget = this.widgets[data.noteContext.ntxId];
|
||||
|
||||
if (!widget) {
|
||||
widget = this.widgets[data.noteContext.mainNtxId];
|
||||
}
|
||||
if (name === 'activeContextChanged') {
|
||||
const widget = this.widgets[data.noteContext.ntxId];
|
||||
|
||||
if (widget.hasBeenAlreadyShown) {
|
||||
return Promise.resolve();
|
||||
|
@ -426,7 +426,7 @@ export default class TabRowWidget extends BasicWidget {
|
||||
return this.$widget.find('.note-tab[active]')[0];
|
||||
}
|
||||
|
||||
activeTabChangedEvent() {
|
||||
activeContextChangedEvent() {
|
||||
let activeNoteContext = appContext.tabManager.getActiveContext();
|
||||
|
||||
if (!activeNoteContext) {
|
||||
@ -612,7 +612,7 @@ export default class TabRowWidget extends BasicWidget {
|
||||
};
|
||||
|
||||
noteSwitchedAndActivatedEvent({noteContext}) {
|
||||
this.activeTabChangedEvent();
|
||||
this.activeContextChangedEvent();
|
||||
|
||||
this.updateTabById(noteContext.mainNtxId || noteContext.ntxId);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user