summaryrefslogtreecommitdiff
path: root/pkg/gui/gui-util.go
diff options
context:
space:
mode:
authorIbrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>2018-12-05 02:19:41 +0300
committerGitHub <noreply@github.com>2018-12-05 02:19:41 +0300
commit5c481dfe96fc40b8b7ad4fdc63fa0968e6832939 (patch)
tree6442b45aeac0e88e83656e871c0e0872d59e4044 /pkg/gui/gui-util.go
parentDevelop (#20) (diff)
downloadgitbatch-5c481dfe96fc40b8b7ad4fdc63fa0968e6832939.tar.gz
Develop (#23)
* restyle on repository selection * restyle continued on selections * added initial logging to git package * reverse scrolling on commits implemented * queue converted to first in first out principle * added sorting * select all feature added * code reuse improved and added scrolling to controls view * update readme
Diffstat (limited to 'pkg/gui/gui-util.go')
-rw-r--r--pkg/gui/gui-util.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/pkg/gui/gui-util.go b/pkg/gui/gui-util.go
index c09ae6c..2ae8cae 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,59 @@ 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
+}
+
+// cursor down acts like half-page down for faster scrolling
+func (gui *Gui) fastCursorDown(g *gocui.Gui, v *gocui.View) error {
+ if v != nil {
+ ox, oy := v.Origin()
+ _, vy := v.Size()
+
+ // TODO: do something when it hits bottom
+ if err := v.SetOrigin(ox, oy+vy/2); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
+// cursor up acts like half-page up for faster scrolling
+func (gui *Gui) fastCursorUp(g *gocui.Gui, v *gocui.View) error {
+ if v != nil {
+ ox, oy := v.Origin()
+ _, vy := v.Size()
+
+ if oy-vy/2 > 0 {
+ if err := v.SetOrigin(ox, oy-vy/2); err != nil {
+ return err
+ }
+ } else if oy-vy/2 <= 0 {
+ if err := v.SetOrigin(0, 0); err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}