As per my previous email about checkboxes, I realized that its much easier to 
work with comma delimited lists for what I needed. Here are some possibly 
useful TH1 scripts for checkboxes and comma delimited lists. Feel free to bug 
me for more info (though I'm on digests, so won't answer right away).

clength and cindex are direct substitutions for llength and lindex that are 
built in. I'm sure these could be improved. But they work for me.

proc strip_last_comma clist {
  set clist [string range $clist 0 [expr [string length $clist]-3]]
  return $clist
}

proc list_to_clist l {
  set new_l ""
  for {set i 0} {$i < [llength $l] } {set i [expr $i+1]} {
    set new_l "$new_l[lindex $l $i], "
  }
  return [strip_last_comma $new_l]
}

proc clength clist {
  if { [string length $clist] == 0 } {return 0}
  set count 0
  set cfirst 0
  for {set i 0} { $i < [string length $clist] } {set i [expr $i+1]} {
    set cfirst [string first ", " "$clist"]
    if { $cfirst != -1 } { 
      set clist [string range $clist [expr $cfirst+2] [string length $clist]]
      set count [expr $count+1] 
    } else {
      break
    }
  }
  if { $clist ne ", " } {
    set count [expr $count+1] 
  }
  return $count
}


proc cindex {clist idx} {
  set count 0
  set cfirst 0
  set cfirst_prev $cfirst
  set l($count) ""
  for {set i 0} { $i < [string length $clist] } {set i [expr $i+1]} {
    set cfirst [string first ", " "$clist"]
    if { $cfirst != -1 } {
      set l($count) [string range $clist $cfirst_prev [expr $cfirst-1]]
      set clist [string range $clist [expr $cfirst+2] [string length $clist]]
      set count [expr $count+1] 
    } else {
      break
    }
  }
  if { $clist ne ", " } {
    set l($count) $clist
  }
  if { [info exists l($idx)] } { 
    return $l($idx) 
  } else {
    return ""
  }
}


-----------------------

To implement checkboxes:


<th1>

set tags_regexp [cindex $tags 0]
for {set i 1} {$i < [clength $tags] } {set i [expr $i+1]} {
  set tags_regexp "$tags_regexp|[cindex $tags $i]"
}
if
 { [string range $tags_regexp [string length $tags_regexp] [string 
length $tags_regexp] ] eq "|" } { set tags_regexp 
"$tags_regexp!!!!!!!!!!" }
if { [string length $tags_regexp] <= 0 } { set tags_regexp "!!!!!!!!!!"}

html "<table width=\"100%\">"
for {set i 0} {$i < [clength $tags_choices] } {set i [expr $i+1]} {
  if { [expr $i%2] eq 0 } { html "<tr>" }
  html "<td width=\"50%\"><input type=\"checkbox\" name=\"tags_$i\" 
value=\"[cindex $tags_choices $i]\" "
  if {[ regexp $tags_regexp "[cindex $tags_choices $i]" ]} {
    html "checked" 
  } 
  html "/>[cindex $tags_choices $i]</td>" 
  if { [expr $i%2] eq 1 } { html "</tr>" }
}
html "<input type=\"hidden\" name=\"tags_regexp\" value=\"$tags_regexp\">"
if { [expr [clength $tags_choices]%2 ] eq 1 } {html "<td></td></tr>" }
html "</table>"
</th1>

-------------------

$tags_choices are implemented as follows:

set tags_choices {X
  "Y With Space"
  ZZ}


----------------------

Hope that helps someone sometime somewhere in the future....

Tomek
                                          
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users

Reply via email to