Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -193,6 +195,12 @@ export class FileTreeDialogService extends Tree {
}
}

renderWarningMsg() {
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;
};
Comment thread
Ricbet marked this conversation as resolved.

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 renderWarningMsg = useCallback(() => {
if (fileService.renderWarningMsg) {
return fileService.renderWarningMsg();
} else {
return null;
}
}, [fileService.renderWarningMsg]);

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(
() => (
<>
{renderWarningMsg()}
Comment thread
xujingli marked this conversation as resolved.
Outdated
<div className={styles.file_dialog_directory}>{renderDirectorySelection()}</div>
<div className={styles.file_dialog_content}>{renderDialogTree()}</div>
</>
Expand Down