move file sorting to nav

This commit is contained in:
Gokcehan committed 2016-11-11 00:18:56 +03:00
1 parent c6560ad607
commit 609c637e82
2 files changed
+15 -17

No files matched your search

-17
View File
@@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"log" "log"
"path/filepath" "path/filepath"
"sort"
"strconv" "strconv"
"strings" "strings"
"unicode" "unicode"
@@ -158,22 +157,6 @@ func max(a, b int) int {
return b return b
} }
type filesSortable struct {
files []*File
less func(i, j int) bool
}
func (f filesSortable) Len() int { return len(f.files) }
func (f filesSortable) Swap(i, j int) { f.files[i], f.files[j] = f.files[j], f.files[i] }
func (f filesSortable) Less(i, j int) bool { return f.less(i, j) }
// TODO: Replace with `sort.SliceStable` once available
func sortFilesStable(files []*File, less func(i, j int) bool) {
sort.Stable(filesSortable{files: files, less: less})
}
// We don't need no generic code // We don't need no generic code
// We don't need no thought control // We don't need no thought control
// No dark templates in compiler // No dark templates in compiler
+15
View File
@@ -7,6 +7,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"sort"
"strings" "strings"
) )
@@ -24,6 +25,20 @@ type File struct {
Path string Path string
} }
type FilesSortable struct {
files []*File
less func(i, j int) bool
}
func (f FilesSortable) Len() int { return len(f.files) }
func (f FilesSortable) Swap(i, j int) { f.files[i], f.files[j] = f.files[j], f.files[i] }
func (f FilesSortable) Less(i, j int) bool { return f.less(i, j) }
// TODO: Replace with `sort.SliceStable` once available
func sortFilesStable(files []*File, less func(i, j int) bool) {
sort.Stable(FilesSortable{files: files, less: less})
}
func getFilesSorted(path string) []*File { func getFilesSorted(path string) []*File {
fi, err := readdir(path) fi, err := readdir(path)
if err != nil { if err != nil {