import { Astal, Gtk } from "ags/gtk4"; import { Windows } from "../windows"; import { PopupWindow } from "./PopupWindow"; import { Separator } from "./Separator"; import { tr } from "../i18n/intl"; import { Accessor } from "ags"; import { transformWidget, variableToBoolean, WidgetNodeType } from "../scripts/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?: WidgetNodeType; 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; })(); }