Skip to content

Commit

Permalink
feat(workspace): update removeEditorWindow api
Browse files Browse the repository at this point in the history
  • Loading branch information
liujuping authored and JackLian committed Aug 23, 2023
1 parent 14d294c commit 547bbf4
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
9 changes: 9 additions & 0 deletions docs/docs/api/workspace.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,16 @@ openEditorWindowById(id: string): void;
移除视图窗口

```typescript
/**
* 移除视图窗口
* @deprecated
*/
removeEditorWindow(resourceName: string, id: string): void;

/**
* 移除视图窗口
*/
removeEditorWindow(resource: Resource): void;
```

### removeEditorWindowById
Expand Down
8 changes: 6 additions & 2 deletions packages/shell/src/api/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,12 @@ export class Workspace implements IPublicApiWorkspace {
this[workspaceSymbol].openEditorWindowById(id);
}

removeEditorWindow(resourceName: string, id: string) {
this[workspaceSymbol].removeEditorWindow(resourceName, id);
removeEditorWindow() {
if (typeof arguments[0] === 'string') {
this[workspaceSymbol].removeEditorWindow(arguments[0], arguments[1]);
} else {
this[workspaceSymbol].removeEditorWindowByResource(arguments[0]?.[resourceSymbol]);
}
}

removeEditorWindowById(id: string) {
Expand Down
10 changes: 9 additions & 1 deletion packages/types/src/shell/api/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ export interface IPublicApiWorkspace<
/** 通过视图 id 打开窗口 */
openEditorWindowById(id: string): void;

/** 移除视图窗口 */
/**
* 移除视图窗口
* @deprecated
*/
removeEditorWindow(resourceName: string, id: string): void;

/**
* 移除视图窗口
*/
removeEditorWindow(resource: Resource): void;

/** 通过视图 id 移除窗口 */
removeEditorWindowById(id: string): void;

Expand Down
21 changes: 19 additions & 2 deletions packages/workspace/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const CHANGE_EVENT = 'resource.list.change';
export interface IWorkspace extends Omit<IPublicApiWorkspace<
LowCodePluginManager,
IEditorWindow
>, 'resourceList' | 'plugins'> {
>, 'resourceList' | 'plugins' | 'openEditorWindow' | 'removeEditorWindow'> {
readonly registryInnerPlugin: (designer: IDesigner, editor: Editor, plugins: IPublicApiPlugins) => Promise<IPublicTypeDisposable>;

readonly shellModelFactory: IShellModelFactory;
Expand Down Expand Up @@ -52,6 +52,18 @@ export interface IWorkspace extends Omit<IPublicApiWorkspace<
emitChangeActiveEditorView(): void;

openEditorWindowByResource(resource: IResource, sleep: boolean): Promise<void>;

/**
* @deprecated
*/
removeEditorWindow(resourceName: string, id: string): void;

removeEditorWindowByResource(resource: IResource): void;

/**
* @deprecated
*/
openEditorWindow(name: string, title: string, options: Object, viewName?: string, sleep?: boolean): Promise<void>;
}

export class Workspace implements IWorkspace {
Expand Down Expand Up @@ -213,7 +225,12 @@ export class Workspace implements IWorkspace {
}

removeEditorWindow(resourceName: string, id: string) {
const index = this.windows.findIndex(d => (d.resource?.name === resourceName && d.title === id));
const index = this.windows.findIndex(d => (d.resource?.name === resourceName && (d.title === id || d.resource.id === id)));
this.remove(index);
}

removeEditorWindowByResource(resource: IResource) {
const index = this.windows.findIndex(d => (d.resource?.id === resource.id));
this.remove(index);
}

Expand Down

0 comments on commit 547bbf4

Please sign in to comment.