Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jupyter): open file after creation #107

Merged
merged 2 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .changeset/gorgeous-hats-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
"@difizen/libro-cofine-editor-contribution": patch
"@difizen/libro-cofine-editor-core": patch
"@difizen/libro-search-code-cell": patch
"@difizen/libro-cofine-textmate": patch
"@difizen/libro-language-client": patch
"@difizen/libro-cofine-editor": patch
"@difizen/libro-markdown-cell": patch
"@difizen/libro-shared-model": patch
"@difizen/libro-code-editor": patch
"@difizen/libro-prompt-cell": patch
"@difizen/libro-virtualized": patch
"@difizen/libro-codemirror": patch
"@difizen/libro-rendermime": patch
"@difizen/libro-code-cell": patch
"@difizen/libro-markdown": patch
"@difizen/libro-raw-cell": patch
"@difizen/libro-terminal": patch
"@difizen/libro-jupyter": patch
"@difizen/libro-common": patch
"@difizen/libro-kernel": patch
"@difizen/libro-output": patch
"@difizen/libro-search": patch
"@difizen/libro-widget": patch
"@difizen/libro-core": patch
"@difizen/libro-l10n": patch
"@difizen/libro-lab": patch
"@difizen/libro-lsp": patch
"@difizen/libro-toc": patch
"@difizen/libro-docs": patch
---

Lab: open file after creation
11 changes: 10 additions & 1 deletion packages/libro-jupyter/src/file/file-create-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { ModalItemProps, ModalItem } from '@difizen/mana-app';
import { CommandRegistry } from '@difizen/mana-app';
import { URI, useInject, ViewManager } from '@difizen/mana-app';
import { Col, Form, message, Row, Input, Modal } from 'antd';
import type { InputRef } from 'antd';
Expand Down Expand Up @@ -27,6 +28,7 @@ export const FileCreateModalComponent: React.FC<ModalItemProps<ModalItemType>> =
data,
}: ModalItemProps<ModalItemType>) => {
const fileService = useInject(JupyterFileService);
const commands = useInject(CommandRegistry);
const viewManager = useInject(ViewManager);
const [fileType, setFileType] = useState<FileType>(data?.fileType);
const [fileView, setFileView] = useState<FileView>();
Expand All @@ -37,13 +39,20 @@ export const FileCreateModalComponent: React.FC<ModalItemProps<ModalItemType>> =
await form.validateFields();
close();
try {
await fileService.newFile(
const stat = await fileService.newFile(
values.fileName + (fileType || ''),
new URI(data?.path),
);
if (fileView) {
fileView.model.refresh();
}
if (stat.isFile) {
commands.executeCommand('fileTree.command.openfile', {
fileStat: stat,
uri: stat.resource,
});
}
// message.success('新建文件成功');
} catch {
message.error('新建文件失败');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/libro-jupyter/src/file/file-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ export class JupyterFileService extends FileService {
ext,
});
await this.rename(new URI(res.path.toString()), fileName);
return this.resolve(target);
return this.resolve(targetFileUri);
}

async newFileDir(dirName: string, target: URI): Promise<FileStatWithMetadata> {
Expand Down
1 change: 1 addition & 0 deletions packages/libro-jupyter/src/file/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './file-protocol.js';
export * from './file-icon.js';
export * from './file-create-modal.js';
export * from './file-createdir-modal.js';
export * from './file-command.js';
Loading