Файли
openidea/src/platform/choosePath.ts
T
l0ng-ai 25d6e8ac7c fix(remote): browse the remote host when a setting asks for a path (#3920)
In a remote window, choosePath (Project Structure libraries, SDK homes, interpreters and the other settings that pick a file or folder) opened the desktop's own dialog, so it listed this machine's files while the path is used on the remote host. It now opens an in-app chooser that lists the host's folders through fs_read_dir: click selects, double click or Enter opens a folder or chooses the file, the arrow goes to the parent folder, and the path can be typed. Local windows keep the desktop dialog. Refs #3447
2026-11-17 14:48:50 +08:00

41 рядки
1.4 KiB
TypeScript

import { isTauri } from "@/platform/ipc";
import { isRemoteWindow } from "@/platform/remote";
export interface ChoosePathOptions {
directory: boolean;
title: string;
defaultPath?: string;
}
type HostChooser = (opts: ChoosePathOptions) => Promise<string | null>;
let hostChooser: HostChooser | null = null;
/**
* Registers the in-app chooser that browses the remote host (the workbench's, in `inputDialogs`):
* the desktop's own dialog would show this machine's files.
*/
export function registerHostPathChooser(chooser: HostChooser): () => void {
hostChooser = chooser;
return () => {
if (hostChooser === chooser) hostChooser = null;
};
}
/**
* File / folder chooser for a path on the host this window's commands run on: the desktop's dialog
* locally, the in-app chooser in a remote window. Null when cancelled or outside Tauri.
*/
export async function choosePath(opts: ChoosePathOptions): Promise<string | null> {
if (!isTauri()) return null;
if (isRemoteWindow() && hostChooser) return hostChooser(opts);
// Lazy on purpose: loading platform/dialog starts its GTK capability probe at module load.
const { open } = await import("@/platform/dialog");
const picked = await open({
directory: opts.directory,
multiple: false,
title: opts.title,
defaultPath: opts.defaultPath || undefined,
});
return (Array.isArray(picked) ? picked[0] : picked) ?? null;
}