дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
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
41 рядки
1.4 KiB
TypeScript
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;
|
|
}
|