diff options
Diffstat (limited to 'pkg/gui/gui-util.go')
| -rw-r--r-- | pkg/gui/gui-util.go | 78 |
1 files changed, 53 insertions, 25 deletions
diff --git a/pkg/gui/gui-util.go b/pkg/gui/gui-util.go index 2ae8cae..2338bac 100644 --- a/pkg/gui/gui-util.go +++ b/pkg/gui/gui-util.go @@ -1,11 +1,10 @@ package gui import ( - "sort" - "github.com/isacikgoz/gitbatch/pkg/git" "github.com/isacikgoz/gitbatch/pkg/helpers" "github.com/jroimartin/gocui" + log "github.com/sirupsen/logrus" ) // refreshes the side views of the application for given git.RepoEntity struct @@ -26,6 +25,58 @@ func (gui *Gui) refreshViews(g *gocui.Gui, entity *git.RepoEntity) error { return err } +// focus to next view +func (gui *Gui) nextViewOfGroup(g *gocui.Gui, v *gocui.View, group []viewFeature) error { + var focusedViewName string + if v == nil || v.Name() == group[len(group)-1].Name { + focusedViewName = group[0].Name + } else { + for i := range group { + if v.Name() == group[i].Name { + focusedViewName = group[i+1].Name + break + } + if i == len(group)-1 { + return nil + } + } + } + if _, err := g.SetCurrentView(focusedViewName); err != nil { + log.WithFields(log.Fields{ + "view": focusedViewName, + }).Warn("View cannot be focused.") + return nil + } + gui.updateKeyBindingsView(g, focusedViewName) + return nil +} + +// focus to previous view +func (gui *Gui) previousViewOfGroup(g *gocui.Gui, v *gocui.View, group []viewFeature) error { + var focusedViewName string + if v == nil || v.Name() == group[0].Name { + focusedViewName = group[len(group)-1].Name + } else { + for i := range group { + if v.Name() == group[i].Name { + focusedViewName = group[i-1].Name + break + } + if i == len(group)-1 { + return nil + } + } + } + if _, err := g.SetCurrentView(focusedViewName); err != nil { + log.WithFields(log.Fields{ + "view": focusedViewName, + }).Warn("View cannot be focused.") + return nil + } + gui.updateKeyBindingsView(g, focusedViewName) + return nil +} + // siwtch the app mode // TODO: switching can be made with conventional iteration func (gui *Gui) switchMode(g *gocui.Gui, v *gocui.View) error { @@ -110,29 +161,6 @@ func writeRightHandSide(v *gocui.View, text string, cx, cy int) error { return nil } -// sortByName sorts the repositories by A to Z order -func (gui *Gui) sortByName(g *gocui.Gui, v *gocui.View) error { - sort.Sort(git.Alphabetical(gui.State.Repositories)) - gui.refreshAfterSort(g) - return nil -} - -// sortByMod sorts the repositories according to last modifed date -// the top element will be the last modified -func (gui *Gui) sortByMod(g *gocui.Gui, v *gocui.View) error { - sort.Sort(git.LastModified(gui.State.Repositories)) - gui.refreshAfterSort(g) - return nil -} - -// utility function that refreshes main and side views after that -func (gui *Gui) refreshAfterSort(g *gocui.Gui) error { - gui.refreshMain(g) - entity := gui.getSelectedRepository() - gui.refreshViews(g, entity) - return nil -} - // cursor down acts like half-page down for faster scrolling func (gui *Gui) fastCursorDown(g *gocui.Gui, v *gocui.View) error { if v != nil { |
