дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
When a drag from the Project view leaves the window it becomes an OS file drag (copy only) of the selected local files and folders: AppKit dragging session on macOS, OLE CF_HDROP on Windows, GTK on Linux, in the new ide-drag-out crate behind the window_drag_files command. A drop back on the window itself is ignored, and remote projects keep the in-window drag only. Closes #2867 Co-authored-by: bertyhell <[email protected]>
48 рядки
1.6 KiB
TypeScript
48 рядки
1.6 KiB
TypeScript
/**
|
|
* Files dragged out of the window become an OS file drag, so the app they are dropped
|
|
* on (Explorer, Finder, an SFTP client) copies them, as from IDEA's Project view (#2867).
|
|
* Only a local project's files: a remote project's live on its server.
|
|
*/
|
|
import { call, commands, isTauri } from "./ipc";
|
|
import { isRemoteWindow } from "./remote";
|
|
|
|
/** The running drag, until it ends or the next press shows none is live. */
|
|
let running: object | null = null;
|
|
const pressed = () => {
|
|
running = null;
|
|
};
|
|
|
|
/** Whether files can be dragged out of this window. */
|
|
export function canDragOut(): boolean {
|
|
return isTauri() && !isRemoteWindow();
|
|
}
|
|
|
|
/**
|
|
* Hands `paths` to an OS drag; call while the primary button is held, once the pointer
|
|
* left the window. Resolves when the drag ends: true when another app took the files.
|
|
*/
|
|
export async function dragOut(paths: readonly string[]): Promise<boolean> {
|
|
const drag = {};
|
|
running = drag;
|
|
// A backend that loses the drag never resolves; a fresh press means it is over anyway.
|
|
window.addEventListener("pointerdown", pressed, true);
|
|
try {
|
|
return await call(commands.windowDragFiles([...paths]));
|
|
} catch (e) {
|
|
console.warn("could not drag files out", e);
|
|
return false;
|
|
} finally {
|
|
if (running === drag) running = null;
|
|
window.removeEventListener("pointerdown", pressed, true);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Whether a drag out of this window is running. An OS file drop meanwhile is the
|
|
* dragged files coming back, which the window ignores instead of importing or
|
|
* opening its own files.
|
|
*/
|
|
export function isDraggingOut(): boolean {
|
|
return running !== null;
|
|
}
|