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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Wed Aug 25 02:22:02 MSD 2010


Author: Rejjin
Date: 2010-08-25 02:22:02 +0400 (Wed, 25 Aug 2010)
New Revision: 370

Added:
   trunk/plugins/tastebin/
   trunk/plugins/tastebin/highlights
   trunk/plugins/tastebin/image/
   trunk/plugins/tastebin/image/toolbar_icon.gif
   trunk/plugins/tastebin/msgs/
   trunk/plugins/tastebin/msgs/ru.msg
   trunk/plugins/tastebin/tastebin.tcl
Log:
Reworked version of the plugin Tastebin.
Removed package ListPopup, code moved to tastebin.tcl

Added: trunk/plugins/tastebin/highlights
===================================================================
--- trunk/plugins/tastebin/highlights	                        (rev 0)
+++ trunk/plugins/tastebin/highlights	2010-08-24 22:22:02 UTC (rev 370)
@@ -0,0 +1,138 @@
+ActionScript actionscript
+{ActionScript 3} actionscript3
+Ada ada
+{Apache Log} apache
+AppleScript applescript
+{APT Sources} apt_sources
+{ASM (NASM)} asm
+ASP asp
+AutoIt autoit
+Avisynth avisynth
+Bash bash
+Basic4GL basic4gl
+BibTeX bibtex
+{Blitz Basic} blitzbasic
+BNF bnf
+BOO boo
+BrainFuck bf
+C c
+{C for Macs} c_mac
+{C Intermediate Language} cill
+C# csharp
+C++ cpp
+{CAD DCL} caddcl
+{CAD Lisp} cadlisp
+CFDG cfdg
+{Clone C} klonec
+{Clone C++} klonecpp
+CMake cmake
+COBOL cobol
+ColdFusion cfm
+CSS css
+D d
+DCS dcs
+Delphi delphi
+Diff dff
+DIV div
+DOS dos
+DOT dot
+Eiffel eiffel
+Email email
+Erlang erlang
+{FO Language} fo
+Fortran fortran
+FreeBasic freebasic
+{Game Maker} gml
+Genero genero
+GetText gettext
+Groovy groovy
+Haskell haskell
+{HQ9 Plus} hq9plus
+HTML html4strict
+IDL idl
+{INI file} ini
+{Inno Script} inno
+INTERCAL intercal
+IO io
+Java java
+{Java 5} java5
+JavaScript javascript
+KiXtart kixtart
+Latex latex
+{Linden Scripting} lsl2
+Lisp lisp
+{Loco Basic} locobasic
+{LOL Code} lolcode
+{Lotus Formulas} lotusformulas
+{Lotus Script} lotusscript
+LScript lscript
+Lua lua
+{M68000 Assembler} m68k
+Make make
+MatLab matlab
+mIRC mirc
+{Modula 3} modula3
+MPASM mpasm
+MXML mxml
+MySQL mysql
+None text
+{NullSoft Installer} nsis
+{Oberon 2} oberon2
+{Objective C} objc
+{OCalm Brief} ocaml-brief
+OCaml ocaml
+{OpenGL Shading} glsl
+{Openoffice BASIC} oobas
+{Oracle 11} oracle11
+{Oracle 8} oracle8
+Pascal pascal
+PAWN pawn
+Per per
+Perl perl
+PHP php
+{PHP Brief} php-brief
+{Pic 16} pic16
+{Pixel Bender} pixelbender
+PL/SQL plsql
+POV-Ray povray
+{Power Shell} powershell
+Progress progress
+Prolog prolog
+Properties properties
+ProvideX providex
+Python python
+QBasic qbasic
+Rails rails
+REBOL rebol
+REG reg
+Robots robots
+Ruby ruby
+{Ruby Gnuplot} gnuplot
+SAS sas
+Scala scala
+Scheme scheme
+Scilab scilab
+SdlBasic sdlbasic
+Smalltalk smalltalk
+Smarty smarty
+SQL sql
+T-SQL tsql
+TCL tcl
+{Tera Term} teraterm
+thinBasic thinbasic
+TypoScript typoscript
+unrealScript unreal
+VB.NET vbnet
+VeriLog verilog
+VHDL vhdl
+VIM vim
+Visual Pro Log visualprolog
+VisualBasic vb
+VisualFoxPro visualfoxpro
+WhiteSpace whitespace
+WHOIS whois
+{Win Batch} winbatch
+XML xml
+{Xorg Config} xorg_conf
+XPP xpp
+{Z80 Assembler} z80
\ No newline at end of file

Added: trunk/plugins/tastebin/image/toolbar_icon.gif
===================================================================
(Binary files differ)


Property changes on: trunk/plugins/tastebin/image/toolbar_icon.gif
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/plugins/tastebin/msgs/ru.msg
===================================================================
--- trunk/plugins/tastebin/msgs/ru.msg	                        (rev 0)
+++ trunk/plugins/tastebin/msgs/ru.msg	2010-08-24 22:22:02 UTC (rev 370)
@@ -0,0 +1,15 @@
+::msgcat::mcset ru "Syntax Highlighting" "Подсветка синтаксиса"
+::msgcat::mcset ru  "Your name or nick" "Ваше имя или ник"
+::msgcat::mcset ru "Empty string." "Пустая строка."
+::msgcat::mcset ru "Error" "Ошибка"
+::msgcat::mcset ru "Send" "Отправить"
+::msgcat::mcset ru "Clean" "Очистить"
+::msgcat::mcset ru "Close" "Закрыть"
+::msgcat::mcset ru "History" "История"
+::msgcat::mcset ru "Tastebin options" "Tastebin-настройки"
+::msgcat::mcset ru "Show on top of all windows" "Отображать поверх всех окон"
+::msgcat::mcset ru "Your name or nick (Default name - \"Tastebin - Tkabber Plugin\")" "Ваше имя или ник. (Имя по-умолчанию - \"Tastebin - Tkabber Plugin\")"
+::msgcat::mcset ru "Use a special display window" "Использовать специальное отображение окна"
+::msgcat::mcset ru "Use the priority to generate a list of highlights syntax" "Использовать приоритетную генерацию списка подсветок синтаксиса"
+::msgcat::mcset ru "Size of popup menu" "Высота всплывающего меню"
+::msgcat::mcset ru "Save state" "Сохранять состояние"
\ No newline at end of file

Added: trunk/plugins/tastebin/tastebin.tcl
===================================================================
--- trunk/plugins/tastebin/tastebin.tcl	                        (rev 0)
+++ trunk/plugins/tastebin/tastebin.tcl	2010-08-24 22:22:02 UTC (rev 370)
@@ -0,0 +1,443 @@
+#	Tastebin - pastebin.com uploader plugin
+#	Written by Renji
+#	xmpp: rejjin at jabber.dk
+#	e-mail: webrenji at gmail.com
+
+package require http
+package require msgcat
+
+namespace eval tastebin {
+	variable options
+	
+	set options(path) [file dirname [info script]]
+	
+	::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(save_state) 0 \
+		[::msgcat::mc "Save state"] \
+		-group Tastebin -type boolean
+	
+	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
+}
+
+
+namespace eval tastebin::balloon { 
+	variable state 
+}
+
+
+proc tastebin::GetHighlights { } {
+	variable options
+	
+	set chan [open [file join $options(path) highlights] RDONLY]
+	
+	lappend options(highlightsNames) None
+	lappend options(highlights) text
+	
+	while { [eof $chan] == 0 } {
+		gets $chan line
+		lappend options(highlightsNames) [lindex $line 0]
+		lappend options(highlights) [lindex $line 1]
+	}
+	
+	close $chan
+}
+
+
+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
+	
+	if { [lsearch -exact [wm attributes .tastebin] -topmost] >= 0 } {
+		wm attributes .tastebin -topmost $options(topmost) 
+	}
+	
+	if { [lsearch -exact [wm attributes .tastebin] -toolwindow] >= 0 } {
+		wm attributes .tastebin -topmost $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
+		
+	[namespace current]::balloon::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 [list [namespace current]::Close]
+	
+	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::Close { } {
+	variable options
+	
+	if { $options(save_state) == 1 } {
+		return [SwitchState]
+	}
+	
+	destroy .tastebin
+}
+
+
+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
+	}
+		
+	lset options(highlightsNames) 0 $name
+	lset 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]
+}
+
+# Balloon
+
+proc tastebin::balloon::toPath w {
+	return [string map {. _} $w]
+}
+
+proc tastebin::balloon::for { win listvar cmd height } {
+	variable state
+
+	set state(w,$win) .pastebin_balloon_[toPath $win]
+	set state(balloon,$win,listvar) $listvar
+	set state(balloon,$win,cmd) $cmd
+	
+	RegisterBalloon $win
+	CreateBalloon $win $height
+	
+    bind $win <Enter> [list [namespace current]::BalloonPending %W $win]
+	bind $state(w,$win).list <Leave> [list [namespace current]::BalloonCancel $win]
+}
+
+proc  tastebin::balloon::del win {
+	variable state
+	if { [isRegistredBalloon $win] } { 
+		unset state(registred,$win)
+	}
+}
+
+proc tastebin::balloon::CreateBalloon { win height } {
+	variable state
+	
+	if [winfo exist  $state(w,$win)] { 
+		destroy  $state(w,$win)
+	}
+	
+	toplevel  $state(w,$win) \
+		-borderwidth 0 -relief flat
+		
+	listbox  $state(w,$win).list \
+		-activestyle none \
+		-listvariable $state(balloon,$win,listvar) \
+		-height $height
+		
+	pack $state(w,$win).list \
+		-side left -fill y
+	
+	bind $state(w,$win).list <<ListboxSelect>> \
+		[list [namespace current]::ListboxPushed $win %W] 
+	
+	if { "-topmost" in [wm attributes $state(w,$win)] } {
+		wm attributes $state(w,$win) -topmost 1
+	}
+	
+	wm overrideredirect $state(w,$win) 1
+	wm withdraw $state(w,$win)
+}
+
+proc tastebin::balloon::ListboxPushed { win W } {
+	variable state
+	eval $state(balloon,$win,cmd) [list [$W get [$W curselection]]]
+	BalloonCancel $win
+}
+
+proc tastebin::balloon::BalloonPending { W win } {
+	variable state
+	
+	if { [isRegistredBalloon $win] == 0 } { 
+		return 
+	}
+	
+    BalloonCancel $W
+	
+    set state(pending,$win) \
+		[after 100 [list [namespace current]::BalloonShow $W]]
+}
+
+proc tastebin::balloon::BalloonCancel win {
+    variable state
+
+    if { [info exists state(pending,$win)] } {
+        after cancel $state(pending,$win)
+        unset state(pending,$win)
+    }
+    wm withdraw $state(w,$win)
+}
+
+proc tastebin::balloon::BalloonShow win {
+    variable state
+		
+	foreach {x y} [winfo pointerxy .] break
+	
+	wm geometry $state(w,$win) +[expr {$x - 20}]+[expr {$y - 20}]
+	wm deiconify $state(w,$win)
+	
+	raise $state(w,$win)
+	focus $state(w,$win).list
+	
+    catch { unset state(pending,$win) }
+}
+
+proc  tastebin::balloon::RegisterBalloon win {
+	variable state
+		if {[isRegistredBalloon $win]} { return }
+		lappend state(registred,$win) $win
+}
+
+proc  tastebin::balloon::isRegistredBalloon win {
+	variable state
+		if { [info exist state(registred,$win)] && \
+			$win in $state(registred,$win) } { 
+			return 1
+		}
+		return 0
+}
+
+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



More information about the Tkabber-dev mailing list