Add tooltips for sort orders
Also generalise the file sort function to allow sorting by any quantity returned by `[file stat]`
This commit is contained in:
parent
9cf915e5f7
commit
42cf8bf238
@ -292,7 +292,7 @@ if {$parent ne ""} {
|
|||||||
"
|
"
|
||||||
}
|
}
|
||||||
|
|
||||||
proc s_time {a b} {
|
proc s_file_stat {a b attr} {
|
||||||
global dir
|
global dir
|
||||||
|
|
||||||
set a "$dir/$a"
|
set a "$dir/$a"
|
||||||
@ -310,40 +310,21 @@ proc s_time {a b} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if {[catch {file stat $a l}]} { return 0}
|
if {[catch {file stat $a l}]} { return 0}
|
||||||
set at $l(mtime)
|
set at $l($attr)
|
||||||
if {[catch {file stat $b l}]} { return 0}
|
if {[catch {file stat $b l}]} { return 0}
|
||||||
set bt $l(mtime)
|
set bt $l($attr)
|
||||||
|
|
||||||
if {$at < $bt} { return -1 }
|
if {$at < $bt} { return -1 }
|
||||||
if {$at > $bt} { return 1 }
|
if {$at > $bt} { return 1 }
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
proc s_time {a b} {
|
||||||
|
tailcall s_file_stat $a $b mtime
|
||||||
|
}
|
||||||
|
|
||||||
proc s_size {a b} {
|
proc s_size {a b} {
|
||||||
global dir
|
tailcall s_file_stat $a $b size
|
||||||
|
|
||||||
set a "$dir/$a"
|
|
||||||
set b "$dir/$b"
|
|
||||||
|
|
||||||
set ad [file isdirectory $a]
|
|
||||||
set bd [file isdirectory $b]
|
|
||||||
|
|
||||||
if {$ad && !$bd} { return -1 }
|
|
||||||
if {$bd && !$ad} { return 1 }
|
|
||||||
if {$ad && $bd} {
|
|
||||||
if {$a < $b} { return -1 }
|
|
||||||
if {$a > $b} { return 1 }
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
if {[catch {file stat $a l}]} { return 0}
|
|
||||||
set as $l(size)
|
|
||||||
if {[catch {file stat $b l}]} { return 0}
|
|
||||||
set bs $l(size)
|
|
||||||
|
|
||||||
if {$as < $bs} { return -1 }
|
|
||||||
if {$as > $bs} { return 1 }
|
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set files [readdir -nocomplain $dir]
|
set files [readdir -nocomplain $dir]
|
||||||
@ -367,26 +348,27 @@ Directories: $dircount, Files: $filecount
|
|||||||
# Sort icons
|
# Sort icons
|
||||||
puts "<div id=sortdiv>"
|
puts "<div id=sortdiv>"
|
||||||
set sortlist {
|
set sortlist {
|
||||||
{0 sort_name name}
|
{0 sort_name name {Alphabetical order A->Z}}
|
||||||
{1 sort_date date} {2 sort_date reverse-date}
|
{1 sort_date date {Oldest first}} {2 sort_date reverse-date {Newest first}}
|
||||||
{3 sort_size size} {4 sort_size reverse-size}}
|
{3 sort_size size {Smallest first}} {4 sort_size reverse-size {Largest first}}}
|
||||||
puts "
|
puts "
|
||||||
Sort by: "
|
Sort by: "
|
||||||
foreach sl $sortlist {
|
foreach sl $sortlist {
|
||||||
lassign $sl index img descr
|
lassign $sl index img descr tt
|
||||||
|
|
||||||
if {$index} { puts " | " }
|
if {$index} { puts " | " }
|
||||||
|
|
||||||
set tag " (current)"
|
set tag " (current)"
|
||||||
if {$order != $index} {
|
if {$order != $index} {
|
||||||
set qs [regsub -all {&order=[[[:digit:]]+} $env(QUERY_STRING) ""]
|
set qs [regsub -all {&order=[[[:digit:]]+} $env(QUERY_STRING) ""]
|
||||||
puts "<a href=\"$env(SCRIPT_NAME)?$qs&order=$index\">"
|
puts "<a href=\"$env(SCRIPT_NAME)?$qs&order=$index\" title=\"$tt\">"
|
||||||
set tag ""
|
set tag ""
|
||||||
|
set ket "a"
|
||||||
|
} else {
|
||||||
|
puts "<span title=\"$tt\">"
|
||||||
|
set ket "span"
|
||||||
}
|
}
|
||||||
puts "<img class=va border=0 src=/img/$img.gif> $descr$tag"
|
puts "<img class=va border=0 src=\"/img/$img.gif\"> $descr$tag</$ket>"
|
||||||
if {$order != $index} {
|
|
||||||
puts "</a>"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
puts "</div>"
|
puts "</div>"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user