diff options
Diffstat (limited to 'pkg/gui/gui-util.go')
| -rw-r--r-- | pkg/gui/gui-util.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/pkg/gui/gui-util.go b/pkg/gui/gui-util.go index c09ae6c..d3f0934 100644 --- a/pkg/gui/gui-util.go +++ b/pkg/gui/gui-util.go @@ -1,6 +1,8 @@ package gui import ( + "sort" + "github.com/isacikgoz/gitbatch/pkg/git" "github.com/isacikgoz/gitbatch/pkg/helpers" "github.com/jroimartin/gocui" @@ -107,3 +109,26 @@ func writeRightHandSide(v *gocui.View, text string, cx, cy int) error { v.SetCursor(cx, cy) 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 +} |
