Skip to content

Commit 12df9d2

Browse files
committed
Assert that only one controller can set click or render functions on a BaseContext
The rationale for this is the same as in the previous commit; however, for these functions we only allow a single controller to set them, because they are event handlers and it doesn't make sense for multiple controllers to handle them.
1 parent 4dfa4e8 commit 12df9d2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pkg/gui/context/base_context.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,16 +140,25 @@ func (self *BaseContext) ClearAllAttachedControllerFunctions() {
140140
self.mouseKeybindingsFns = nil
141141
self.onFocusFns = nil
142142
self.onFocusLostFns = nil
143+
self.onClickFn = nil
144+
self.onClickFocusedMainViewFn = nil
145+
self.onRenderToMainFn = nil
143146
}
144147

145148
func (self *BaseContext) AddOnClickFn(fn func() error) {
146149
if fn != nil {
150+
if self.onClickFn != nil {
151+
panic("only one controller is allowed to set an onClickFn")
152+
}
147153
self.onClickFn = fn
148154
}
149155
}
150156

151157
func (self *BaseContext) AddOnClickFocusedMainViewFn(fn onClickFocusedMainViewFn) {
152158
if fn != nil {
159+
if self.onClickFocusedMainViewFn != nil {
160+
panic("only one controller is allowed to set an onClickFocusedMainViewFn")
161+
}
153162
self.onClickFocusedMainViewFn = fn
154163
}
155164
}
@@ -164,6 +173,9 @@ func (self *BaseContext) GetOnClickFocusedMainView() onClickFocusedMainViewFn {
164173

165174
func (self *BaseContext) AddOnRenderToMainFn(fn func()) {
166175
if fn != nil {
176+
if self.onRenderToMainFn != nil {
177+
panic("only one controller is allowed to set an onRenderToMainFn")
178+
}
167179
self.onRenderToMainFn = fn
168180
}
169181
}

0 commit comments

Comments
 (0)