Skip to content

Commit

Permalink
fix(lab): close the open tab when delete the file
Browse files Browse the repository at this point in the history
  • Loading branch information
sunshinesmilelk authored and BroKun committed Jan 16, 2024
1 parent ad58473 commit bf45fa2
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
32 changes: 32 additions & 0 deletions .changeset/tasty-stingrays-jump.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions packages/libro-jupyter/src/file/file-command.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('删除文件失败!');
}
Expand Down
7 changes: 7 additions & 0 deletions packages/libro-jupyter/src/file/file-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -26,6 +28,11 @@ interface DirectoryModel extends IContentsModel {

@singleton({ token: FileService })
export class JupyterFileService extends FileService {
fileRemoveEmitter: Emitter<string> = new Emitter<string>();

get onFileRemove(): ManaEvent<string> {
return this.fileRemoveEmitter.event;
}
@inject(ContentsManager) protected readonly contentsManager: ContentsManager;
// '/read'
// '/read-dir'
Expand Down
23 changes: 22 additions & 1 deletion packages/libro-lab/src/layout/saveable-tab-view.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 (
<ViewContext view={item}>
Expand Down

0 comments on commit bf45fa2

Please sign in to comment.