💥 ags(ask-popup): fix wrong behaviors, make AskPopupProps.onAccept prop optional
This commit is contained in:
@@ -11,7 +11,7 @@ export type AskPopupProps = {
|
|||||||
text: string | Binding<string | undefined>;
|
text: string | Binding<string | undefined>;
|
||||||
cancelText?: string;
|
cancelText?: string;
|
||||||
acceptText?: string;
|
acceptText?: string;
|
||||||
onAccept: () => void;
|
onAccept?: () => void;
|
||||||
onCancel?: () => void;
|
onCancel?: () => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -23,19 +23,22 @@ export type AskPopupProps = {
|
|||||||
* system.
|
* system.
|
||||||
*/
|
*/
|
||||||
export function AskPopup(props: AskPopupProps): Widget.Window {
|
export function AskPopup(props: AskPopupProps): Widget.Window {
|
||||||
|
let accepted: boolean = false;
|
||||||
|
|
||||||
const buttons = [
|
const buttons = [
|
||||||
new Widget.Button({
|
new Widget.Button({
|
||||||
className: "cancel",
|
className: "cancel",
|
||||||
hexpand: true,
|
hexpand: true,
|
||||||
label: props.cancelText || tr("ask_popup.options.cancel") || "Cancel",
|
label: props.cancelText ?? tr("cancel"),
|
||||||
onClick: () => window.close(),
|
onClick: () => window.close(),
|
||||||
} as Widget.ButtonProps),
|
} as Widget.ButtonProps),
|
||||||
new Widget.Button({
|
new Widget.Button({
|
||||||
className: "accept",
|
className: "accept",
|
||||||
hexpand: true,
|
hexpand: true,
|
||||||
label: props.acceptText || tr("ask_popup.options.accept") || "Ok",
|
label: props.acceptText ?? tr("accept"),
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
window.close();
|
window.close();
|
||||||
|
accepted = true;
|
||||||
props.onAccept?.();
|
props.onAccept?.();
|
||||||
}
|
}
|
||||||
} as Widget.ButtonProps)
|
} as Widget.ButtonProps)
|
||||||
@@ -50,7 +53,7 @@ export function AskPopup(props: AskPopupProps): Widget.Window {
|
|||||||
layer: Astal.Layer.OVERLAY,
|
layer: Astal.Layer.OVERLAY,
|
||||||
widthRequest: 400,
|
widthRequest: 400,
|
||||||
heightRequest: 220,
|
heightRequest: 220,
|
||||||
onDestroy: () => props.onCancel?.(),
|
onDestroy: () => !accepted && props.onCancel?.(),
|
||||||
child: new Widget.Box({
|
child: new Widget.Box({
|
||||||
className: "ask-popup-box",
|
className: "ask-popup-box",
|
||||||
orientation: Gtk.Orientation.VERTICAL,
|
orientation: Gtk.Orientation.VERTICAL,
|
||||||
|
|||||||
Reference in New Issue
Block a user