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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Tue Aug 24 18:44:15 MSD 2010


Author: Rejjin
Date: 2010-08-24 18:44:15 +0400 (Tue, 24 Aug 2010)
New Revision: 368

Added:
   trunk/plugins/tastebin/tastebin.tcl
Removed:
   trunk/plugins/tastebin/Tastebin.tcl
Log:


Deleted: trunk/plugins/tastebin/Tastebin.tcl
===================================================================
--- trunk/plugins/tastebin/Tastebin.tcl	2010-08-24 14:42:30 UTC (rev 367)
+++ trunk/plugins/tastebin/Tastebin.tcl	2010-08-24 14:44:15 UTC (rev 368)
@@ -1,309 +0,0 @@
-
-namespace eval tastebin {
-	variable options
-	
-	set options(path) [file dirname [info script]]
-	
-	lappend ::auto_path [file join $options(path) ListPopup]
-	
-	package require http
-	package require msgcat
-	package require ListPopup
-	
-	::msgcat::mcload [file join $options(path) msgs]
-	
-	custom::defgroup Plugins \
-		[::msgcat::mc "Plugins options."] \
-			-group Tkabber	
-	
-    custom::defgroup Tastebin \
-		[::msgcat::mc "Tastebin options"] \
-			-group Plugins	
-	
-	custom::defvar options(default,name) [::msgcat::mc "Your name or nick"] \
-		[::msgcat::mc "Your name or nick (Default name - \"Tastebin - Tkabber Plugin\")"] \
-		-group Tastebin -type string
-	
-	custom::defvar options(toolwindow) 1 \
-		[::msgcat::mc "Use a special display window"] \
-		-group Tastebin -type boolean
-		
-	custom::defvar options(topmost) 1 \
-		[::msgcat::mc "Show on top of all windows"] \
-		-group Tastebin -type boolean
-	
-	custom::defvar options(save_last_lang) 1 \
-		[::msgcat::mc "Use the priority to generate a list of highlights syntax"] \
-		-group Tastebin -type boolean
-		
-	custom::defvar options(listbox_size) 15 \
-		[::msgcat::mc "Size of popup menu"] \
-		-group Tastebin -type string
-}
-
-proc tastebin::GetHighlights { } {
-	variable options
-	
-	set chan [open [file join $options(path) highlights] RDONLY]
-	
-	while { [eof $chan] == 0 } {
-		gets $chan line
-		lappend options(highlightsNames) [lindex $line 0]
-		lappend options(highlights) [lindex $line 1]
-	}
-	
-	close $chan
-}
-
-proc tastebin::_OptionExist attribute {
-	if { "-$attribute" in [wm attributes .tastebin] } { 
-		return 1 
-	} 
-	return -1
-}
-
-
-proc tastebin::SwitchState { } {
-	if { [winfo exist .tastebin] == 0 } {
-		return [CreateWindow]
-	}
-	
-	if { [wm state .tastebin] eq "normal" } {
-		return [wm state .tastebin withdraw]
-	}
-	
-	wm state .tastebin normal
-}
-
-
-proc tastebin::CreateWindow { } {
-	variable options
-	
-	if { [winfo exist .tastebin] } { 
-		destroy .tastebin 
-	}
-	
-	GetHighlights
-
-	toplevel .tastebin
-	
-	foreach option { toolwindow topmost } {
-		if { [_OptionExist $option] } {
-			wm attributes .tastebin -$option $options(toolwindow)
-		}
-	}
-	
-	wm title .tastebin "Tastebin"
-	wm resizable .tastebin 0 0
-	
-	frame .tastebin.send_bar \
-		-relief ridge -pady 3 -width 500
-	
-	entry .tastebin.send_bar.lang \
-		-state readonly -cursor arrow
-		
-	::ListPopup::for .tastebin.send_bar.lang \
-		[namespace current]::options(highlightsNames) \
-		[namespace current]::ChoiseLangCallback \
-		$options(listbox_size)
-		
-	button .tastebin.send_bar.send \
-		-text [msgcat::mc Send] -command [namespace current]::Send
-		
-	pack .tastebin.send_bar \
-		-padx 3 -pady 2 -expand 1 -fill x
-		
-	pack .tastebin.send_bar.lang .tastebin.send_bar.send \
-		-padx 4 -side left -fill x -expand 1
-	
-	initEntry .tastebin.send_bar.lang [msgcat::mc "Syntax Highlighting"]
-	
-	frame .tastebin.main_bar \
-		-relief ridge -pady 3 -width 500
-		
-	entry .tastebin.main_bar.header \
-		-state disabled
-		
-	text .tastebin.main_bar.txt \
-		-yscrollcommand [list .tastebin.main_bar.ys set] \
-		-maxundo 0 -undo true -wrap word
-		
-	scrollbar .tastebin.main_bar.ys \
-		-command [list .tastebin.main_bar.txt yview]
-	
-	pack .tastebin.main_bar \
-		-padx 3  -pady 2
-	
-	pack .tastebin.main_bar.header \
-		-fill x -pady 2
-	
-	pack .tastebin.main_bar.txt .tastebin.main_bar.ys \
-	-pady 4 -side left -fill y
-	
-	initEntry .tastebin.main_bar.header $options(default,name)
-	
-	bind .tastebin.main_bar.header <1> {
-		.tastebin.main_bar.header configure -state normal
-		.tastebin.main_bar.header delete 0 end
-		set [namespace current]::options(choised,name) 1
-	}
-	
-	frame .tastebin.options_bar \
-		-relief ridge -bd 2 -pady 3
-	
-	button .tastebin.options_bar.clean \
-		-text [msgcat::mc Clean] -command [namespace current]::delContent
-		
-	button .tastebin.options_bar.history \
-		-text [msgcat::mc History] \
-		-command [list [namespace current]::history .tastebin.main_bar.txt]
-	
-	button .tastebin.options_bar.close \
-		-text [msgcat::mc Close] -command { destroy .tastebin }
-	
-	pack .tastebin.options_bar \
-		-padx 3 -pady 2 -expand 1 -fill x
-		
-	pack .tastebin.options_bar.clean \
-		.tastebin.options_bar.history \
-		.tastebin.options_bar.close \
-		 -padx 4 -side left -fill x -expand 1
-	
-}
-
-
-proc tastebin::initEntry { w text } {
-	set oldState [$w cget -state]
-	$w configure -state normal
-	$w delete 0 end
-	$w insert end $text
-	$w configure -state $oldState
-}
-
-
-proc tastebin::ChoiseLangCallback value {
-	variable options
-	.tastebin.send_bar.lang configure -state normal
-	.tastebin.send_bar.lang delete 0 end
-	.tastebin.send_bar.lang insert 0 $value
-	.tastebin.send_bar.lang configure -state readonly
-	set options(choised,lang) 1
-}
-	
-	
-proc tastebin::GetTrueLang old_lang {
-	variable options
-	if { [set ix [lsearch -exact $options(highlightsNames) $old_lang]] >= 0 } {
-		return [lindex  $options(highlights) $ix]
-	} 
-	return text
-}
-
-
-proc tastebin::SetLastLang { lang name } {
-	variable options 
-	
-	if { $options(save_last_lang) == 0 } {
-		return
-	}
-	
-	set options(highlightsNames) [linsert $options(highlightsNames) 0 $name]
-	set options(highlights) [linsert $options(highlights) 0 $lang]
-}
-
-
-proc tastebin::Send { } {
-	variable options 
-	
-	set url "http://pastebin.com/api_public.php"
-	set w ".tastebin.main_bar.txt"
-	
-	set code [$w get 0.0 end]
-	if { [string length $code] < 5 } {
-		return [infoMessage \
-			[::msgcat::mc "Empty string."] \
-				[::msgcat::mc "Error"] warning]
-	}	
-	
-	if { [info exist options(choised,name)] && $options(choised,name) == 0 } {
-		set name "Tastebin - Tkabber Plugin"
-	} else {
-		set name [.tastebin.main_bar.header get]
-	}
-	
-	if { [info exist options(choised,lang)] && $options(choised,lang) == 0 } {
-		set lang text
-	} else {
-		set lang [GetTrueLang [.tastebin.send_bar.lang get]]
-	}
-	
-	SetLastLang $lang [.tastebin.send_bar.lang get]
-	
-	$w delete 0.0 end
-	$w insert 0.0 {Please wait ...}
-	$w configure -state disabled
-	
-	set post [http::formatQuery paste_code $code \
-		paste_format $lang paste_name $name]
-	
-		set token [http::geturl $url -query $post \
-			-command [list [namespace current]::TransComplite $w]]
-		http::wait $token
-}
-			
-proc tastebin::TransComplite { w token } {
-	variable options 
-	
-	if { [http::status $token] ne "ok" } {
-		$w configure -state normal
-		$w delete 0.0 end
-		$w insert 0.0 "Error"
-		return [http::cleanup $token]
-	}
-	
-	set data [http::data $token]
-	
-	$w configure -state normal
-	$w delete 0.0 end
-	$w insert 0.0 $data
-	http::cleanup $token
-	
-	lappend options(history) "\[[clock format [clock seconds] -format "%R %p %D"]\] $data"
-}
-
-
-proc tastebin::infoMessage { msg {title Info} {type info} } {
-	tk_messageBox -default ok \
-		-message $msg -title $title \
-		-icon $type -type ok
-}
-
-
-proc tastebin::delContent { {w .tastebin.main_bar.txt} } {
-	$w delete 0.0 end
-}
-
-
-proc tastebin::history w {
-	variable options
-	
-	if { [info exist options(history)] == 0 } {
-		return
-	}
-	
-	delContent
-	$w insert 0.0 [join $options(history) \n]
-}
-
-
-namespace eval tastebin {
-	variable options
-	
-	hook::add finload_hook [list \
-		ifacetk::add_toolbar_button \
-			[image create photo -file \
-			[file join $options(path) image toolbar_icon.gif]] \
-				[namespace current]::SwitchState \
-					"Tastebin"]
-}
-	
\ No newline at end of file

Copied: trunk/plugins/tastebin/tastebin.tcl (from rev 367, trunk/plugins/tastebin/Tastebin.tcl)
===================================================================
--- trunk/plugins/tastebin/tastebin.tcl	                        (rev 0)
+++ trunk/plugins/tastebin/tastebin.tcl	2010-08-24 14:44:15 UTC (rev 368)
@@ -0,0 +1,309 @@
+
+namespace eval tastebin {
+	variable options
+	
+	set options(path) [file dirname [info script]]
+	
+	lappend ::auto_path [file join $options(path) ListPopup]
+	
+	package require http
+	package require msgcat
+	package require ListPopup
+	
+	::msgcat::mcload [file join $options(path) msgs]
+	
+	custom::defgroup Plugins \
+		[::msgcat::mc "Plugins options."] \
+			-group Tkabber	
+	
+    custom::defgroup Tastebin \
+		[::msgcat::mc "Tastebin options"] \
+			-group Plugins	
+	
+	custom::defvar options(default,name) [::msgcat::mc "Your name or nick"] \
+		[::msgcat::mc "Your name or nick (Default name - \"Tastebin - Tkabber Plugin\")"] \
+		-group Tastebin -type string
+	
+	custom::defvar options(toolwindow) 1 \
+		[::msgcat::mc "Use a special display window"] \
+		-group Tastebin -type boolean
+		
+	custom::defvar options(topmost) 1 \
+		[::msgcat::mc "Show on top of all windows"] \
+		-group Tastebin -type boolean
+	
+	custom::defvar options(save_last_lang) 1 \
+		[::msgcat::mc "Use the priority to generate a list of highlights syntax"] \
+		-group Tastebin -type boolean
+		
+	custom::defvar options(listbox_size) 15 \
+		[::msgcat::mc "Size of popup menu"] \
+		-group Tastebin -type string
+}
+
+proc tastebin::GetHighlights { } {
+	variable options
+	
+	set chan [open [file join $options(path) highlights] RDONLY]
+	
+	while { [eof $chan] == 0 } {
+		gets $chan line
+		lappend options(highlightsNames) [lindex $line 0]
+		lappend options(highlights) [lindex $line 1]
+	}
+	
+	close $chan
+}
+
+proc tastebin::_OptionExist attribute {
+	if { "-$attribute" in [wm attributes .tastebin] } { 
+		return 1 
+	} 
+	return -1
+}
+
+
+proc tastebin::SwitchState { } {
+	if { [winfo exist .tastebin] == 0 } {
+		return [CreateWindow]
+	}
+	
+	if { [wm state .tastebin] eq "normal" } {
+		return [wm state .tastebin withdraw]
+	}
+	
+	wm state .tastebin normal
+}
+
+
+proc tastebin::CreateWindow { } {
+	variable options
+	
+	if { [winfo exist .tastebin] } { 
+		destroy .tastebin 
+	}
+	
+	GetHighlights
+
+	toplevel .tastebin
+	
+	foreach option { toolwindow topmost } {
+		if { [_OptionExist $option] } {
+			wm attributes .tastebin -$option $options(toolwindow)
+		}
+	}
+	
+	wm title .tastebin "Tastebin"
+	wm resizable .tastebin 0 0
+	
+	frame .tastebin.send_bar \
+		-relief ridge -pady 3 -width 500
+	
+	entry .tastebin.send_bar.lang \
+		-state readonly -cursor arrow
+		
+	::ListPopup::for .tastebin.send_bar.lang \
+		[namespace current]::options(highlightsNames) \
+		[namespace current]::ChoiseLangCallback \
+		$options(listbox_size)
+		
+	button .tastebin.send_bar.send \
+		-text [msgcat::mc Send] -command [namespace current]::Send
+		
+	pack .tastebin.send_bar \
+		-padx 3 -pady 2 -expand 1 -fill x
+		
+	pack .tastebin.send_bar.lang .tastebin.send_bar.send \
+		-padx 4 -side left -fill x -expand 1
+	
+	initEntry .tastebin.send_bar.lang [msgcat::mc "Syntax Highlighting"]
+	
+	frame .tastebin.main_bar \
+		-relief ridge -pady 3 -width 500
+		
+	entry .tastebin.main_bar.header \
+		-state disabled
+		
+	text .tastebin.main_bar.txt \
+		-yscrollcommand [list .tastebin.main_bar.ys set] \
+		-maxundo 0 -undo true -wrap word
+		
+	scrollbar .tastebin.main_bar.ys \
+		-command [list .tastebin.main_bar.txt yview]
+	
+	pack .tastebin.main_bar \
+		-padx 3  -pady 2
+	
+	pack .tastebin.main_bar.header \
+		-fill x -pady 2
+	
+	pack .tastebin.main_bar.txt .tastebin.main_bar.ys \
+	-pady 4 -side left -fill y
+	
+	initEntry .tastebin.main_bar.header $options(default,name)
+	
+	bind .tastebin.main_bar.header <1> {
+		.tastebin.main_bar.header configure -state normal
+		.tastebin.main_bar.header delete 0 end
+		set [namespace current]::options(choised,name) 1
+	}
+	
+	frame .tastebin.options_bar \
+		-relief ridge -bd 2 -pady 3
+	
+	button .tastebin.options_bar.clean \
+		-text [msgcat::mc Clean] -command [namespace current]::delContent
+		
+	button .tastebin.options_bar.history \
+		-text [msgcat::mc History] \
+		-command [list [namespace current]::history .tastebin.main_bar.txt]
+	
+	button .tastebin.options_bar.close \
+		-text [msgcat::mc Close] -command { destroy .tastebin }
+	
+	pack .tastebin.options_bar \
+		-padx 3 -pady 2 -expand 1 -fill x
+		
+	pack .tastebin.options_bar.clean \
+		.tastebin.options_bar.history \
+		.tastebin.options_bar.close \
+		 -padx 4 -side left -fill x -expand 1
+	
+}
+
+
+proc tastebin::initEntry { w text } {
+	set oldState [$w cget -state]
+	$w configure -state normal
+	$w delete 0 end
+	$w insert end $text
+	$w configure -state $oldState
+}
+
+
+proc tastebin::ChoiseLangCallback value {
+	variable options
+	.tastebin.send_bar.lang configure -state normal
+	.tastebin.send_bar.lang delete 0 end
+	.tastebin.send_bar.lang insert 0 $value
+	.tastebin.send_bar.lang configure -state readonly
+	set options(choised,lang) 1
+}
+	
+	
+proc tastebin::GetTrueLang old_lang {
+	variable options
+	if { [set ix [lsearch -exact $options(highlightsNames) $old_lang]] >= 0 } {
+		return [lindex  $options(highlights) $ix]
+	} 
+	return text
+}
+
+
+proc tastebin::SetLastLang { lang name } {
+	variable options 
+	
+	if { $options(save_last_lang) == 0 } {
+		return
+	}
+	
+	set options(highlightsNames) [linsert $options(highlightsNames) 0 $name]
+	set options(highlights) [linsert $options(highlights) 0 $lang]
+}
+
+
+proc tastebin::Send { } {
+	variable options 
+	
+	set url "http://pastebin.com/api_public.php"
+	set w ".tastebin.main_bar.txt"
+	
+	set code [$w get 0.0 end]
+	if { [string length $code] < 5 } {
+		return [infoMessage \
+			[::msgcat::mc "Empty string."] \
+				[::msgcat::mc "Error"] warning]
+	}	
+	
+	if { [info exist options(choised,name)] && $options(choised,name) == 0 } {
+		set name "Tastebin - Tkabber Plugin"
+	} else {
+		set name [.tastebin.main_bar.header get]
+	}
+	
+	if { [info exist options(choised,lang)] && $options(choised,lang) == 0 } {
+		set lang text
+	} else {
+		set lang [GetTrueLang [.tastebin.send_bar.lang get]]
+	}
+	
+	SetLastLang $lang [.tastebin.send_bar.lang get]
+	
+	$w delete 0.0 end
+	$w insert 0.0 {Please wait ...}
+	$w configure -state disabled
+	
+	set post [http::formatQuery paste_code $code \
+		paste_format $lang paste_name $name]
+	
+		set token [http::geturl $url -query $post \
+			-command [list [namespace current]::TransComplite $w]]
+		http::wait $token
+}
+			
+proc tastebin::TransComplite { w token } {
+	variable options 
+	
+	if { [http::status $token] ne "ok" } {
+		$w configure -state normal
+		$w delete 0.0 end
+		$w insert 0.0 "Error"
+		return [http::cleanup $token]
+	}
+	
+	set data [http::data $token]
+	
+	$w configure -state normal
+	$w delete 0.0 end
+	$w insert 0.0 $data
+	http::cleanup $token
+	
+	lappend options(history) "\[[clock format [clock seconds] -format "%R %p %D"]\] $data"
+}
+
+
+proc tastebin::infoMessage { msg {title Info} {type info} } {
+	tk_messageBox -default ok \
+		-message $msg -title $title \
+		-icon $type -type ok
+}
+
+
+proc tastebin::delContent { {w .tastebin.main_bar.txt} } {
+	$w delete 0.0 end
+}
+
+
+proc tastebin::history w {
+	variable options
+	
+	if { [info exist options(history)] == 0 } {
+		return
+	}
+	
+	delContent
+	$w insert 0.0 [join $options(history) \n]
+}
+
+
+namespace eval tastebin {
+	variable options
+	
+	hook::add finload_hook [list \
+		ifacetk::add_toolbar_button \
+			[image create photo -file \
+			[file join $options(path) image toolbar_icon.gif]] \
+				[namespace current]::SwitchState \
+					"Tastebin"]
+}
+	
\ No newline at end of file


Property changes on: trunk/plugins/tastebin/tastebin.tcl
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/plugins-0.11.1/Tastebin/Tastebin.tcl:208



More information about the Tkabber-dev mailing list