Permalink
Browse files

lsort-dict in skutil and sorting server list

  • Loading branch information...
hypatia2 committed Aug 22, 2015
1 parent 62b96ea commit db8500096b0dbb25eb28f9d1d1375303e750923b
Showing with 23 additions and 1 deletion.
  1. +4 −1 fruho/main.tcl
  2. +19 −0 sklib/skutil.tcl
@@ -2416,7 +2416,10 @@ proc ServerListClicked {} {
$wt column 1 -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 ccode [dict get $sitem ccode]
if {$ccode eq ""} {
@@ -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
}

0 comments on commit db85000

Please sign in to comment.