import { Astal, Gtk } from "ags/gtk4"; import { Windows } from "../windows"; import { getPopupWindowContainer, PopupWindow } from "./PopupWindow"; import { Separator } from "./Separator"; import { tr } from "../i18n/intl"; import { Accessor, Node } from "ags"; import { transformWidget, variableToBoolean } from "../modules/utils"; export type CustomDialogProps = { namespace?: string | Accessor; className?: string | Accessor; cssBackground?: string; title?: string | Accessor; text?: string | Accessor; heightRequest?: number | Accessor; widthRequest?: number | Accessor; childOrientation?: Gtk.Orientation | Accessor; children?: Node; onFinish?: () => void; options?: Array | Accessor>; optionsOrientation?: Gtk.Orientation | Accessor; }; export interface CustomDialogOption { onClick?: () => void; text: string | Accessor; closeOnClick?: boolean | Accessor; } function CustomDialogOption({closeOnClick = true, ...props}: CustomDialogOption & { dialog: Astal.Window; }) { return { props.onClick?.(); closeOnClick && props.dialog?.close(); }} /> } export function CustomDialog({ options = [{ text: tr("accept") }], ...props}: CustomDialogProps) { return Windows.getDefault().createWindowForFocusedMonitor((mon) => { const popup = props.onFinish?.()} widthRequest={props.widthRequest ?? 400} heightRequest={props.heightRequest ?? 220}> {transformWidget(props.children, (child) => child as JSX.Element)} 0} spacing={8} orientation={Gtk.Orientation.VERTICAL} /> as Astal.Window; (popup.get_child()!.get_first_child()!.get_first_child() as Gtk.Box).append( {transformWidget(options, (props) => )} as Gtk.Box ); return popup; })(); } export function getContainerCustomDialog(dialog: Astal.Window): Gtk.Box { return getPopupWindowContainer(dialog).get_first_child()?.get_last_child()?.get_prev_sibling() as Gtk.Box; }