diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-12-30 23:24:24 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-04-30 13:19:52 +1000 |
commit | 8edad826caf2fa48bfad33f9f8c4f3ba49a052da (patch) | |
tree | 0b49145e4f656e72441199b5a5c30176c898d7a7 /pkg/gui/layout.go | |
parent | 826128a8e03fb50f7287029ebac93c85712faecb (diff) |
Begin refactoring gui
This begins a big refactor of moving more code out of the Gui struct into contexts, controllers, and helpers. We also move some code into structs in the
gui package purely for the sake of better encapsulation
Diffstat (limited to 'pkg/gui/layout.go')
-rw-r--r-- | pkg/gui/layout.go | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go index 0deb37d2e..0b522ec88 100644 --- a/pkg/gui/layout.go +++ b/pkg/gui/layout.go @@ -101,11 +101,11 @@ func (gui *Gui) layout(g *gocui.Gui) error { if err != nil && !gocui.IsUnknownView(err) { return err } - view.Visible = gui.getViewNameForWindow(context.GetWindowName()) == context.GetViewName() + view.Visible = gui.helpers.Window.GetViewNameForWindow(context.GetWindowName()) == context.GetViewName() } if gui.PrevLayout.Information != informationStr { - gui.setViewContent(gui.Views.Information, informationStr) + gui.c.SetViewContent(gui.Views.Information, informationStr) gui.PrevLayout.Information = informationStr } @@ -181,7 +181,7 @@ func (gui *Gui) onInitialViewsCreationForRepo() error { } } - initialContext := gui.currentSideContext() + initialContext := gui.c.CurrentSideContext() if err := gui.c.PushContext(initialContext); err != nil { return err } @@ -226,15 +226,44 @@ func (gui *Gui) onInitialViewsCreation() error { } if gui.showRecentRepos { - if err := gui.handleCreateRecentReposMenu(); err != nil { + if err := gui.helpers.Repos.CreateRecentReposMenu(); err != nil { return err } gui.showRecentRepos = false } - gui.Updater.CheckForNewUpdate(gui.onBackgroundUpdateCheckFinish, false) + gui.helpers.Update.CheckForUpdateInBackground() gui.waitForIntro.Done() return nil } + +// getFocusLayout returns a manager function for when view gain and lose focus +func (gui *Gui) getFocusLayout() func(g *gocui.Gui) error { + var previousView *gocui.View + return func(g *gocui.Gui) error { + newView := gui.g.CurrentView() + // for now we don't consider losing focus to a popup panel as actually losing focus + if newView != previousView && !gui.isPopupPanel(newView.Name()) { + if err := gui.onViewFocusLost(previousView); err != nil { + return err + } + + previousView = newView + } + return nil + } +} + +func (gui *Gui) onViewFocusLost(oldView *gocui.View) error { + if oldView == nil { + return nil + } + + oldView.Highlight = false + + _ = oldView.SetOriginX(0) + + return nil +} |