feat: add state for workspace windows

This commit is contained in:
liujuping 2023-07-25 10:28:05 +08:00 committed by 林熠
parent e875e33dc5
commit d267fecc67
2 changed files with 41 additions and 1 deletions

View File

@ -26,6 +26,22 @@ export interface IEditorWindow extends Omit<IPublicModelWindow<IResource>, 'chan
sleep?: boolean;
init(): void;
updateState(state: WINDOW_STATE): void;
}
export enum WINDOW_STATE {
// 睡眠
sleep = 'sleep',
// 激活
active = 'active',
// 未激活
inactive = 'inactive',
// 销毁
destroyed = 'destroyed'
}
export class EditorWindow implements IEditorWindow {
@ -51,6 +67,22 @@ export class EditorWindow implements IEditorWindow {
this.title = config.title;
this.icon = resource.icon;
this.sleep = config.sleep;
if (config.sleep) {
this.updateState(WINDOW_STATE.sleep);
}
}
updateState(state: WINDOW_STATE): void {
switch (state) {
case WINDOW_STATE.active:
this.editorView?.setActivate(true);
break;
case WINDOW_STATE.inactive:
this.editorView?.setActivate(false);
break;
case WINDOW_STATE.destroyed:
break;
}
}
async importSchema(schema: any) {
@ -102,6 +134,7 @@ export class EditorWindow implements IEditorWindow {
this.initReady = true;
this.workspace.checkWindowQueue();
this.sleep = false;
this.updateState(WINDOW_STATE.active);
}
initViewTypes = async () => {

View File

@ -2,7 +2,7 @@ import { IDesigner, ILowCodePluginManager, LowCodePluginManager } from '@alilc/l
import { createModuleEventBus, Editor, IEditor, IEventBus, makeObservable, obx } from '@alilc/lowcode-editor-core';
import { IPublicApiPlugins, IPublicApiWorkspace, IPublicEnumPluginRegisterLevel, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType, IShellModelFactory } from '@alilc/lowcode-types';
import { BasicContext } from './context/base-context';
import { EditorWindow } from './window';
import { EditorWindow, WINDOW_STATE } from './window';
import type { IEditorWindow } from './window';
import { IResource, Resource } from './resource';
import { IResourceType, ResourceType } from './resource-type';
@ -198,6 +198,7 @@ export class Workspace implements IWorkspace {
}
const window = this.windows[index];
this.windows.splice(index, 1);
this.window?.updateState(WINDOW_STATE.destroyed);
if (this.window === window) {
this.window = this.windows[index] || this.windows[index + 1] || this.windows[index - 1];
if (this.window?.sleep) {
@ -206,6 +207,7 @@ export class Workspace implements IWorkspace {
this.emitChangeActiveWindow();
}
this.emitChangeWindow();
this.window?.updateState(WINDOW_STATE.active);
}
removeEditorWindow(resourceName: string, title: string) {
@ -215,6 +217,7 @@ export class Workspace implements IWorkspace {
async openEditorWindowById(id: string) {
const window = this.editorWindowMap.get(id);
this.window?.updateState(WINDOW_STATE.inactive);
if (window) {
this.window = window;
if (window.sleep) {
@ -222,6 +225,7 @@ export class Workspace implements IWorkspace {
}
this.emitChangeActiveWindow();
}
this.window?.updateState(WINDOW_STATE.active);
}
async openEditorWindow(name: string, title: string, options: Object, viewType?: string, sleep?: boolean) {
@ -236,6 +240,7 @@ export class Workspace implements IWorkspace {
console.error(`${name} resourceType is not available`);
return;
}
this.window?.updateState(WINDOW_STATE.inactive);
const filterWindows = this.windows.filter(d => (d.resource?.name === name && d.resource.title == title));
if (filterWindows && filterWindows.length) {
this.window = filterWindows[0];
@ -245,6 +250,7 @@ export class Workspace implements IWorkspace {
this.checkWindowQueue();
}
this.emitChangeActiveWindow();
this.window?.updateState(WINDOW_STATE.active);
return;
}
const resource = new Resource({
@ -266,6 +272,7 @@ export class Workspace implements IWorkspace {
}
this.emitChangeWindow();
this.emitChangeActiveWindow();
this.window?.updateState(WINDOW_STATE.active);
}
onChangeWindows(fn: () => void) {