Skip to content

Commit

Permalink
Fix the action item in explorer, it should not be sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
kivutar committed Mar 7, 2023
1 parent f38287b commit 898036a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
10 changes: 5 additions & 5 deletions menu/menu_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func Test_buildExplorer(t *testing.T) {
os.Create(tmp + "File 1.txt")
os.Create(tmp + "File 2.img")
os.Create(tmp + "File 3.txt")
os.Create(tmp + "File 4.img")
os.Create(tmp + "File 4.img") // this entry will be pushed at the end by sort+prettify
os.Create(tmp + "File 5.txt")
os.Create(tmp + "File 6.txt")
os.Create(tmp + "File 7.txt")
Expand Down Expand Up @@ -158,14 +158,14 @@ func Test_buildExplorer(t *testing.T) {
})

t.Run("Targeted files have OK callbacks", func(t *testing.T) {
children[3].callbackOK()
children[2].callbackOK()
if exec != 1 {
t.Errorf("buildExplorer = %v, want %v", exec, 1)
}
})

t.Run("Folders have folder icon", func(t *testing.T) {
if children[4].icon != "folder" {
if children[3].icon != "folder" {
t.Errorf("buildExplorer = %v, want %v", children[4].icon, "folder")
}
})
Expand All @@ -174,15 +174,15 @@ func Test_buildExplorer(t *testing.T) {
if len(menu.stack) != 1 {
t.Errorf("buildExplorer = %v, want %v", len(menu.stack), 1)
}
children[4].callbackOK()
children[3].callbackOK()
if len(menu.stack) != 2 {
t.Errorf("buildExplorer = %v, want %v", len(menu.stack), 2)
}
})

t.Run("Prettifier should work", func(t *testing.T) {
want := "IMAGE 4"
if children[3].label != want {
if children[4].label != want {
t.Errorf("buildExplorer = %v, want %v", children[3].label, want)
}
})
Expand Down
14 changes: 9 additions & 5 deletions menu/scene_explorer.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ func buildExplorer(path string, exts []string, cb func(string), dirAction *entry
}

files, err := ioutil.ReadDir(path)

// Sort entries by their labels, ignoring case.
sort.SliceStable(files, func(i, j int) bool {
if prettifier != nil {
return strings.ToLower(prettifier(utils.FileName(files[i].Name()))) < strings.ToLower(prettifier(utils.FileName(files[j].Name())))
}
return strings.ToLower(utils.FileName(files[i].Name())) < strings.ToLower(utils.FileName(files[j].Name()))
})

if err != nil {
ntf.DisplayAndLog(ntf.Error, "Menu", err.Error())
}
Expand All @@ -158,11 +167,6 @@ func buildExplorer(path string, exts []string, cb func(string), dirAction *entry
appendNode(&list, fullPath, f.Name(), fi, exts, cb, dirAction, prettifier)
}

// Sort entries by their labels, ignoring case.
sort.SliceStable(list.children, func(i, j int) bool {
return strings.ToLower(list.children[i].label) < strings.ToLower(list.children[j].label)
})

buildIndexes(&list.entry)

if len(files) == 0 {
Expand Down

0 comments on commit 898036a

Please sign in to comment.