From 524bf83a4a681408c3fb57818f6968cab632e0ae Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Mon, 13 Jun 2022 11:01:26 +1000 Subject: refactor to only have one context per view --- pkg/gui/context/list_context_trait.go | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'pkg/gui/context/list_context_trait.go') diff --git a/pkg/gui/context/list_context_trait.go b/pkg/gui/context/list_context_trait.go index 04cbefcf9..df5bbc0af 100644 --- a/pkg/gui/context/list_context_trait.go +++ b/pkg/gui/context/list_context_trait.go @@ -12,7 +12,6 @@ type ListContextTrait struct { c *types.HelperCommon list types.IList - viewTrait *ViewTrait getDisplayStrings func(startIdx int, length int) [][]string } @@ -20,43 +19,39 @@ func (self *ListContextTrait) GetList() types.IList { return self.list } -func (self *ListContextTrait) GetViewTrait() types.IViewTrait { - return self.viewTrait -} - func (self *ListContextTrait) FocusLine() { // we need a way of knowing whether we've rendered to the view yet. - self.viewTrait.FocusPoint(self.list.GetSelectedLineIdx()) + self.GetViewTrait().FocusPoint(self.list.GetSelectedLineIdx()) self.setFooter() } func (self *ListContextTrait) setFooter() { - self.viewTrait.SetFooter(formatListFooter(self.list.GetSelectedLineIdx(), self.list.Len())) + self.GetViewTrait().SetFooter(formatListFooter(self.list.GetSelectedLineIdx(), self.list.Len())) } func formatListFooter(selectedLineIdx int, length int) string { return fmt.Sprintf("%d of %d", selectedLineIdx+1, length) } -func (self *ListContextTrait) HandleFocus(opts ...types.OnFocusOpts) error { +func (self *ListContextTrait) HandleFocus(opts types.OnFocusOpts) error { self.FocusLine() - self.viewTrait.SetHighlight(self.list.Len() > 0) + self.GetViewTrait().SetHighlight(self.list.Len() > 0) - return self.Context.HandleFocus(opts...) + return self.Context.HandleFocus(opts) } -func (self *ListContextTrait) HandleFocusLost() error { - self.viewTrait.SetOriginX(0) +func (self *ListContextTrait) HandleFocusLost(opts types.OnFocusLostOpts) error { + self.GetViewTrait().SetOriginX(0) - return self.Context.HandleFocusLost() + return self.Context.HandleFocusLost(opts) } // OnFocus assumes that the content of the context has already been rendered to the view. OnRender is the function which actually renders the content to the view func (self *ListContextTrait) HandleRender() error { self.list.RefreshSelectedIdx() content := utils.RenderDisplayStrings(self.getDisplayStrings(0, self.list.Len())) - self.viewTrait.SetContent(content) + self.GetViewTrait().SetContent(content) self.c.Render() self.setFooter() @@ -65,5 +60,5 @@ func (self *ListContextTrait) HandleRender() error { func (self *ListContextTrait) OnSearchSelect(selectedLineIdx int) error { self.GetList().SetSelectedLineIdx(selectedLineIdx) - return self.HandleFocus() + return self.HandleFocus(types.OnFocusOpts{}) } -- cgit v1.2.3