1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

Plugins: Add support for hiding and showing panels

This commit is contained in:
Laurent Cozic
2021-01-02 13:32:15 +00:00
parent 0be8cdf760
commit 5b295d5f6f
25 changed files with 298 additions and 17 deletions

View File

@@ -17,13 +17,33 @@ interface CloseResponse {
reject: Function;
}
// TODO: Copied from:
// packages/app-desktop/gui/ResizableLayout/utils/findItemByKey.ts
function findItemByKey(layout: any, key: string): any {
if (!layout) throw new Error('Layout cannot be null');
function recurseFind(item: any): any {
if (item.key === key) return item;
if (item.children) {
for (const child of item.children) {
const found = recurseFind(child);
if (found) return found;
}
}
return null;
}
return recurseFind(layout);
}
export default class WebviewController extends ViewController {
private baseDir_: string;
private messageListener_: Function = null;
private closeResponse_: CloseResponse = null;
constructor(id: string, pluginId: string, store: any, baseDir: string, containerType: ContainerType) {
public constructor(id: string, pluginId: string, store: any, baseDir: string, containerType: ContainerType) {
super(id, pluginId, store);
this.baseDir_ = toSystemSlashes(baseDir, 'linux');
@@ -91,6 +111,29 @@ export default class WebviewController extends ViewController {
this.messageListener_ = callback;
}
// ---------------------------------------------
// Specific to panels
// ---------------------------------------------
public async show(show: boolean = true): Promise<void> {
this.store.dispatch({
type: 'MAIN_LAYOUT_SET_ITEM_PROP',
itemKey: this.handle,
propName: 'visible',
propValue: show,
});
}
public async hide(): Promise<void> {
return this.show(false);
}
public get visible(): boolean {
const mainLayout = this.store.getState().mainLayout;
const item = findItemByKey(mainLayout, this.handle);
return item ? item.visible : false;
}
// ---------------------------------------------
// Specific to dialogs
// ---------------------------------------------