Файли
openidea/src/platform/desktopFiles.ts
T
LU XIANGRUIтаwildcatDownstairs 979cce1175 feat(python): show matplotlib figures in a Plots tool window (#6529)
Python runs, debug sessions and the Python Console get MPLBACKEND pointing at a small bundled Agg backend (unless the run or the environment already sets it). plt.show() saves each open figure as a PNG in the project's cache folder; a watcher sends PlotAdded and the Plots tool window lists the figures with thumbnails, the image viewer, save, copy and delete. Settings > Python > Plots turns it off.

Closes #6514

Co-authored-by: wildcatDownstairs <[email protected]>
2026-11-27 23:53:40 +08:00

29 рядки
1.2 KiB
TypeScript

import { toBase64 } from "./base64";
import { call, callDesktop, commands, isErrorKind } from "./ipc";
import { isRemoteWindow } from "./remote";
/** Text selected in the desktop's file dialog, including in a remote window. */
export function readDesktopText(path: string): Promise<string> {
return isRemoteWindow() ? callDesktop<string>("fs_read_text", { path }) : call(commands.fsReadText(path));
}
/** Write UTF-8 to a path already confirmed in the desktop's save dialog. */
export function writeDesktopText(path: string, text: string): Promise<void> {
return writeDesktopBase64(path, toBase64(new TextEncoder().encode(text)));
}
/** Write base64-encoded bytes to a path already confirmed in the desktop's save dialog. */
export async function writeDesktopBase64(path: string, data: string): Promise<void> {
if (!isRemoteWindow()) {
await call(commands.fsDelete(path)).catch(() => {});
await call(commands.fsCreateFileBytes(path, data));
return;
}
const kind = await callDesktop<string>("fs_entry_kind", { path }).catch((e: unknown) => {
if (!isErrorKind(e, "notFound")) throw e;
return null;
});
if (kind === "file") await callDesktop("fs_delete", { path });
await callDesktop("fs_create_file_bytes", { path, data });
}