From bf45fa26d69ead71d836db5e6763c08ffa1ac123 Mon Sep 17 00:00:00 2001 From: sunshinesmilelk <1176136681@qq.com> Date: Mon, 15 Jan 2024 23:24:57 +0800 Subject: [PATCH] fix(lab): close the open tab when delete the file --- .changeset/tasty-stingrays-jump.md | 32 +++++++++++++++++++ .../libro-jupyter/src/file/file-command.tsx | 1 + .../libro-jupyter/src/file/file-service.ts | 7 ++++ .../src/layout/saveable-tab-view.tsx | 23 ++++++++++++- 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 .changeset/tasty-stingrays-jump.md diff --git a/.changeset/tasty-stingrays-jump.md b/.changeset/tasty-stingrays-jump.md new file mode 100644 index 00000000..35429dd5 --- /dev/null +++ b/.changeset/tasty-stingrays-jump.md @@ -0,0 +1,32 @@ +--- +'@difizen/libro-jupyter': patch +'@difizen/libro-core': patch +'@difizen/libro-lab': patch +'@difizen/libro-docs': patch +'@difizen/libro-code-cell': patch +'@difizen/libro-code-editor': patch +'@difizen/libro-codemirror': patch +'@difizen/libro-cofine-editor': patch +'@difizen/libro-cofine-editor-contribution': patch +'@difizen/libro-cofine-editor-core': patch +'@difizen/libro-cofine-textmate': patch +'@difizen/libro-common': patch +'@difizen/libro-kernel': patch +'@difizen/libro-l10n': patch +'@difizen/libro-lsp': patch +'@difizen/libro-markdown': patch +'@difizen/libro-markdown-cell': patch +'@difizen/libro-output': patch +'@difizen/libro-prompt-cell': patch +'@difizen/libro-raw-cell': patch +'@difizen/libro-rendermime': patch +'@difizen/libro-search': patch +'@difizen/libro-search-code-cell': patch +'@difizen/libro-shared-model': patch +'@difizen/libro-terminal': patch +'@difizen/libro-toc': patch +'@difizen/libro-virtualized': patch +'@difizen/libro-widget': patch +--- + +1. fix:close the open tab when delete the file 2. stop propagation when focus cell right toolbar diff --git a/packages/libro-jupyter/src/file/file-command.tsx b/packages/libro-jupyter/src/file/file-command.tsx index 67b9a9f6..50cb3187 100644 --- a/packages/libro-jupyter/src/file/file-command.tsx +++ b/packages/libro-jupyter/src/file/file-command.tsx @@ -199,6 +199,7 @@ export class FileCommandContribution onOk: async () => { try { await this.fileService.delete(node.uri); + this.fileService.fileRemoveEmitter.fire(node.uri.path.toString()); } catch { message.error('删除文件失败!'); } diff --git a/packages/libro-jupyter/src/file/file-service.ts b/packages/libro-jupyter/src/file/file-service.ts index 32772cd1..dac327a4 100644 --- a/packages/libro-jupyter/src/file/file-service.ts +++ b/packages/libro-jupyter/src/file/file-service.ts @@ -7,7 +7,9 @@ import type { FileStatWithMetadata, MoveFileOptions, ResolveFileOptions, + Event as ManaEvent, } from '@difizen/mana-app'; +import { Emitter } from '@difizen/mana-app'; import { FileService, URI, inject, singleton } from '@difizen/mana-app'; import { message } from 'antd'; @@ -26,6 +28,11 @@ interface DirectoryModel extends IContentsModel { @singleton({ token: FileService }) export class JupyterFileService extends FileService { + fileRemoveEmitter: Emitter = new Emitter(); + + get onFileRemove(): ManaEvent { + return this.fileRemoveEmitter.event; + } @inject(ContentsManager) protected readonly contentsManager: ContentsManager; // '/read' // '/read-dir' diff --git a/packages/libro-lab/src/layout/saveable-tab-view.tsx b/packages/libro-lab/src/layout/saveable-tab-view.tsx index 8806bff4..63f2340e 100644 --- a/packages/libro-lab/src/layout/saveable-tab-view.tsx +++ b/packages/libro-lab/src/layout/saveable-tab-view.tsx @@ -1,5 +1,9 @@ import { CloseOutlined } from '@ant-design/icons'; -import type { View } from '@difizen/mana-app'; +import { JupyterFileService } from '@difizen/libro-jupyter'; +import type { CardTabOption, View } from '@difizen/mana-app'; +import { ViewManager, ViewOption } from '@difizen/mana-app'; +import { NavigatableView } from '@difizen/mana-app'; +import { inject } from '@difizen/mana-app'; import { CardTabView, MenuRender, @@ -15,6 +19,23 @@ import classnames from 'classnames'; @transient() @view('libro-lab-saveable-tab') export class SaveableTabView extends CardTabView { + constructor( + @inject(ViewOption) option: CardTabOption, + @inject(ViewManager) manager: ViewManager, + @inject(JupyterFileService) fileService: JupyterFileService, + ) { + super(option, manager); + fileService.onFileRemove((e) => { + const toDisposeView = this.children.find((item) => { + if (NavigatableView.is(item) && item.getResourceUri()?.path.toString() === e) { + return true; + } + return undefined; + }); + toDisposeView?.dispose(); + }); + } + protected override renderTab(item: View) { return (