[Tkabber-dev] r1957 - in trunk/tkabber-plugins/quotelastmsg: . msgs

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Mon Nov 15 03:39:57 MSK 2010


Author: kostix
Date: 2010-11-15 03:39:56 +0300 (Mon, 15 Nov 2010)
New Revision: 1957

Modified:
   trunk/tkabber-plugins/quotelastmsg/msgs/ru.msg
   trunk/tkabber-plugins/quotelastmsg/quotelastmsg.tcl
Log:
Make quotelastmsg plugin dynamically loadable

Modified: trunk/tkabber-plugins/quotelastmsg/msgs/ru.msg
===================================================================
--- trunk/tkabber-plugins/quotelastmsg/msgs/ru.msg	2010-11-12 00:48:25 UTC (rev 1956)
+++ trunk/tkabber-plugins/quotelastmsg/msgs/ru.msg	2010-11-15 00:39:56 UTC (rev 1957)
@@ -6,10 +6,12 @@
 	формата \"%m\" заменяется на все цитируемое сообщение.\
 	Спецификатор формата \"%%\" заменяется на один знак процента \"%\"."
 ::msgcat::mcset ru "Plugins options." "Настройки расширений."
-::msgcat::mcset ru "Quote Last Message plugin options. This\
-	plugin provides a way to copy a message located at the\
+::msgcat::mcset ru "Whether the last message quoting plugin is loaded." \
+	"Загружено ли расширение цитирования последнего сообщения."
+::msgcat::mcset ru "Quote Last Message plugin options." \
+	"Настройки расширения цитирования последнего сообщения."
+::msgcat::mcset ru "This plugin provides a way to copy a message located at the\
 	bottom of a chat window conversation log to the input\
-	box of that chat window."\
-	"Настройки расширения цитирования последнего сообщения. Это расширение\
-	позволяет копировать сообщение, находящееся в самом низу окна разговора,\
-	в окно ввода сообщения."
+	box of that chat window." \
+	"Это расширение позволяет копировать сообщение, находящееся в самом низу\
+	окна разговора, в окно ввода сообщения."

Modified: trunk/tkabber-plugins/quotelastmsg/quotelastmsg.tcl
===================================================================
--- trunk/tkabber-plugins/quotelastmsg/quotelastmsg.tcl	2010-11-12 00:48:25 UTC (rev 1956)
+++ trunk/tkabber-plugins/quotelastmsg/quotelastmsg.tcl	2010-11-15 00:39:56 UTC (rev 1957)
@@ -8,22 +8,32 @@
 # See license.terms for the terms of distribution.
 # See README for usage details.
 
-event add <<QuoteLastMessage>> <Alt-q>
-event add <<QuoteLastMessage>> <Meta-q>
-
 namespace eval quotelastmsg {
     variable state
     variable options
 
     ::msgcat::mcload [file join [file dirname [info script]] msgs]
 
+    variable desc [::msgcat::mc \
+	    "This plugin provides a way to copy a message located\
+	    at the bottom of a chat window conversation log\
+	    to the input box of that chat window."]
+
+    if {![::plugins::is_registered quotelastmsg]} {
+        ::plugins::register quotelastmsg \
+            -namespace [namespace current] \
+            -source [info script] \
+            -description [::msgcat::mc \
+		"Whether the last message quoting plugin is loaded."]\n$desc \
+            -loadcommand [namespace code load] \
+            -unloadcommand [namespace code unload]
+        return
+    }
+
     custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber
 
     custom::defgroup {Quote Last Message} \
-	[::msgcat::mc "Quote Last Message plugin options.\
-	    This plugin provides a way to copy a message located\
-	    at the bottom of a chat window conversation log\
-	    to the input box of that chat window."] \
+	[::msgcat::mc "Quote Last Message plugin options."]\ $desc \
 	-group Plugins \
 	-group Chat
 
@@ -35,38 +45,66 @@
 	-group {Quote Last Message} \
 	-type string
 
-    hook::add open_chat_post_hook \
-	[namespace current]::setup_chat_window
-    hook::add draw_message_post_hook \
-	[namespace current]::on_message_drawn
 }
 
-proc quotelastmsg::setup_chat_window {chatid type} {
-    variable state
+proc quotelastmsg::load {} {
+    hook::add open_chat_post_hook [namespace current]::prepare_chat_window
+    hook::add close_chat_post_hook [namespace current]::cleanup_state
+    hook::add draw_message_post_hook [namespace current]::on_message_drawn
 
+    event add <<QuoteLastMessage>> <Alt-q>
+    event add <<QuoteLastMessage>> <Meta-q>
+
+    foreach chatid [chat::opened] {
+	prepare_chat_window $chatid ?
+    }
+}
+
+proc quotelastmsg::unload {} {
+    foreach chatid [chat::opened] {
+	unprepare_chat_window $chatid
+    }
+
+    event delete <<QuoteLastMessage>> <Alt-q>
+    event delete <<QuoteLastMessage>> <Meta-q>
+
+    hook::remove open_chat_post_hook [namespace current]::prepare_chat_window
+    hook::remove close_chat_post_hook [namespace current]::cleanup_state
+    hook::remove draw_message_post_hook [namespace current]::on_message_drawn
+}
+
+proc quotelastmsg::prepare_chat_window {chatid type} {
     set iw [::chat::input_win $chatid]
+    set cw [::chat::chat_win $chatid]
     bind $iw <<QuoteLastMessage>> [list [namespace current]::quote [double% $chatid]]
 
+    variable state
+    set state($chatid,last) [$cw index {end - 1 char}]
+}
+
+proc quotelastmsg::unprepare_chat_window {chatid} {
+    set iw [::chat::input_win $chatid]
+    bind $iw <<QuoteLastMessage>> {}
+
     set cw [::chat::chat_win $chatid]
-    set state($cw,last) 1.0
-    bind $cw <Destroy> +[list [namespace current]::cleanup [double% $cw] %W]
+    $cw tag delete lastmsg
+
+    cleanup_state $chatid
 }
 
-proc quotelastmsg::cleanup {w1 w2} {
-    if {![string equal $w1 $w2]} return
-
+proc quotelastmsg::cleanup_state {chatid} {
     variable state
-    unset state($w1,last)
+    unset state($chatid,last)
 }
 
 proc quotelastmsg::on_message_drawn {chatid from type body x} {
     if {![chat::is_opened $chatid]} return
 
-    set cw [::chat::chat_win $chatid]
 
     variable state
-    upvar 0 state($cw,last) last
+    upvar 0 state($chatid,last) last
 
+    set cw [::chat::chat_win $chatid]
     set now [$cw index {end - 1 char}]
     if {[$cw compare $last < $now]} {
 	$cw tag delete lastmsg
@@ -76,7 +114,7 @@
     set last $now
 }
 
-proc quotelastmsg::quote chatid {
+proc quotelastmsg::quote {chatid} {
     variable options
 
     set cw [::chat::chat_win $chatid]



More information about the Tkabber-dev mailing list