Skip to content

Commit 22d2fdd

Browse files
liujupingJackLian
authored andcommitted
feat: workspace add onChangeActiveWindow event api
1 parent 8ac68b9 commit 22d2fdd

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

packages/shell/src/api/workspace.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,8 @@ export class Workspace implements IPublicApiWorkspace {
7373
onChangeActiveWindow(fn: () => void): IPublicTypeDisposable {
7474
return this[workspaceSymbol].onChangeActiveWindow(fn);
7575
}
76+
77+
onChangeActiveEditorView(fn: () => void): IPublicTypeDisposable {
78+
return this[workspaceSymbol].onChangeActiveEditorView(fn);
79+
}
7680
}

packages/shell/src/model/editor-view.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class EditorView {
1010
constructor(editorView: IViewContext) {
1111
this[editorViewSymbol] = editorView;
1212
this[pluginContextSymbol] = this[editorViewSymbol].innerPlugins._getLowCodePluginContext({
13-
pluginName: '',
13+
pluginName: editorView.editorWindow + editorView.viewName,
1414
});
1515
}
1616

packages/workspace/src/window.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { createModuleEventBus, IEventBus, makeObservable, obx } from '@alilc/low
33
import { Context, IViewContext } from './context/view-context';
44
import { IWorkspace } from './workspace';
55
import { IResource } from './resource';
6-
import { IPublicTypeDisposable } from '../../types/es/shell/type/disposable';
7-
import { IPublicModelWindow } from '@alilc/lowcode-types';
6+
import { IPublicModelWindow, IPublicTypeDisposable } from '@alilc/lowcode-types';
87

98
interface IWindowCOnfig {
109
title: string | undefined;
@@ -158,6 +157,10 @@ export class EditorWindow implements IEditorWindow {
158157

159158
if (!ignoreEmit) {
160159
this.emitter.emit('window.change.view.type', name);
160+
161+
if (this.id === this.workspace.window.id) {
162+
this.workspace.emitChangeActiveEditorView();
163+
}
161164
}
162165
this.editorView.setActivate(true);
163166
};

packages/workspace/src/workspace.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ enum EVENT {
1313
CHANGE_ACTIVE_WINDOW = 'change_active_window',
1414

1515
WINDOW_RENDER_READY = 'window_render_ready',
16+
17+
CHANGE_ACTIVE_EDITOR_VIEW = 'change_active_editor_view',
1618
}
1719

1820
const CHANGE_EVENT = 'resource.list.change';
@@ -42,6 +44,10 @@ export interface IWorkspace extends Omit<IPublicApiWorkspace<
4244
initWindow(): void;
4345

4446
setActive(active: boolean): void;
47+
48+
onChangeActiveEditorView(fn: () => void): IPublicTypeDisposable;
49+
50+
emitChangeActiveEditorView(): void;
4551
}
4652

4753
export class Workspace implements IWorkspace {
@@ -258,12 +264,24 @@ export class Workspace implements IWorkspace {
258264
};
259265
}
260266

267+
onChangeActiveEditorView(fn: () => void) {
268+
this.emitter.on(EVENT.CHANGE_ACTIVE_EDITOR_VIEW, fn);
269+
return () => {
270+
this.emitter.removeListener(EVENT.CHANGE_ACTIVE_EDITOR_VIEW, fn);
271+
};
272+
}
273+
274+
emitChangeActiveEditorView() {
275+
this.emitter.emit(EVENT.CHANGE_ACTIVE_EDITOR_VIEW);
276+
}
277+
261278
emitChangeWindow() {
262279
this.emitter.emit(EVENT.CHANGE_WINDOW);
263280
}
264281

265282
emitChangeActiveWindow() {
266283
this.emitter.emit(EVENT.CHANGE_ACTIVE_WINDOW);
284+
this.emitChangeActiveEditorView();
267285
}
268286

269287
onChangeActiveWindow(fn: () => void) {

0 commit comments

Comments
 (0)