[Tkabber-dev] r372 - trunk/plugins/tastebin

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Aug 25 13:46:05 MSD 2010


Author: Rejjin
Date: 2010-08-25 13:46:05 +0400 (Wed, 25 Aug 2010)
New Revision: 372

Modified:
   trunk/plugins/tastebin/tastebin.tcl
Log:
+ Save history to file.

Modified: trunk/plugins/tastebin/tastebin.tcl
===================================================================
--- trunk/plugins/tastebin/tastebin.tcl	2010-08-24 23:33:01 UTC (rev 371)
+++ trunk/plugins/tastebin/tastebin.tcl	2010-08-25 09:46:05 UTC (rev 372)
@@ -28,6 +28,10 @@
 	custom::defvar options(save_state) 0 \
 		[::msgcat::mc "Save state"] \
 		-group Tastebin -type boolean
+		
+	custom::defvar options(save_history_to_file) 1 \
+		[::msgcat::mc "Save history to file"] \
+		-group Tastebin -type boolean
 	
 	custom::defvar options(toolwindow) 1 \
 		[::msgcat::mc "Use a special display window"] \
@@ -289,7 +293,7 @@
 	$w insert 0.0 $data
 	http::cleanup $token
 	
-	lappend options(history) "\[[clock format [clock seconds] -format "%R %p %D"]\] $data"
+	putHistory "\[[clock format [clock seconds] -format "%R %p %D"]\] [.tastebin.send_bar.lang get] - $data"
 }
 
 
@@ -305,15 +309,51 @@
 }
 
 
-proc tastebin::history w {
+proc tastebin::putHistory msg {
 	variable options
 	
-	if { [info exist options(history)] == 0 } {
+	if { $options(save_history_to_file) == 0 } {
+		return [lappend options(history) $msg]
+	}
+	
+	set per a 	
+	
+	if { [file exist [file join $options(path) history]] == 0 } {
+		set per w
+	}
+	
+	set file [open [file join $options(path) history] $per]
+	puts $file $msg
+	close $file
+}
+
+
+proc tastebin::getHistory { } {
+	variable options
+	
+	if { $options(save_history_to_file) == 0 } {
+		if { [info exist options(history)] } {
+			return $options(history)
+		}
+		return 
+	}
+	
+	if { [file exist [file join $options(path) history]] == 0 } {
 		return
 	}
+
+	set file [open [file join $options(path) history] r]
+	set data [read $file]
+	close $file
+	return $data
+}
+
+proc tastebin::history w {
+	variable options
 	
 	delContent
-	$w insert 0.0 [join $options(history) \n]
+	
+	$w insert 0.0 [getHistory]
 }
 
 # Balloon



More information about the Tkabber-dev mailing list