[Tkabber-dev] r1959 - trunk/tkabber-plugins/stripes

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Tue Nov 16 04:38:49 MSK 2010


Author: kostix
Date: 2010-11-16 04:38:49 +0300 (Tue, 16 Nov 2010)
New Revision: 1959

Modified:
   trunk/tkabber-plugins/stripes/stripes.tcl
Log:
Make stripes plugin dynamically loadable

Modified: trunk/tkabber-plugins/stripes/stripes.tcl
===================================================================
--- trunk/tkabber-plugins/stripes/stripes.tcl	2010-11-15 14:16:13 UTC (rev 1958)
+++ trunk/tkabber-plugins/stripes/stripes.tcl	2010-11-16 01:38:49 UTC (rev 1959)
@@ -14,15 +14,39 @@
 namespace eval stripes {
     variable state
 
-    hook::add open_chat_post_hook \
-	[namespace current]::setup_chat_window
-    hook::add draw_message_post_hook \
-	[namespace current]::on_message_drawn
+    if {![::plugins::is_registered stripes]} {
+        ::plugins::register stripes \
+            -namespace [namespace current] \
+            -source [info script] \
+            -description [::msgcat::mc \
+		"Whether the Stripes plugin is loaded."] \
+            -loadcommand [namespace code load] \
+            -unloadcommand [namespace code unload]
+        return
+    }
 }
 
+proc stripes::load {} {
+    hook::add open_chat_post_hook [namespace current]::setup_chat_window
+    hook::add close_chat_post_hook [namespace current]::cleanup_state
+    hook::add draw_message_post_hook [namespace current]::on_message_drawn
+
+    foreach chatid [chat::opened] {
+	setup_chat_window $chatid ?
+    }
+}
+
+proc stripes::unload {} {
+    foreach chatid [chat::opened] {
+	cleanup_chat_window $chatid
+    }
+
+    hook::remove open_chat_post_hook [namespace current]::setup_chat_window
+    hook::remove close_chat_post_hook [namespace current]::cleanup_state
+    hook::remove draw_message_post_hook [namespace current]::on_message_drawn
+}
+
 proc stripes::setup_chat_window {chatid type} {
-    variable state
-
     set cw [::chat::chat_win $chatid]
     set mw [::chat::winid $chatid]
 
@@ -37,29 +61,33 @@
 	$cw tag lower even
     }
 
-    set state($cw,last) 1.0
-    set state($cw,tag) odd
+    variable state
+    set state($chatid,last) [$cw index {end - 1 char}]
+    set state($chatid,tag) odd
+}
 
-    bind $cw <Destroy> +[list [namespace current]::cleanup $cw %W]
+proc stripes::cleanup_state {chatid} {
+    variable state
+    unset state($chatid,last)
+    unset state($chatid,tag)
 }
 
-proc stripes::cleanup {w1 w2} {
-    if {![string equal $w1 $w2]} return
+proc stripes::cleanup_chat_window {chatid} {
+    set cw [::chat::chat_win $chatid]
+    $cw tag delete odd even
 
-    variable state
-    unset state($w1,last)
-    unset state($w1,tag)
+    cleanup_state $chatid
 }
 
 proc stripes::on_message_drawn {chatid from type body x} {
     if {![chat::is_opened $chatid]} return
 
+    variable state
+    upvar 0 state($chatid,last) last
+    upvar 0 state($chatid,tag)  tag
+
     set cw [::chat::chat_win $chatid]
 
-    variable state
-    upvar 0 state($cw,last) last
-    upvar 0 state($cw,tag)  tag
-
     set now [$cw index {end - 1 char}]
     if {[$cw compare $last < $now]} {
 	$cw tag add $tag $last $now



More information about the Tkabber-dev mailing list