mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2025-12-12 11:20:11 +00:00
feat: add state for workspace windows
This commit is contained in:
parent
e875e33dc5
commit
d267fecc67
@ -26,6 +26,22 @@ export interface IEditorWindow extends Omit<IPublicModelWindow<IResource>, 'chan
|
|||||||
sleep?: boolean;
|
sleep?: boolean;
|
||||||
|
|
||||||
init(): void;
|
init(): void;
|
||||||
|
|
||||||
|
updateState(state: WINDOW_STATE): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum WINDOW_STATE {
|
||||||
|
// 睡眠
|
||||||
|
sleep = 'sleep',
|
||||||
|
|
||||||
|
// 激活
|
||||||
|
active = 'active',
|
||||||
|
|
||||||
|
// 未激活
|
||||||
|
inactive = 'inactive',
|
||||||
|
|
||||||
|
// 销毁
|
||||||
|
destroyed = 'destroyed'
|
||||||
}
|
}
|
||||||
|
|
||||||
export class EditorWindow implements IEditorWindow {
|
export class EditorWindow implements IEditorWindow {
|
||||||
@ -51,6 +67,22 @@ export class EditorWindow implements IEditorWindow {
|
|||||||
this.title = config.title;
|
this.title = config.title;
|
||||||
this.icon = resource.icon;
|
this.icon = resource.icon;
|
||||||
this.sleep = config.sleep;
|
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) {
|
async importSchema(schema: any) {
|
||||||
@ -102,6 +134,7 @@ export class EditorWindow implements IEditorWindow {
|
|||||||
this.initReady = true;
|
this.initReady = true;
|
||||||
this.workspace.checkWindowQueue();
|
this.workspace.checkWindowQueue();
|
||||||
this.sleep = false;
|
this.sleep = false;
|
||||||
|
this.updateState(WINDOW_STATE.active);
|
||||||
}
|
}
|
||||||
|
|
||||||
initViewTypes = async () => {
|
initViewTypes = async () => {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import { IDesigner, ILowCodePluginManager, LowCodePluginManager } from '@alilc/l
|
|||||||
import { createModuleEventBus, Editor, IEditor, IEventBus, makeObservable, obx } from '@alilc/lowcode-editor-core';
|
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 { IPublicApiPlugins, IPublicApiWorkspace, IPublicEnumPluginRegisterLevel, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType, IShellModelFactory } from '@alilc/lowcode-types';
|
||||||
import { BasicContext } from './context/base-context';
|
import { BasicContext } from './context/base-context';
|
||||||
import { EditorWindow } from './window';
|
import { EditorWindow, WINDOW_STATE } from './window';
|
||||||
import type { IEditorWindow } from './window';
|
import type { IEditorWindow } from './window';
|
||||||
import { IResource, Resource } from './resource';
|
import { IResource, Resource } from './resource';
|
||||||
import { IResourceType, ResourceType } from './resource-type';
|
import { IResourceType, ResourceType } from './resource-type';
|
||||||
@ -198,6 +198,7 @@ export class Workspace implements IWorkspace {
|
|||||||
}
|
}
|
||||||
const window = this.windows[index];
|
const window = this.windows[index];
|
||||||
this.windows.splice(index, 1);
|
this.windows.splice(index, 1);
|
||||||
|
this.window?.updateState(WINDOW_STATE.destroyed);
|
||||||
if (this.window === window) {
|
if (this.window === window) {
|
||||||
this.window = this.windows[index] || this.windows[index + 1] || this.windows[index - 1];
|
this.window = this.windows[index] || this.windows[index + 1] || this.windows[index - 1];
|
||||||
if (this.window?.sleep) {
|
if (this.window?.sleep) {
|
||||||
@ -206,6 +207,7 @@ export class Workspace implements IWorkspace {
|
|||||||
this.emitChangeActiveWindow();
|
this.emitChangeActiveWindow();
|
||||||
}
|
}
|
||||||
this.emitChangeWindow();
|
this.emitChangeWindow();
|
||||||
|
this.window?.updateState(WINDOW_STATE.active);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeEditorWindow(resourceName: string, title: string) {
|
removeEditorWindow(resourceName: string, title: string) {
|
||||||
@ -215,6 +217,7 @@ export class Workspace implements IWorkspace {
|
|||||||
|
|
||||||
async openEditorWindowById(id: string) {
|
async openEditorWindowById(id: string) {
|
||||||
const window = this.editorWindowMap.get(id);
|
const window = this.editorWindowMap.get(id);
|
||||||
|
this.window?.updateState(WINDOW_STATE.inactive);
|
||||||
if (window) {
|
if (window) {
|
||||||
this.window = window;
|
this.window = window;
|
||||||
if (window.sleep) {
|
if (window.sleep) {
|
||||||
@ -222,6 +225,7 @@ export class Workspace implements IWorkspace {
|
|||||||
}
|
}
|
||||||
this.emitChangeActiveWindow();
|
this.emitChangeActiveWindow();
|
||||||
}
|
}
|
||||||
|
this.window?.updateState(WINDOW_STATE.active);
|
||||||
}
|
}
|
||||||
|
|
||||||
async openEditorWindow(name: string, title: string, options: Object, viewType?: string, sleep?: boolean) {
|
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`);
|
console.error(`${name} resourceType is not available`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.window?.updateState(WINDOW_STATE.inactive);
|
||||||
const filterWindows = this.windows.filter(d => (d.resource?.name === name && d.resource.title == title));
|
const filterWindows = this.windows.filter(d => (d.resource?.name === name && d.resource.title == title));
|
||||||
if (filterWindows && filterWindows.length) {
|
if (filterWindows && filterWindows.length) {
|
||||||
this.window = filterWindows[0];
|
this.window = filterWindows[0];
|
||||||
@ -245,6 +250,7 @@ export class Workspace implements IWorkspace {
|
|||||||
this.checkWindowQueue();
|
this.checkWindowQueue();
|
||||||
}
|
}
|
||||||
this.emitChangeActiveWindow();
|
this.emitChangeActiveWindow();
|
||||||
|
this.window?.updateState(WINDOW_STATE.active);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const resource = new Resource({
|
const resource = new Resource({
|
||||||
@ -266,6 +272,7 @@ export class Workspace implements IWorkspace {
|
|||||||
}
|
}
|
||||||
this.emitChangeWindow();
|
this.emitChangeWindow();
|
||||||
this.emitChangeActiveWindow();
|
this.emitChangeActiveWindow();
|
||||||
|
this.window?.updateState(WINDOW_STATE.active);
|
||||||
}
|
}
|
||||||
|
|
||||||
onChangeWindows(fn: () => void) {
|
onChangeWindows(fn: () => void) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user