MCPcopy
hub / github.com/lxn/walk / PresentError

Method PresentError

tooltiperrorpresenter.go:62–119  ·  view source on GitHub ↗
(err error, widget Widget)

Source from the content-addressed store, hash-verified

60}
61
62func (ttep *ToolTipErrorPresenter) PresentError(err error, widget Widget) {
63 if ttep.toolTip == nil {
64 return
65 }
66
67 if err == nil && widget == ttep.curWidget {
68 ttep.untrack()
69 }
70
71 if err == nil {
72 ttep.toolTip.RemoveTool(widget)
73 delete(ttep.widget2error, widget)
74 } else {
75 ttep.toolTip.addTrackedTool(widget)
76 ttep.widget2error[widget] = err
77 }
78
79 var found bool
80 if widget != nil {
81 walkDescendants(widget.Form().AsFormBase().clientComposite, func(w Window) bool {
82 wt := w.(Widget)
83
84 if !found {
85 if e, ok := ttep.widget2error[wt]; ok {
86 err, widget, found = e, wt, true
87 }
88 }
89
90 if !found && wt == ttep.curWidget || wt != widget || err == nil {
91 wt.GraphicsEffects().Remove(ValidationErrorEffect)
92 }
93
94 return true
95 })
96 }
97
98 if found {
99 if widget != ttep.curWidget {
100 ttep.untrack()
101 }
102
103 if ve, ok := err.(*ValidationError); ok {
104 ttep.toolTip.SetErrorTitle(ve.title)
105 ttep.toolTip.SetText(widget, ve.message)
106 } else {
107 ttep.toolTip.SetErrorTitle(tr("Invalid Input"))
108 ttep.toolTip.SetText(widget, err.Error())
109 }
110
111 if widget != ttep.curWidget {
112 ttep.track(widget)
113
114 if effects := widget.GraphicsEffects(); !effects.Contains(ValidationErrorEffect) {
115 effects.Add(ValidationErrorEffect)
116 }
117 }
118 }
119}

Callers

nothing calls this directly

Calls 15

untrackMethod · 0.95
trackMethod · 0.95
walkDescendantsFunction · 0.85
RemoveToolMethod · 0.80
addTrackedToolMethod · 0.80
SetErrorTitleMethod · 0.80
trFunction · 0.70
AsFormBaseMethod · 0.65
FormMethod · 0.65
RemoveMethod · 0.65
GraphicsEffectsMethod · 0.65
SetTextMethod · 0.45

Tested by

no test coverage detected