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: support file dialog renderCustomMsg #4352

Merged
merged 2 commits into from
Feb 13, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export class FileTreeDialogService extends Tree {

public _whenReady: Promise<void>;

showFilePathSearch: boolean;

constructor(@Optional() root: string) {
super();
this._whenReady = this.resolveWorkspaceRoot(root);
Expand Down Expand Up @@ -175,7 +177,7 @@ export class FileTreeDialogService extends Tree {
async createFile(options: { oldFilePath: string; newFilePath: string }) {
try {
const { oldFilePath, newFilePath } = options;
let fileStat = await this.fileServiceClient.getFileStat(oldFilePath);
const fileStat = await this.fileServiceClient.getFileStat(oldFilePath);

if (!fileStat) {
throw new Error(`Source file not found: ${oldFilePath}`);
Expand All @@ -193,6 +195,14 @@ export class FileTreeDialogService extends Tree {
}
}

renderCustomMsg() {
return null;
}

getDefaultFilePath(defaultPath: string) {
return defaultPath;
}

dispose() {
super.dispose();
}
Expand Down
30 changes: 28 additions & 2 deletions packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ export const FileDialog = ({
fileService.contextKey.fileDialogViewVisibleContext.set(false);
}, [isReady, dialogService, model, fileName, options]);

const getDefaultPath = (model) => {
let defaultPath = (model.treeModel.root as Directory).uri.codeUri.fsPath;

if (fileService.getDefaultFilePath) {
defaultPath = fileService.getDefaultFilePath(defaultPath);
}

return defaultPath;
};

const close = useCallback(() => {
setIsReady(false);
dialogService.hide();
Expand All @@ -106,7 +116,9 @@ export const FileDialog = ({
// 确保数据初始化完毕,减少初始化数据过程中多次刷新视图
// 这里需要重新取一下treeModel的值确保为最新的TreeModel
await model.treeModel.ensureReady;
setSelectPath((model.treeModel.root as Directory).uri.codeUri.fsPath);
const path = getDefaultPath(model);

setSelectPath(path);
setIsReady(true);
}, [model, selectPath, isReady]);

Expand Down Expand Up @@ -211,6 +223,14 @@ export const FileDialog = ({
[model, isReady, selectPath, directoryList],
);

const renderCustomMsg = useCallback(() => {
if (fileService.renderCustomMsg) {
return fileService.renderCustomMsg();
} else {
return null;
}
}, [fileService.renderCustomMsg]);

const renderDialogTreeNode = useCallback(
(props: INodeRendererProps) => (
<FileTreeDialogNode
Expand Down Expand Up @@ -244,6 +264,11 @@ export const FileDialog = ({
}
}, [isReady, model]);

const showFilePathSearch = useMemo(
() => (fileService.showFilePathSearch === false ? false : true),
[fileService.showFilePathSearch],
);

const renderDirectorySelection = useCallback(() => {
if (directoryList.length > 0) {
return (
Expand All @@ -254,7 +279,7 @@ export const FileDialog = ({
size='large'
searchPlaceholder={selectPath}
value={selectPath}
showSearch={true}
showSearch={showFilePathSearch}
>
{directoryList.map((item, idx) => (
<Option value={item} key={`${idx} - ${item}`}>
Expand Down Expand Up @@ -291,6 +316,7 @@ export const FileDialog = ({
const DialogContent = useMemo(
() => (
<>
{renderCustomMsg()}
<div className={styles.file_dialog_directory}>{renderDirectorySelection()}</div>
<div className={styles.file_dialog_content}>{renderDialogTree()}</div>
</>
Expand Down
Loading