[Tkabber-dev] r379 - in trunk/plugins/tastebin: . msgs

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Fri Sep 3 03:22:26 MSD 2010


Author: Rejjin
Date: 2010-09-03 03:22:25 +0400 (Fri, 03 Sep 2010)
New Revision: 379

Modified:
   trunk/plugins/tastebin/msgs/ru.msg
   trunk/plugins/tastebin/tastebin.tcl
Log:
modified files: tastebin.tcl and msgs/ru.msg
tastebin.tcl :
+ Added commands: 
\+p <text> - Sending messages to http://pastebin.com 
\-p <text> - Ignore the message be sent to http://pastebin.com 
If the tastebin::options(autopost_enable) then the message is longer tastebin::options(max_symbol_numbers) is automatically sent to http://pastebin.com 
All messages sent this way do not have lights 
+ Changed the appearance of the menu selection highlight language
+ Fix the window opening of Services/Tastebin

Modified: trunk/plugins/tastebin/msgs/ru.msg
===================================================================
--- trunk/plugins/tastebin/msgs/ru.msg	2010-09-02 14:01:33 UTC (rev 378)
+++ trunk/plugins/tastebin/msgs/ru.msg	2010-09-02 23:22:25 UTC (rev 379)
@@ -17,5 +17,10 @@
 ::msgcat::mcset ru "Undo" "Отмена"
 ::msgcat::mcset ru "Redo" "Повтор"
 ::msgcat::mcset ru "Select all" "Выделить всё"
-
-
+::msgcat::mcset ru "Please wait ..." "Пожалуйста, подождите ..."
+::msgcat::mcset ru "Your message are exceeding limit" "Ваше сообщение привысило ограничение"
+::msgcat::mcset ru "Tastebin autopost" "Автоотправка сообщений Tastebin"
+::msgcat::mcset ru "Tastebin autopost options" "Автоотправка сообщений Tastebin - настройки"
+::msgcat::mcset ru "Enable autopost for your messages" "Включить автоматическую отпраку сообщения"
+::msgcat::mcset ru "Max symbols in your message for normal sending, else - autopost to pastebin" "Максимальное количество символов для нормальной отправки сообщения. Если превышен - сообщение автоматически отсылается на pastebin"
+::msgcat::mcset ru "The number of characters can not be less than 10" "Количество символов не может быть меньше 10-и"

Modified: trunk/plugins/tastebin/tastebin.tcl
===================================================================
--- trunk/plugins/tastebin/tastebin.tcl	2010-09-02 14:01:33 UTC (rev 378)
+++ trunk/plugins/tastebin/tastebin.tcl	2010-09-02 23:22:25 UTC (rev 379)
@@ -15,6 +15,10 @@
 	set options(toolwindow_exist) 0
 	
 	::msgcat::mcload [file join $options(path) msgs]
+}
+
+proc tastebin::initCustomOptions { } {
+	variable options
 	
 	custom::defgroup Plugins \
 		[::msgcat::mc "Plugins options."] \
@@ -32,22 +36,44 @@
 		[::msgcat::mc "Save history to file"] \
 		-group Tastebin -type boolean
 		
-	if { [lsearch -exact [wm attributes .] -topmost] >= 0 } {
+	custom::defgroup [::msgcat::mc "Tastebin autopost"] \
+		[::msgcat::mc "Tastebin autopost options"] \
+			-group Tastebin	
+		
+	custom::defvar options(autopost_enable) 1 \
+		[::msgcat::mc "Enable autopost for your messages"] \
+		-group [::msgcat::mc "Tastebin autopost"] -type boolean
+		
+	custom::defvar options(max_symbol_numbers) 500 \
+			[::msgcat::mc "Max symbols in your message for normal \
+			sending, else - autopost to pastebin"] \
+			-type string -group [::msgcat::mc "Tastebin autopost"]
+			
+	hook::add chat_send_message_hook \
+		[namespace current]::handle_command
+			
+	hook::add generate_completions_hook \
+		[namespace current]::command_comps	
+		
+		
+	if { [optionExist topmost] } {
 		custom::defvar options(topmost) 1 \
 			[::msgcat::mc "Show on top of all windows"] \
-				-group Tastebin -type boolean
-		set options(topmost_exist) 1
+			-group Tastebin -type boolean
 	}
 	
-	if { [lsearch -exact [wm attributes .] -toolwindow] >= 0 } {
-		custom::defvar options(toolwindow) 1 \
-			[::msgcat::mc "Use a special display window"] \
-				-group Tastebin -type boolean
-		set options(toolwindow_exist) 1
+	if { [optionExist toolwindow] } {
+	custom::defvar options(toolwindow) 1 \
+		[::msgcat::mc "Use a special display window"] \
+		-group Tastebin -type boolean
 	}
 }
 
+proc tastebin::optionExist option {
+	return [expr {[lsearch -exact [wm attributes .] -$option] >= 0}]
+}
 
+
 proc tastebin::GetHighlights { } {
 	variable options
 	
@@ -88,11 +114,11 @@
 
 	toplevel .tastebin
 	
-	if {  $options(topmost_exist) } {
+	if { [optionExist topmost] } {
 		wm attributes .tastebin -topmost $options(topmost) 
 	}
 	
-	if {  $options(toolwindow_exist) } {
+	if { [optionExist toolwindow] } {
 		wm attributes .tastebin -toolwindow $options(toolwindow) 
 	}
 
@@ -252,19 +278,42 @@
 	if { [winfo exists $m] == 0 } {
 	
 		menu $m -tearoff 0
-				
+						
+		set map_small [set map_big {}]
+		set nomap {}
+
 		foreach name $options(highlightsNames) {
+			if { [set ix [lsearch -index 0 $map_small [string index $name 0]]] >= 0 } {
+				set lng [lindex $map_small $ix]
+				set map_small [lreplace $map_small $ix $ix]
+				lappend map_big $lng
+				lappend map_big [list [string index $name 0] $name]
+				lappend nomap [string index $name 0]
+			} else {
+				if { [lsearch -exact $nomap [string index $name 0]] < 0 } {
+					lappend map_small [list [string index $name 0] $name]
+				} else {
+					lappend map_big [list [string index $name 0] $name]
+				}
+			}
+		}
 		
-			set children $m.[string tolower [string index $name 0]]
-		
-			if { [winfo exist $children] == 0 } {
-				$m add cascade -menu $children \
-					-label "[string totitle [string index $name 0]]       "
-				menu $children -tearoff 0
+		set map_all [concat $map_small $map_big]
+
+		foreach name [lsort -ascii -nocase $map_all] {
+			if {[lsearch -exact $map_small $name] >= 0} {
+				$m add command -label [string totitle [lindex $name 1]] \
+					-command [list [namespace current]::ChoiseLangCallback [lindex $name 1]]
+			} else {
+				set children $m.[string tolower [lindex $name 0]]
+				if { [winfo exist $children] == 0 } {
+					$m add cascade -menu $children \
+						-label "[string totitle [lindex $name 0]]  ..."
+					menu $children -tearoff 0
+				}
+				$children add command -label [lindex $name 1] \
+					-command [list [namespace current]::ChoiseLangCallback [lindex $name 1]]
 			}
-			
-			$children add command -label $name \
-				-command [list [namespace current]::ChoiseLangCallback $name]
 		}
 	}
 	
@@ -333,7 +382,7 @@
 	set log [$w get 0.0 10.0]
 	
 	$w delete 0.0 end
-	$w insert 0.0 {Please wait ...}
+	$w insert 0.0 [::msgcat::mc "Please wait ..."]
 	$w configure -state disabled
 	
 	set post [http::formatQuery paste_code $code \
@@ -364,7 +413,7 @@
 	set date [clock format [clock seconds] -format \
 	$::plugins::options(delayed_timestamp_format)]
 	putHistory "$date\t[.tastebin.main_bar.lang get] - ${data}:\
-	 \n$log\n...\n[string repeat _ 20]\n\n"
+	 \n\n$log\n...\n[string repeat _ 20]\n\n"
 }
 
 
@@ -428,21 +477,87 @@
 }
 
 proc tastebin::create_buttons { } {
-	ifacetk::add_toolbar_button TastebinButton \
-		[namespace current]::SwitchState "Tastebin"
+	set com [subst [namespace current]::SwitchState]
+	
+	ifacetk::add_toolbar_button \
+		TastebinButton $com \
+		[::msgcat::mc "Tastebin"] 
 		
 	[.mainframe getmenu services] insert \
 		[::msgcat::mc "Plugins"] separator
 		
 	[.mainframe getmenu services] insert \
 		[::msgcat::mc "Plugins"] command \
-		-label Tastebin \
-		-command [namespace current]::SwitchState]
+		-label [::msgcat::mc "Tastebin"] -command $com
 }
 
-namespace eval tastebin {
+proc tastebin::command_comps {chatid compsvar wordstart line} {
+    upvar 0 $compsvar comps
+
+    if { $wordstart == 0 } {
+		lappend comps {/+p } {/-p }
+    }
+}
+
+proc tastebin::handle_command {chatid user body type} {
 	variable options
 	
+	if { [string match {/+p*} $body] } {
+		set com post
+	} elseif { [string match {/-p*} $body] } {
+		return stop
+	} elseif { $options(autopost_enable) && \
+		[string length $body] >= \
+			$options(max_symbol_numbers) } {
+				set com big
+	} else {
+		return
+	}
+	
+	set tab \n[string repeat _ 40]\n
+	
+	if { $com eq "post" } {
+		set body [string range $body 4 end]
+	}
+	
+	if { [string length $body] < 10 } {
+		show info $chatid $tab[::msgcat::mc "The number of characters can not be less than 10"]$tab
+		return stop
+	}
+	
+	if { $com eq "big" } {
+		show error $chatid $tab[::msgcat::mc "Your message are exceeding limit"]$tab
+	}
+		
+	show info $chatid $tab[::msgcat::mc "Please wait ..."]$tab
+	
+	set url [sendFromLimit $body]
+	
+	show error $chatid $tab$url$tab
+	return stop
+}
+
+proc tastebin::sendFromLimit code {
+	set url "http://pastebin.com/api_public.php"
+	set name "Tastebin - Tkabber Plugin"
+	set lang text
+	set post [http::formatQuery paste_code $code \
+		paste_format $lang paste_name $name]
+	set token [http::geturl $url -query $post]
+	set data [http::data $token]
+	http::cleanup $token
+	return $data
+}
+
+proc tastebin::show { type chatid msg } {
+    set jid [chat::get_jid $chatid]
+    set cw [chat::chat_win $chatid]
+
+    chat::add_message $chatid $jid $type $msg {}
+}
+
+namespace eval tastebin {
+	initCustomOptions
 	GetHighlights
 		
 	image create photo TastebinButton -file \
@@ -450,5 +565,6 @@
 		
 	hook::add finload_hook \
 		[namespace current]::create_buttons
+	
 }
 	
\ No newline at end of file



More information about the Tkabber-dev mailing list