MCPcopy Create free account
hub / github.com/cogentcore/core / AddCloseDialog

Method AddCloseDialog

core/widgetevents.go:129–161  ·  view source on GitHub ↗

AddCloseDialog adds a dialog that confirms that the user wants to close the Scene associated with this widget when they try to close it. It calls the given config function to configure the dialog. It is the responsibility of this config function to add the title and close button to the dialog, which

(config func(d *Body) bool)

Source from the content-addressed store, hash-verified

127// dialog. This can be used to make the dialog conditional on other things, like whether
128// something is saved.
129func (wb *WidgetBase) AddCloseDialog(config func(d *Body) bool) {
130 var inClose, canClose bool
131 wb.OnClose(func(e events.Event) {
132 if canClose {
133 return // let it close
134 }
135 if inClose {
136 e.SetHandled()
137 return
138 }
139 inClose = true
140 d := NewBody()
141 d.AddBottomBar(func(parent Widget) {
142 d.AddCancel(parent).OnClick(func(e events.Event) {
143 inClose = false
144 canClose = false
145 })
146 parent.AsWidget().SetOnChildAdded(func(n tree.Node) {
147 if bt := AsButton(n); bt != nil {
148 bt.OnFirst(events.Click, func(e events.Event) {
149 // any button click gives us permission to close
150 canClose = true
151 })
152 }
153 })
154 })
155 if !config(d) {
156 return
157 }
158 e.SetHandled()
159 d.RunDialog(wb)
160 })
161}
162
163// Send sends an new event of the given type to this widget,
164// optionally starting from values in the given original event

Callers 1

Calls 12

OnCloseMethod · 0.95
AddBottomBarMethod · 0.95
AddCancelMethod · 0.95
RunDialogMethod · 0.95
NewBodyFunction · 0.85
AsButtonFunction · 0.85
configFunction · 0.85
SetOnChildAddedMethod · 0.80
OnFirstMethod · 0.80
SetHandledMethod · 0.65
AsWidgetMethod · 0.65
OnClickMethod · 0.45

Tested by 1