Skip to content

Commit d267fec

Browse files
liujupingJackLian
authored andcommitted
feat: add state for workspace windows
1 parent e875e33 commit d267fec

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

packages/workspace/src/window.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ export interface IEditorWindow extends Omit<IPublicModelWindow<IResource>, 'chan
2626
sleep?: boolean;
2727

2828
init(): void;
29+
30+
updateState(state: WINDOW_STATE): void;
31+
}
32+
33+
export enum WINDOW_STATE {
34+
// 睡眠
35+
sleep = 'sleep',
36+
37+
// 激活
38+
active = 'active',
39+
40+
// 未激活
41+
inactive = 'inactive',
42+
43+
// 销毁
44+
destroyed = 'destroyed'
2945
}
3046

3147
export class EditorWindow implements IEditorWindow {
@@ -51,6 +67,22 @@ export class EditorWindow implements IEditorWindow {
5167
this.title = config.title;
5268
this.icon = resource.icon;
5369
this.sleep = config.sleep;
70+
if (config.sleep) {
71+
this.updateState(WINDOW_STATE.sleep);
72+
}
73+
}
74+
75+
updateState(state: WINDOW_STATE): void {
76+
switch (state) {
77+
case WINDOW_STATE.active:
78+
this.editorView?.setActivate(true);
79+
break;
80+
case WINDOW_STATE.inactive:
81+
this.editorView?.setActivate(false);
82+
break;
83+
case WINDOW_STATE.destroyed:
84+
break;
85+
}
5486
}
5587

5688
async importSchema(schema: any) {
@@ -102,6 +134,7 @@ export class EditorWindow implements IEditorWindow {
102134
this.initReady = true;
103135
this.workspace.checkWindowQueue();
104136
this.sleep = false;
137+
this.updateState(WINDOW_STATE.active);
105138
}
106139

107140
initViewTypes = async () => {

packages/workspace/src/workspace.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { IDesigner, ILowCodePluginManager, LowCodePluginManager } from '@alilc/l
22
import { createModuleEventBus, Editor, IEditor, IEventBus, makeObservable, obx } from '@alilc/lowcode-editor-core';
33
import { IPublicApiPlugins, IPublicApiWorkspace, IPublicEnumPluginRegisterLevel, IPublicResourceList, IPublicTypeDisposable, IPublicTypeResourceType, IShellModelFactory } from '@alilc/lowcode-types';
44
import { BasicContext } from './context/base-context';
5-
import { EditorWindow } from './window';
5+
import { EditorWindow, WINDOW_STATE } from './window';
66
import type { IEditorWindow } from './window';
77
import { IResource, Resource } from './resource';
88
import { IResourceType, ResourceType } from './resource-type';
@@ -198,6 +198,7 @@ export class Workspace implements IWorkspace {
198198
}
199199
const window = this.windows[index];
200200
this.windows.splice(index, 1);
201+
this.window?.updateState(WINDOW_STATE.destroyed);
201202
if (this.window === window) {
202203
this.window = this.windows[index] || this.windows[index + 1] || this.windows[index - 1];
203204
if (this.window?.sleep) {
@@ -206,6 +207,7 @@ export class Workspace implements IWorkspace {
206207
this.emitChangeActiveWindow();
207208
}
208209
this.emitChangeWindow();
210+
this.window?.updateState(WINDOW_STATE.active);
209211
}
210212

211213
removeEditorWindow(resourceName: string, title: string) {
@@ -215,13 +217,15 @@ export class Workspace implements IWorkspace {
215217

216218
async openEditorWindowById(id: string) {
217219
const window = this.editorWindowMap.get(id);
220+
this.window?.updateState(WINDOW_STATE.inactive);
218221
if (window) {
219222
this.window = window;
220223
if (window.sleep) {
221224
await window.init();
222225
}
223226
this.emitChangeActiveWindow();
224227
}
228+
this.window?.updateState(WINDOW_STATE.active);
225229
}
226230

227231
async openEditorWindow(name: string, title: string, options: Object, viewType?: string, sleep?: boolean) {
@@ -236,6 +240,7 @@ export class Workspace implements IWorkspace {
236240
console.error(`${name} resourceType is not available`);
237241
return;
238242
}
243+
this.window?.updateState(WINDOW_STATE.inactive);
239244
const filterWindows = this.windows.filter(d => (d.resource?.name === name && d.resource.title == title));
240245
if (filterWindows && filterWindows.length) {
241246
this.window = filterWindows[0];
@@ -245,6 +250,7 @@ export class Workspace implements IWorkspace {
245250
this.checkWindowQueue();
246251
}
247252
this.emitChangeActiveWindow();
253+
this.window?.updateState(WINDOW_STATE.active);
248254
return;
249255
}
250256
const resource = new Resource({
@@ -266,6 +272,7 @@ export class Workspace implements IWorkspace {
266272
}
267273
this.emitChangeWindow();
268274
this.emitChangeActiveWindow();
275+
this.window?.updateState(WINDOW_STATE.active);
269276
}
270277

271278
onChangeWindows(fn: () => void) {

0 commit comments

Comments
 (0)