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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Sep 29 19:30:13 MSD 2010


Author: Rejjin
Date: 2010-09-29 19:30:13 +0400 (Wed, 29 Sep 2010)
New Revision: 411

Modified:
   trunk/plugins/tastebin/tastebin.tcl
Log:
Command-label moved to header of menu 
right-click mouse button.
Fixed bug with deleting first symbol.
Command /post replaced /paste
Added support paste with highlight.
New commands:
/paste langs -- Show all langs
/paste <text> -- post a text
/-paste <text> -- don't post a text
Examples for paste with highlight:
  /paste Tcl puts "Hello, world!"
  /paste M68000 Assembler Hello!
  /paste python TestTestTest! 

Modified: trunk/plugins/tastebin/tastebin.tcl
===================================================================
--- trunk/plugins/tastebin/tastebin.tcl	2010-09-29 14:22:48 UTC (rev 410)
+++ trunk/plugins/tastebin/tastebin.tcl	2010-09-29 15:30:13 UTC (rev 411)
@@ -47,7 +47,7 @@
 	hook::add finload_hook ${NS}::handle
 	hook::add chat_send_message_hook ${NS}::handle_command	
 	hook::add generate_completions_hook ${NS}::command_comps
-	hook::add chat_win_popup_menu_hook ${NS}::popup_menu
+	hook::add chat_win_popup_menu_hook ${NS}::popup_menu 1
 }
 
 
@@ -554,25 +554,44 @@
 
 proc tastebin::command_comps {chatid compsvar wordstart line} {
     upvar 0 $compsvar comps
-    if {!$wordstart} { lappend comps {/post } {/-post} }
+    if {!$wordstart} { lappend comps {/paste } {/-paste} {/paste langs}}
 }
 
 proc tastebin::handle_command {chatid user body type} {
 	variable options
+	variable highlights
 	
-	if {[string match {/post*} $body]} {
+	if {[string match {/paste langs*} $body]} {
+		show info  $chatid [join $highlights(names) "     |     "]
+		return -code break
+	}
+	
+	if {[string match {/paste*} $body]} {
 		if {[string length $body] < 10} {
 			show error $chatid [::msgcat::mc "Too many chars"]
 			return -code break
 		} else {
-			set out [post_message [string range $body 7 end]]
+		
+			set lang text
+			foreach name $highlights(names) {
+				set len [string length $name]
+				set tname [string tolower $name]
+				set tbody [string range [string tolower $body] 7 end]
+				if [string equal -length $len $tname $tbody] {
+					show info $chatid  ">>> $name"
+					set lang [get_lang_code $name]
+					set body [string range $body $len end]
+				}
+			}
+			
+			set out [post_message [string range $body 7 end] $lang]
 			show info $chatid " >>> $out"
 			add_history "[get_time]\t${out}[string repeat _ 20]\n\n"
 			return -code break
 		}
 	}
 	
-	if {[string match {/-post*} $body]} {
+	if {[string match {/-paste*} $body]} {
 		return 
 	}
 	
@@ -592,11 +611,11 @@
 	}
 }
 	
-proc tastebin::post_message { body } {
+proc tastebin::post_message { body {lang text}} {
 	set url "http://pastebin.com/api_public.php"
 	set name "Tastebin - Tkabber Plugin"
 	set post [http::formatQuery paste_code $body \
-		paste_format text paste_name $name]
+		paste_format $lang paste_name $name]
 	set token [http::geturl $url -query $post]
 	set data [http::data $token]
 	http::cleanup $token
@@ -634,6 +653,7 @@
 		$m add command \
 			-label [::msgcat::mc "Show pastebin content"] \
 			-command [list ${NS}::get_pastebin_url $url]
+		$m add separator
 	}
 }
 



More information about the Tkabber-dev mailing list