split window WIP

This commit is contained in:
zadam 2021-05-21 22:34:40 +02:00
parent 1a13132a69
commit 39f0f26f28
4 changed files with 82 additions and 49 deletions

View File

@ -100,6 +100,8 @@ export default class TabManager extends Component {
filteredTabs[0].active = true;
}
console.log("filteredTabs", filteredTabs);
await this.tabsUpdate.allowUpdateWithoutChange(async () => {
for (const tab of filteredTabs) {
await this.openTabWithNote(tab.notePath, tab.active, tab.tabId, tab.hoistedNoteId, tab.parentTabId);
@ -201,8 +203,15 @@ export default class TabManager extends Component {
await tabContext.setEmpty();
}
async openEmptyTab(tabId, hoistedNoteId, parentTabId = null) {
async openEmptyTab(tabId, hoistedNoteId = 'root', parentTabId = null) {
const tabContext = new TabContext(tabId, hoistedNoteId, parentTabId);
const existingTabContext = this.children.find(tc => tc.tabId === tabContext.tabId);
if (existingTabContext) {
return existingTabContext;
}
this.child(tabContext);
await this.triggerEvent('newTabOpened', {tabContext});
@ -228,7 +237,7 @@ export default class TabManager extends Component {
return this.openTabWithNote(notePath, false, null, hoistedNoteId);
}
async openTabWithNote(notePath, activate, tabId, hoistedNoteId, parentTabId = null) {
async openTabWithNote(notePath, activate, tabId, hoistedNoteId = 'root', parentTabId = null) {
const tabContext = await this.openEmptyTab(tabId, hoistedNoteId, parentTabId);
if (notePath) {
@ -280,15 +289,7 @@ export default class TabManager extends Component {
}
async removeTab(tabId) {
let mainTabContextToRemove = this.getTabContextById(tabId);
if (!mainTabContextToRemove) {
return;
}
if (mainTabContextToRemove.parentTabId) {
mainTabContextToRemove = this.getTabContextById(mainTabContextToRemove.parentTabId);
}
const mainTabContextToRemove = this.getTabContextById(tabId).getMainTabContext();
// close dangling autocompletes after closing the tab
$(".aa-input").autocomplete("close");

View File

@ -14,51 +14,55 @@ export default class PaneContainer extends FlexContainer {
this.css('flex-grow', '1');
}
setTabContextEvent({tabContext}) {
/** @var {TabContext} */
this.tabContext = tabContext;
}
async newTabOpenedEvent({tabContext}) {
const widget = this.widgetFactory();
const $renderedWidget = widget.render();
$renderedWidget.on('click', () => {
appContext.tabManager.activateTab(tabContext.tabId);
});
$renderedWidget.attr("data-main-tab-id", tabContext.tabId);
let $parent;
$renderedWidget.on('click', () => appContext.tabManager.activateTab(tabContext.tabId));
if (!tabContext.parentTabId) {
$parent = $("<div>")
.attr("data-main-tab-id", tabContext.tabId)
.css("display", "flex")
.css("flex-grow", "1");
this.$widget.append($parent);
}
else {
$parent = this.$widget.find(`[data-main-tab-id="${tabContext.parentTabId}"]`);
}
$parent.append($renderedWidget);
this.$widget.append($renderedWidget);
this.widgets[tabContext.tabId] = widget;
await widget.handleEvent('setTabContext', { tabContext });
this.child(widget);
this.refresh();
}
async openNewPaneCommand() {
const tabContext = await appContext.tabManager.openEmptyTab(null, null, appContext.tabManager.getActiveTabContext().tabId);
const tabContext = await appContext.tabManager.openEmptyTab(null, 'root', appContext.tabManager.getActiveTabContext().tabId);
await appContext.tabManager.activateTab(tabContext.tabId);
await tabContext.setEmpty();
}
async refresh() {
this.toggleExt(true);
}
toggleInt(show) {} // not needed
toggleExt(show) {
const activeTabId = appContext.tabManager.getActiveTabContext().getMainTabContext().tabId;
for (const tabId in this.widgets) {
const tabContext = appContext.tabManager.getTabContextById(tabId);
const widget = this.widgets[tabId];
widget.toggleExt(show && activeTabId && [tabContext.tabId, tabContext.parentTabId].includes(activeTabId));
if (!widget.hasBeenAlreadyShown) {
widget.handleEvent('activeTabChanged', {tabContext});
}
}
}
/**
* widget.hasBeenAlreadyShown is intended for lazy loading of cached tabs - initial note switches of new tabs
* are not executed, we're waiting for the first tab activation and then we update the tab. After this initial
@ -69,27 +73,56 @@ export default class PaneContainer extends FlexContainer {
// this event is propagated only to the widgets of a particular tab
const widget = this.widgets[data.tabContext.tabId];
if (widget && (widget.hasBeenAlreadyShown || name === 'tabNoteSwitchedAndActivated')) {
widget.hasBeenAlreadyShown = true;
return widget.handleEvent('tabNoteSwitched', data);
}
else {
if (!widget) {
return Promise.resolve();
}
const promises = [];
for (const subTabContext of data.tabContext.getMainTabContext().getAllSubTabContexts()) {
const subWidget = this.widgets[subTabContext.tabId];
if (!subWidget) {
continue;
}
if (subTabContext !== data.tabContext && !subWidget.hasBeenAlreadyShown) {
promises.push(widget.handleEvent('activeTabChanged', {tabContext: subTabContext}));
continue;
}
if (subTabContext === data.tabContext && (subWidget.hasBeenAlreadyShown || name === 'tabNoteSwitchedAndActivated')) {
subWidget.hasBeenAlreadyShown = true;
promises.push(widget.handleEvent('tabNoteSwitched', data));
}
}
if (name === 'tabNoteSwitchedAndActivated') {
this.toggleExt(true);
}
return Promise.all(promises);
}
if (name === 'activeTabChanged') {
const widget = this.widgets[data.tabContext.tabId];
const promises = [];
if (widget.hasBeenAlreadyShown) {
return Promise.resolve();
}
else {
widget.hasBeenAlreadyShown = true;
for (const subTabContext of data.tabContext.getMainTabContext().getAllSubTabContexts()) {
console.log("subTabContext", subTabContext);
return widget.handleEvent(name, data);
const widget = this.widgets[subTabContext.tabId];
if (!widget.hasBeenAlreadyShown) {
widget.hasBeenAlreadyShown = true;
promises.push(widget.handleEvent(name, {tabContext: subTabContext}));
}
}
this.toggleExt(true);
return Promise.all(promises);
} else {
return super.handleEventInChildren(name, data);
}

View File

@ -55,7 +55,7 @@ export default class TabCachingWidget extends TabAwareWidget {
toggleExt(show) {
for (const tabId in this.widgets) {
this.widgets[tabId].toggleExt(show && this.isTabOrParent(tabId));
this.widgets[tabId].toggleExt(show && this.isTab(tabId));
}
}

View File

@ -2,7 +2,6 @@ import noteAutocompleteService from '../../services/note_autocomplete.js';
import TypeWidget from "./type_widget.js";
import appContext from "../../services/app_context.js";
import searchService from "../../services/search.js";
import linkService from "../../services/link.js";
const TPL = `
<div class="note-detail-empty note-detail-printable">