Skip to content

Commit 38c2498

Browse files
committed
fix: allow external modification of file selection
1 parent 92e7bca commit 38c2498

2 files changed

Lines changed: 36 additions & 2 deletions

File tree

packages/file-tree-next/src/browser/dialog/file-dialog.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export class FileTreeDialogService extends Tree {
4747

4848
public _whenReady: Promise<void>;
4949

50+
showFilePathSearch: boolean;
51+
5052
constructor(@Optional() root: string) {
5153
super();
5254
this._whenReady = this.resolveWorkspaceRoot(root);
@@ -193,6 +195,12 @@ export class FileTreeDialogService extends Tree {
193195
}
194196
}
195197

198+
renderWarningMsg() {
199+
return null;
200+
}
201+
202+
getDefaultFilePath(defaultPath: string) { return defaultPath; }
203+
196204
dispose() {
197205
super.dispose();
198206
}

packages/file-tree-next/src/browser/dialog/file-dialog.view.tsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ export const FileDialog = ({
9595
fileService.contextKey.fileDialogViewVisibleContext.set(false);
9696
}, [isReady, dialogService, model, fileName, options]);
9797

98+
const getDefaultPath = (model) => {
99+
let defaultPath = (model.treeModel.root as Directory).uri.codeUri.fsPath;
100+
101+
if (fileService.getDefaultFilePath) {
102+
defaultPath = fileService.getDefaultFilePath(defaultPath);
103+
}
104+
105+
return defaultPath;
106+
};
107+
98108
const close = useCallback(() => {
99109
setIsReady(false);
100110
dialogService.hide();
@@ -106,7 +116,9 @@ export const FileDialog = ({
106116
// 确保数据初始化完毕,减少初始化数据过程中多次刷新视图
107117
// 这里需要重新取一下treeModel的值确保为最新的TreeModel
108118
await model.treeModel.ensureReady;
109-
setSelectPath((model.treeModel.root as Directory).uri.codeUri.fsPath);
119+
const path = getDefaultPath(model);
120+
121+
setSelectPath(path);
110122
setIsReady(true);
111123
}, [model, selectPath, isReady]);
112124

@@ -211,6 +223,14 @@ export const FileDialog = ({
211223
[model, isReady, selectPath, directoryList],
212224
);
213225

226+
const renderWarningMsg = useCallback(() => {
227+
if (fileService.renderWarningMsg) {
228+
return fileService.renderWarningMsg();
229+
} else {
230+
return null;
231+
}
232+
}, [fileService.renderWarningMsg]);
233+
214234
const renderDialogTreeNode = useCallback(
215235
(props: INodeRendererProps) => (
216236
<FileTreeDialogNode
@@ -244,6 +264,11 @@ export const FileDialog = ({
244264
}
245265
}, [isReady, model]);
246266

267+
const showFilePathSearch = useMemo(
268+
() => (fileService.showFilePathSearch === false ? false : true),
269+
[fileService.showFilePathSearch],
270+
);
271+
247272
const renderDirectorySelection = useCallback(() => {
248273
if (directoryList.length > 0) {
249274
return (
@@ -254,7 +279,7 @@ export const FileDialog = ({
254279
size='large'
255280
searchPlaceholder={selectPath}
256281
value={selectPath}
257-
showSearch={true}
282+
showSearch={showFilePathSearch}
258283
>
259284
{directoryList.map((item, idx) => (
260285
<Option value={item} key={`${idx} - ${item}`}>
@@ -291,6 +316,7 @@ export const FileDialog = ({
291316
const DialogContent = useMemo(
292317
() => (
293318
<>
319+
{renderWarningMsg()}
294320
<div className={styles.file_dialog_directory}>{renderDirectorySelection()}</div>
295321
<div className={styles.file_dialog_content}>{renderDialogTree()}</div>
296322
</>

0 commit comments

Comments
 (0)