You've already forked joplin
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:
@@ -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
|
||||
// ---------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user