[Tkabber-dev] r121 - trunk/plugins/singularity

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Tue Aug 19 03:09:01 MSD 2008


Author: kostix
Date: 2008-08-19 03:09:00 +0400 (Tue, 19 Aug 2008)
New Revision: 121

Modified:
   trunk/plugins/singularity/singularity.tcl
Log:
singularity/singularity.tcl: Implemented saving of input and history
 of the chat windows to be closed. Input is accumulated, but history
 currently is copied only from the last window being closed
 (needs improvements).


Modified: trunk/plugins/singularity/singularity.tcl
===================================================================
--- trunk/plugins/singularity/singularity.tcl	2008-08-18 22:30:36 UTC (rev 120)
+++ trunk/plugins/singularity/singularity.tcl	2008-08-18 23:09:00 UTC (rev 121)
@@ -9,8 +9,12 @@
 # See README for usage details.
 
 namespace eval singularity {
+	variable contexts
+
 	hook::add open_chat_pre_hook \
 		[namespace current]::process_new_chat_opening
+	hook::add open_chat_post_hook \
+		[namespace current]::restore_chat_context
 }
 
 proc singularity::process_new_chat_opening {chatid type} {
@@ -19,6 +23,14 @@
 	set from [chat::get_jid $chatid]
 	set barejid [node_and_server_from_jid $from]
 
+	variable contexts
+	upvar 0 contexts(input,$chatid) savedinput
+	upvar 0 contexts(history,$chatid) savedhistory
+	variable [namespace parent]::history
+
+	set savedinput ""
+	set savedhistory [list]
+
 	if {$ifacetk::options(use_tabbar)} {
 		foreach page [.nb pages] {
 			upvar #0 chat::chat_id([ifacetk::nbpath $page]) cid 
@@ -26,6 +38,10 @@
 			set jid [chat::get_jid $cid]
 			if {![string equal $from $jid] &&
 					[string equal $barejid [node_and_server_from_jid $jid]]} {
+				if {$savedinput != ""} { append savedinput \n }
+				append savedinput [[chat::input_win $cid] get 1.0 end-1c]
+				set savedhistory [list \
+					$history(stack,$cid) $history(pos,$cid)]
 				eval destroy [pack slaves [.nb getframe $page]]
 				.nb delete $page 1
 				ifacetk::tab_move .nb 0
@@ -37,3 +53,20 @@
 
 }
 
+proc singularity::restore_chat_context {chatid type} {
+	if {![string equal $type chat]} return
+
+	variable contexts
+	upvar 0 contexts(input,$chatid) savedinput
+	upvar 0 contexts(history,$chatid) savedhistory
+	if {![info exists savedinput]} return
+
+	variable [namespace parent]::history
+
+	[chat::input_win $chatid] insert end $contexts(input,$chatid)
+	lassign $contexts(history,$chatid) \
+		history(stack,$chatid) history(pos,$chatid)
+
+	unset contexts(input,$chatid) contexts(history,$chatid)
+}
+



More information about the Tkabber-dev mailing list