Notes/src/public/app/widgets/containers/pane_container.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-05-19 22:45:34 +02:00
import FlexContainer from "./flex_container.js";
import appContext from "../../services/app_context.js";
import TabContext from "../../services/tab_context.js";
export default class PaneContainer extends FlexContainer {
constructor(widgetFactory) {
super('row');
this.counter = 0;
this.widgetFactory = widgetFactory;
this.child(this.widgetFactory());
this.id('pane-container-widget');
this.css('flex-grow', '1');
}
2021-05-19 23:00:03 +02:00
doRender() {
super.doRender();
this.$widget.find("div").on("click", () => {
const activeTabContext = appContext.tabManager.getActiveTabContext();
const tabId = activeTabContext.parentTabId || activeTabContext.tabId;
appContext.tabManager.activateTab(tabId);
});
}
2021-05-19 22:45:34 +02:00
async openNewPaneCommand() {
const newWidget = this.widgetFactory();
2021-05-19 23:00:03 +02:00
const $rendered = newWidget.render();
this.$widget.append($rendered);
2021-05-19 22:45:34 +02:00
const tabContext = new TabContext();
appContext.tabManager.tabContexts.push(tabContext);
appContext.tabManager.child(tabContext);
2021-05-19 23:00:03 +02:00
$rendered.on('click', () => {
appContext.tabManager.activateTab(tabContext.tabId);
});
2021-05-19 22:45:34 +02:00
tabContext.parentTabId = appContext.tabManager.getActiveTabContext().tabId;
await newWidget.handleEvent('setTabContext', { tabContext });
this.child(newWidget);
tabContext.setEmpty();
appContext.tabManager.activateTab(tabContext.tabId);
}
}