[Tkabber-dev] r1006 - in trunk/tkabber: . plugins/search

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Mar 4 19:14:31 MSK 2007


Author: sergei
Date: 2007-03-04 19:14:29 +0300 (Sun, 04 Mar 2007)
New Revision: 1006

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/plugins/search/search.tcl
Log:
	* plugins/search/search.tcl: Added functions to search in listboxes
	  (thanks to Konstantin Khomoutov).


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2007-03-04 14:13:16 UTC (rev 1005)
+++ trunk/tkabber/ChangeLog	2007-03-04 16:14:29 UTC (rev 1006)
@@ -20,6 +20,9 @@
 
 	* plugins/search/spanel.tcl: Fixed error message.
 
+	* plugins/search/search.tcl: Added functions to search in listboxes
+	  (thanks to Konstantin Khomoutov).
+
 2007-03-03  Sergei Golovan  <sgolovan at nes.ru>
 
 	* plugins/general/headlines.tcl: Bugfix. Removed trailing linefeed

Modified: trunk/tkabber/plugins/search/search.tcl
===================================================================
--- trunk/tkabber/plugins/search/search.tcl	2007-03-04 14:13:16 UTC (rev 1005)
+++ trunk/tkabber/plugins/search/search.tcl	2007-03-04 16:14:29 UTC (rev 1006)
@@ -178,6 +178,7 @@
 }
 
 ##########################################################################
+##########################################################################
 
 namespace eval search::bwtree {}
 
@@ -308,4 +309,74 @@
 }
 
 ##########################################################################
+##########################################################################
+# Support for searching in listbox widgets for Tkabber.
 
+namespace eval search::listbox {}
+
+##########################################################################
+
+proc search::listbox::do_search {w pattern dir} {
+    set selection_first 0
+    set selection_last [$w index end]
+    for {set i 0} {$i < [$w index end]} {incr i} {
+	if {[$w selection includes $i]} {
+	    if {$selection_first == 0} {
+		set selection_first $i
+	    }
+	    set selection_last $i
+	}
+    }
+
+    if {[string equal $dir down]} {
+	set step   1
+	set start1 [incr selection_last]
+	set end1   [$w index end]
+	set cond1  {$i <= $end1}
+	set start2 0
+	set end2   $selection_last
+	set cond2  {$i < $end2}
+    } else {
+	set step   -1
+	set start1 [incr selection_first -1]
+	set end1   0
+	set cond1  {$i >= $end1}
+	set start2 [$w index end]
+	set end2   $selection_first
+	set cond2  {$i > $end2}
+    }
+
+    set found 0
+
+    for {set i $start1} $cond1 {incr i $step} {
+	if {[[namespace parent]::match $pattern [$w get $i]]} {
+	    set found 1
+	    break
+	}
+    }
+    if {!$found} {
+	for {set i $start2} $cond2 {incr i $step} {
+	    if {[[namespace parent]::match $pattern [$w get $i]]} {
+		set found 1
+		break
+	    }
+	}
+    }
+
+    if {$found} {
+	hilite $w $i
+    }
+
+    return $found
+}
+
+##########################################################################
+
+proc search::listbox::hilite {w index} {
+    $w selection clear 0 end
+    $w selection set $index
+    $w see $index
+}
+
+##########################################################################
+



More information about the Tkabber-dev mailing list