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

Method CallFunc

core/funcbutton.go:329–377  ·  view source on GitHub ↗

CallFunc calls the function associated with this button, prompting the user for any arguments.

()

Source from the content-addressed store, hash-verified

327// CallFunc calls the function associated with this button,
328// prompting the user for any arguments.
329func (fb *FuncButton) CallFunc() {
330 if !fb.reflectFunc.IsValid() {
331 return
332 }
333 ctx := fb.goodContext()
334 if len(fb.Args) == 0 {
335 if !fb.Confirm {
336 fb.callFuncShowReturns()
337 return
338 }
339 fb.confirmDialog()
340 return
341 }
342 d := NewBody().AddTitle(fb.Text).AddText(fb.Tooltip)
343 str := funcArgsToStruct(fb.Args)
344 sv := NewForm(d).SetStruct(str.Addr().Interface())
345
346 accept := func() {
347 for i := range fb.Args {
348 fb.Args[i].Value = str.Field(i).Interface()
349 }
350 fb.callFuncShowReturns()
351 }
352
353 // If there is a single value button, automatically
354 // open its dialog instead of this one
355 if len(fb.Args) == 1 {
356 sv.UpdateWidget() // need to update first
357 bt := AsButton(sv.Child(1))
358 if bt != nil {
359 bt.OnFinal(events.Change, func(e events.Event) {
360 // the dialog for the argument has been accepted, so we call the function
361 accept()
362 })
363 bt.Scene = fb.Scene // we must use this scene for context
364 bt.Send(events.Click)
365 return
366 }
367 }
368
369 d.AddBottomBar(func(parent Widget) {
370 d.AddCancel(parent)
371 d.AddOK(parent).SetText(fb.Text).OnClick(func(e events.Event) {
372 d.Close() // note: the other Close event happens too late!
373 accept()
374 })
375 })
376 d.RunDialog(ctx)
377}
378
379// funcArgsToStruct converts a slice of [FuncArg] objects
380// to a new non-pointer struct [reflect.Value].

Callers 5

InitMethod · 0.95
RenameFilesMethod · 0.80
CallFuncFunction · 0.80
makeFilesRowMethod · 0.80
MakeToolbarMethod · 0.80

Calls 15

goodContextMethod · 0.95
callFuncShowReturnsMethod · 0.95
confirmDialogMethod · 0.95
NewBodyFunction · 0.85
funcArgsToStructFunction · 0.85
NewFormFunction · 0.85
AsButtonFunction · 0.85
AddTextMethod · 0.80
AddTitleMethod · 0.80
FieldMethod · 0.80
UpdateWidgetMethod · 0.80
ChildMethod · 0.80

Tested by

no test coverage detected