diff --git a/pkg/gui/popup/popup_handler.go b/pkg/gui/popup/popup_handler.go index 7fe77a8da..d8ce654b4 100644 --- a/pkg/gui/popup/popup_handler.go +++ b/pkg/gui/popup/popup_handler.go @@ -115,6 +115,20 @@ func (self *PopupHandler) Confirm(opts types.ConfirmOpts) { }) } +func (self *PopupHandler) ConfirmIf(condition bool, opts types.ConfirmOpts) error { + if condition { + self.createPopupPanelFn(context.Background(), types.CreatePopupPanelOpts{ + Title: opts.Title, + Prompt: opts.Prompt, + HandleConfirm: opts.HandleConfirm, + HandleClose: opts.HandleClose, + }) + return nil + } + + return opts.HandleConfirm() +} + func (self *PopupHandler) Prompt(opts types.PromptOpts) { self.createPopupPanelFn(context.Background(), types.CreatePopupPanelOpts{ Title: opts.Title, diff --git a/pkg/gui/types/common.go b/pkg/gui/types/common.go index fb472ab24..bf7267a8c 100644 --- a/pkg/gui/types/common.go +++ b/pkg/gui/types/common.go @@ -126,6 +126,8 @@ type IPopupHandler interface { Alert(title string, message string) // Shows a popup asking the user for confirmation. Confirm(opts ConfirmOpts) + // Shows a popup asking the user for confirmation if condition is true; otherwise, the HandleConfirm function is called directly. + ConfirmIf(condition bool, opts ConfirmOpts) error // Shows a popup prompting the user for input. Prompt(opts PromptOpts) WithWaitingStatus(message string, f func(gocui.Task) error) error