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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Jul 3 17:45:21 MSK 2013


Author: sergei
Date: 2013-07-03 17:45:21 +0400 (Wed, 03 Jul 2013)
New Revision: 2013

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/plugins/search/search.tcl
Log:
	* plugins/search/search.tcl: Added code for searching in multicolumn
	  listboxes.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2013-05-20 14:27:18 UTC (rev 2012)
+++ trunk/tkabber/ChangeLog	2013-07-03 13:45:21 UTC (rev 2013)
@@ -1,3 +1,8 @@
+2013-07-03  Sergei Golovan  <sgolovan at nes.ru>
+
+	* plugins/search/search.tcl: Added code for searching in multicolumn
+	  listboxes.
+
 2013-05-20  Sergei Golovan  <sgolovan at nes.ru>
 
 	* messages.tcl: Fixed choosing the outgoing connection when sending

Modified: trunk/tkabber/plugins/search/search.tcl
===================================================================
--- trunk/tkabber/plugins/search/search.tcl	2013-05-20 14:27:18 UTC (rev 2012)
+++ trunk/tkabber/plugins/search/search.tcl	2013-07-03 13:45:21 UTC (rev 2013)
@@ -379,4 +379,78 @@
 }
 
 ##########################################################################
+##########################################################################
+# Support for searching in mclistbox widgets for Tkabber.
 
+namespace eval search::mclistbox {}
+
+##########################################################################
+
+proc search::mclistbox::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  {!$found && $i <= $end1}
+	set start2 0
+	set end2   $selection_last
+	set cond2  {!$found && $i < $end2}
+    } else {
+	set step   -1
+	set start1 [incr selection_first -1]
+	set end1   0
+	set cond1  {!$found && $i >= $end1}
+	set start2 [$w index end]
+	set end2   $selection_first
+	set cond2  {!$found && $i > $end2}
+    }
+
+    set found 0
+
+    for {set i $start1} $cond1 {incr i $step} {
+	foreach item [$w get $i] {
+	    if {[[namespace parent]::match $pattern $item]} {
+		set found 1
+		break
+	    }
+	}
+    }
+    if {!$found} {
+	for {set i $start2} $cond2 {incr i $step} {
+	    foreach item [$w get $i] {
+		if {[[namespace parent]::match $pattern $item]} {
+		    set found 1
+		    break
+		}
+	    }
+	}
+    }
+
+    if {$found} {
+	hilite $w $i
+    }
+
+    return $found
+}
+
+##########################################################################
+
+proc search::mclistbox::hilite {w index} {
+    $w selection clear 0 end
+    $w selection set $index
+    $w see $index
+}
+
+##########################################################################
+



More information about the Tkabber-dev mailing list