Skip to content

Commit

Permalink
lsort-dict in skutil and sorting server list
Browse files Browse the repository at this point in the history
  • Loading branch information
hypatia2 committed Aug 22, 2015
1 parent 62b96ea commit db85000
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion fruho/main.tcl
Expand Up @@ -2416,7 +2416,10 @@ proc ServerListClicked {} {
$wt column 1 -width 140 -anchor w $wt column 1 -width 140 -anchor w
$wt column 2 -width 140 -anchor w $wt column 2 -width 140 -anchor w


foreach sitem $slist {
set sorted_slist [lsort-dict $slist {country city}]

foreach sitem $sorted_slist {
set id [dict get $sitem id] set id [dict get $sitem id]
set ccode [dict get $sitem ccode] set ccode [dict get $sitem ccode]
if {$ccode eq ""} { if {$ccode eq ""} {
Expand Down
19 changes: 19 additions & 0 deletions sklib/skutil.tcl
Expand Up @@ -703,6 +703,25 @@ proc dict-move {d from to} {
} }




# sort list of dictionaries by given keys
# l - list of dictionaries to sort
# keys - list of keys by which to sort
proc lsort-dict {l keys} {
# create a new list of [list $sortkey $dict] so we can use lsort
set newlist {}
foreach d $l {
set sortkey {}
foreach k $keys {
lappend sortkey [dict-pop $d $k ""]
}
lappend newlist [list $sortkey $d]
}
set sortednewlist [lsort -index 0 $newlist]
# get rid of sortkey
set result [lmap ll $sortednewlist {lindex $ll 1}]
return $result
}







Expand Down

0 comments on commit db85000

Please sign in to comment.