refactored TabContext => NoteContext

This commit is contained in:
zadam 2021-05-22 17:58:46 +02:00
parent 98dfc77195
commit 5b220adc31
7 changed files with 50 additions and 72 deletions

View File

@ -224,7 +224,7 @@ export default class Entrypoints extends Component {
this.hideAllTooltips(); this.hideAllTooltips();
} }
activeTabChangedEvent() { activeContextChangedEvent() {
this.hideAllTooltips(); this.hideAllTooltips();
} }
} }

View File

@ -285,7 +285,7 @@ export default class TabManager extends Component {
this.activeNtxId = ntxId; this.activeNtxId = ntxId;
if (triggerEvent) { if (triggerEvent) {
this.triggerEvent('activeTabChanged', { this.triggerEvent('activeContextChanged', {
noteContext: this.getNoteContextById(ntxId) noteContext: this.getNoteContextById(ntxId)
}); });
} }

View File

@ -5,8 +5,6 @@ export default class PaneContainer extends FlexContainer {
constructor(widgetFactory) { constructor(widgetFactory) {
super('row'); super('row');
this.counter = 0;
this.widgetFactory = widgetFactory; this.widgetFactory = widgetFactory;
this.widgets = {}; this.widgets = {};
@ -25,13 +23,13 @@ export default class PaneContainer extends FlexContainer {
this.$widget.append($renderedWidget); this.$widget.append($renderedWidget);
widget.toggleExt(false);
this.widgets[noteContext.ntxId] = widget; this.widgets[noteContext.ntxId] = widget;
await widget.handleEvent('setNoteContext', { noteContext }); await widget.handleEvent('setNoteContext', { noteContext });
this.child(widget); this.child(widget);
this.refresh();
} }
async openNewPaneCommand() { async openNewPaneCommand() {
@ -42,6 +40,14 @@ export default class PaneContainer extends FlexContainer {
await noteContext.setEmpty(); await noteContext.setEmpty();
} }
activeContextChangedEvent() {
this.refresh();
}
noteSwitchedAndActivatedEvent() {
this.refresh();
}
async refresh() { async refresh() {
this.toggleExt(true); this.toggleExt(true);
} }
@ -57,10 +63,6 @@ export default class PaneContainer extends FlexContainer {
const widget = this.widgets[ntxId]; const widget = this.widgets[ntxId];
widget.toggleExt(show && activeNtxId && [noteContext.ntxId, noteContext.mainNtxId].includes(activeNtxId)); 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(); return Promise.resolve();
} }
const promises = []; if (widget.hasBeenAlreadyShown
|| name === 'noteSwitchedAndActivated'
if (appContext.tabManager.getActiveMainContext() === data.noteContext.getMainContext()) { || appContext.tabManager.getActiveMainContext() === data.noteContext.getMainContext()
promises.push(widget.handleEvent('activeTabChanged', 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));
}
}
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; widget.hasBeenAlreadyShown = true;
promises.push(widget.handleEvent(name, {noteContext: subNoteContext})); return [
widget.handleEvent('noteSwitched', data),
this.refreshNotShown(data)
];
}
else {
return Promise.resolve();
} }
} }
this.toggleExt(true); if (name === 'activeContextChanged') {
return this.refreshNotShown(data);
return Promise.all(promises);
} else { } else {
return super.handleEventInChildren(name, data); 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);
}
} }

View File

@ -45,7 +45,7 @@ export default class RootContainer extends FlexContainer {
this.refresh(); this.refresh();
} }
activeTabChangedEvent() { activeContextChangedEvent() {
this.refresh(); this.refresh();
} }

View File

@ -66,13 +66,13 @@ export default class NoteContextAwareWidget extends BasicWidget {
await this.refresh(); await this.refresh();
} }
async activeTabChangedEvent({noteContext}) { async activeContextChangedEvent({noteContext}) {
this.noteContext = noteContext; this.noteContext = noteContext;
await this.activeTabChanged(); await this.activeContextChanged();
} }
async activeTabChanged() { async activeContextChanged() {
await this.refresh(); await this.refresh();
} }

View File

@ -67,11 +67,7 @@ export default class NoteContextCachingWidget extends NoteContextAwareWidget {
handleEventInChildren(name, data) { handleEventInChildren(name, data) {
if (['noteSwitched', 'noteSwitchedAndActivated'].includes(name)) { if (['noteSwitched', 'noteSwitchedAndActivated'].includes(name)) {
// this event is propagated only to the widgets of a particular tab // this event is propagated only to the widgets of a particular tab
let widget = this.widgets[data.noteContext.ntxId]; const widget = this.widgets[data.noteContext.ntxId];
if (!widget) {
widget = this.widgets[data.noteContext.mainNtxId];
}
if (widget && (widget.hasBeenAlreadyShown || name === 'noteSwitchedAndActivated')) { if (widget && (widget.hasBeenAlreadyShown || name === 'noteSwitchedAndActivated')) {
widget.hasBeenAlreadyShown = true; widget.hasBeenAlreadyShown = true;
@ -83,12 +79,8 @@ export default class NoteContextCachingWidget extends NoteContextAwareWidget {
} }
} }
if (name === 'activeTabChanged') { if (name === 'activeContextChanged') {
let widget = this.widgets[data.noteContext.ntxId]; const widget = this.widgets[data.noteContext.ntxId];
if (!widget) {
widget = this.widgets[data.noteContext.mainNtxId];
}
if (widget.hasBeenAlreadyShown) { if (widget.hasBeenAlreadyShown) {
return Promise.resolve(); return Promise.resolve();

View File

@ -426,7 +426,7 @@ export default class TabRowWidget extends BasicWidget {
return this.$widget.find('.note-tab[active]')[0]; return this.$widget.find('.note-tab[active]')[0];
} }
activeTabChangedEvent() { activeContextChangedEvent() {
let activeNoteContext = appContext.tabManager.getActiveContext(); let activeNoteContext = appContext.tabManager.getActiveContext();
if (!activeNoteContext) { if (!activeNoteContext) {
@ -612,7 +612,7 @@ export default class TabRowWidget extends BasicWidget {
}; };
noteSwitchedAndActivatedEvent({noteContext}) { noteSwitchedAndActivatedEvent({noteContext}) {
this.activeTabChangedEvent(); this.activeContextChangedEvent();
this.updateTabById(noteContext.mainNtxId || noteContext.ntxId); this.updateTabById(noteContext.mainNtxId || noteContext.ntxId);
} }