From 12df9d2b42d426cb6121a821e081f46cb70a3268 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 10 Jul 2025 19:45:04 +0200 Subject: [PATCH] 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. --- pkg/gui/context/base_context.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/gui/context/base_context.go b/pkg/gui/context/base_context.go index b254d043d..7c6e9b617 100644 --- a/pkg/gui/context/base_context.go +++ b/pkg/gui/context/base_context.go @@ -140,16 +140,25 @@ func (self *BaseContext) ClearAllAttachedControllerFunctions() { self.mouseKeybindingsFns = nil self.onFocusFns = nil self.onFocusLostFns = nil + self.onClickFn = nil + self.onClickFocusedMainViewFn = nil + self.onRenderToMainFn = nil } func (self *BaseContext) AddOnClickFn(fn func() error) { if fn != nil { + if self.onClickFn != nil { + panic("only one controller is allowed to set an onClickFn") + } self.onClickFn = fn } } func (self *BaseContext) AddOnClickFocusedMainViewFn(fn onClickFocusedMainViewFn) { if fn != nil { + if self.onClickFocusedMainViewFn != nil { + panic("only one controller is allowed to set an onClickFocusedMainViewFn") + } self.onClickFocusedMainViewFn = fn } } @@ -164,6 +173,9 @@ func (self *BaseContext) GetOnClickFocusedMainView() onClickFocusedMainViewFn { func (self *BaseContext) AddOnRenderToMainFn(fn func()) { if fn != nil { + if self.onRenderToMainFn != nil { + panic("only one controller is allowed to set an onRenderToMainFn") + } self.onRenderToMainFn = fn } }