summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorİbrahim Serdar Açıkgöz <serdaracikgoz86@gmail.com>2019-01-04 14:07:44 +0300
committerİbrahim Serdar Açıkgöz <serdaracikgoz86@gmail.com>2019-01-04 14:07:44 +0300
commit164958183d3e44db91d9a6b1511bfd2be47efd4f (patch)
tree2885ba7847f3ad9b52338e6b88f6fe0523bfb92b /gui
parentadd state to repository and some renaming (diff)
downloadgitbatch-164958183d3e44db91d9a6b1511bfd2be47efd4f.tar.gz
sort at lazy start
Diffstat (limited to 'gui')
-rw-r--r--gui/gui.go47
1 files changed, 46 insertions, 1 deletions
diff --git a/gui/gui.go b/gui/gui.go
index 84bdb51..3bfa9e2 100644
--- a/gui/gui.go
+++ b/gui/gui.go
@@ -2,6 +2,7 @@ package gui
import (
"sync"
+ "unicode"
"github.com/isacikgoz/gitbatch/core/git"
"github.com/isacikgoz/gitbatch/core/job"
@@ -132,11 +133,55 @@ func (gui *Gui) Run() error {
}
func (gui *Gui) addRepository(r *git.Repository) {
- gui.State.Repositories = append(gui.State.Repositories, r)
+ gui.mutex.Lock()
+ gui.State.Repositories = gui.appendAlphabetically(r)
+ gui.mutex.Unlock()
r.On(git.RepositoryUpdated, gui.repositoryUpdated)
+
gui.repositoryUpdated(nil)
}
+func (gui *Gui) appendAlphabetically(r *git.Repository) []*git.Repository {
+ rs := gui.State.Repositories
+ i := len(rs) - 1
+ if i >= 0 && rs[i] != nil && !less(rs[i], r) {
+ rs = append(rs, nil)
+ copy(rs[i+1:], rs[i:])
+ rs[i] = r
+ } else {
+ rs = append(rs, r)
+ }
+ return rs
+}
+
+func less(ri, rj *git.Repository) bool {
+ iRunes := []rune(ri.Name)
+ jRunes := []rune(rj.Name)
+
+ max := len(iRunes)
+ if max > len(jRunes) {
+ max = len(jRunes)
+ }
+
+ for idx := 0; idx < max; idx++ {
+ ir := iRunes[idx]
+ jr := jRunes[idx]
+
+ lir := unicode.ToLower(ir)
+ ljr := unicode.ToLower(jr)
+
+ if lir != ljr {
+ return lir < ljr
+ }
+
+ // the lowercase runes are the same, so compare the original
+ if ir != jr {
+ return ir < jr
+ }
+ }
+ return false
+}
+
// set the layout and create views with their default size, name etc. values
// TODO: window sizes can be handled better
func (gui *Gui) layout(g *gocui.Gui) error {