Skip to content

Commit 547bbf4

Browse files
liujupingJackLian
authored andcommitted
feat(workspace): update removeEditorWindow api
1 parent 14d294c commit 547bbf4

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

docs/docs/api/workspace.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,16 @@ openEditorWindowById(id: string): void;
107107
移除视图窗口
108108

109109
```typescript
110+
/**
111+
* 移除视图窗口
112+
* @deprecated
113+
*/
110114
removeEditorWindow(resourceName: string, id: string): void;
115+
116+
/**
117+
* 移除视图窗口
118+
*/
119+
removeEditorWindow(resource: Resource): void;
111120
```
112121

113122
### removeEditorWindowById

packages/shell/src/api/workspace.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,12 @@ export class Workspace implements IPublicApiWorkspace {
7676
this[workspaceSymbol].openEditorWindowById(id);
7777
}
7878

79-
removeEditorWindow(resourceName: string, id: string) {
80-
this[workspaceSymbol].removeEditorWindow(resourceName, id);
79+
removeEditorWindow() {
80+
if (typeof arguments[0] === 'string') {
81+
this[workspaceSymbol].removeEditorWindow(arguments[0], arguments[1]);
82+
} else {
83+
this[workspaceSymbol].removeEditorWindowByResource(arguments[0]?.[resourceSymbol]);
84+
}
8185
}
8286

8387
removeEditorWindowById(id: string) {

packages/types/src/shell/api/workspace.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,17 @@ export interface IPublicApiWorkspace<
4242
/** 通过视图 id 打开窗口 */
4343
openEditorWindowById(id: string): void;
4444

45-
/** 移除视图窗口 */
45+
/**
46+
* 移除视图窗口
47+
* @deprecated
48+
*/
4649
removeEditorWindow(resourceName: string, id: string): void;
4750

51+
/**
52+
* 移除视图窗口
53+
*/
54+
removeEditorWindow(resource: Resource): void;
55+
4856
/** 通过视图 id 移除窗口 */
4957
removeEditorWindowById(id: string): void;
5058

packages/workspace/src/workspace.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const CHANGE_EVENT = 'resource.list.change';
2222
export interface IWorkspace extends Omit<IPublicApiWorkspace<
2323
LowCodePluginManager,
2424
IEditorWindow
25-
>, 'resourceList' | 'plugins'> {
25+
>, 'resourceList' | 'plugins' | 'openEditorWindow' | 'removeEditorWindow'> {
2626
readonly registryInnerPlugin: (designer: IDesigner, editor: Editor, plugins: IPublicApiPlugins) => Promise<IPublicTypeDisposable>;
2727

2828
readonly shellModelFactory: IShellModelFactory;
@@ -52,6 +52,18 @@ export interface IWorkspace extends Omit<IPublicApiWorkspace<
5252
emitChangeActiveEditorView(): void;
5353

5454
openEditorWindowByResource(resource: IResource, sleep: boolean): Promise<void>;
55+
56+
/**
57+
* @deprecated
58+
*/
59+
removeEditorWindow(resourceName: string, id: string): void;
60+
61+
removeEditorWindowByResource(resource: IResource): void;
62+
63+
/**
64+
* @deprecated
65+
*/
66+
openEditorWindow(name: string, title: string, options: Object, viewName?: string, sleep?: boolean): Promise<void>;
5567
}
5668

5769
export class Workspace implements IWorkspace {
@@ -213,7 +225,12 @@ export class Workspace implements IWorkspace {
213225
}
214226

215227
removeEditorWindow(resourceName: string, id: string) {
216-
const index = this.windows.findIndex(d => (d.resource?.name === resourceName && d.title === id));
228+
const index = this.windows.findIndex(d => (d.resource?.name === resourceName && (d.title === id || d.resource.id === id)));
229+
this.remove(index);
230+
}
231+
232+
removeEditorWindowByResource(resource: IResource) {
233+
const index = this.windows.findIndex(d => (d.resource?.id === resource.id));
217234
this.remove(index);
218235
}
219236

0 commit comments

Comments
 (0)