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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Aug 29 23:26:07 MSD 2010


Author: Rejjin
Date: 2010-08-29 23:26:07 +0400 (Sun, 29 Aug 2010)
New Revision: 374

Modified:
   trunk/plugins/tastebin/msgs/ru.msg
   trunk/plugins/tastebin/tastebin.tcl
Log:
Redesigned interface, ListPopup replaced by the menu. Files: tastebin.tcl, msgs/ru.msg

Modified: trunk/plugins/tastebin/msgs/ru.msg
===================================================================
--- trunk/plugins/tastebin/msgs/ru.msg	2010-08-29 17:12:03 UTC (rev 373)
+++ trunk/plugins/tastebin/msgs/ru.msg	2010-08-29 19:26:07 UTC (rev 374)
@@ -10,6 +10,4 @@
 ::msgcat::mcset ru "Show on top of all windows" "Отображать поверх всех окон"
 ::msgcat::mcset ru "Your name or nick" "Ваше имя или ник"
 ::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

Modified: trunk/plugins/tastebin/tastebin.tcl
===================================================================
--- trunk/plugins/tastebin/tastebin.tcl	2010-08-29 17:12:03 UTC (rev 373)
+++ trunk/plugins/tastebin/tastebin.tcl	2010-08-29 19:26:07 UTC (rev 374)
@@ -20,10 +20,6 @@
     custom::defgroup Tastebin \
 		[::msgcat::mc "Tastebin options"] \
 			-group Plugins	
-	
-	custom::defvar options(default,name) {} \
-		[::msgcat::mc "Your name or nick"] \
-		-group Tastebin -type string
 		
 	custom::defvar options(save_state) 0 \
 		[::msgcat::mc "Save state"] \
@@ -40,29 +36,16 @@
 	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
+	set options(highlightsNames) {}
+	set options(highlights) {}
 	
 	while { [eof $chan] == 0 } {
 		gets $chan line
@@ -87,15 +70,12 @@
 	wm state .tastebin normal
 }
 
-
 proc tastebin::CreateWindow { } {
 	variable options
 	
 	if { [winfo exist .tastebin] } { 
 		destroy .tastebin 
 	}
-	
-	GetHighlights
 
 	toplevel .tastebin
 	
@@ -110,31 +90,25 @@
 	wm title .tastebin "Tastebin"
 	wm resizable .tastebin 0 0
 	
-	frame .tastebin.send_bar \
+	frame .tastebin.main_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)
+	label .tastebin.main_bar.help_lang \
+		-text [::msgcat::mc "Syntax Highlighting"]
 		
-	button .tastebin.send_bar.send \
-		-text [msgcat::mc Send] -command [namespace current]::Send
+	entry .tastebin.main_bar.lang -state disabled
+	
+	pack .tastebin.main_bar.help_lang \
+		-anchor w 
 		
-	pack .tastebin.send_bar \
-		-padx 3 -pady 2 -expand 1 -fill x
+	pack .tastebin.main_bar.lang \
+		-fill x -pady 2
 		
-	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
+	bind .tastebin.main_bar.lang <1> [list [namespace current]::initMenu %X %Y]
 		
+	label .tastebin.main_bar.help_nick \
+		-text [::msgcat::mc "Your name or nick"]
+		
 	entry .tastebin.main_bar.header \
 		-state disabled
 		
@@ -148,14 +122,14 @@
 	pack .tastebin.main_bar \
 		-padx 3  -pady 2
 	
+	pack .tastebin.main_bar.help_nick -anchor w 
+	
 	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
@@ -164,7 +138,10 @@
 	
 	frame .tastebin.options_bar \
 		-relief ridge -bd 2 -pady 3
-	
+		
+	button .tastebin.options_bar.send \
+		-text [msgcat::mc Send] -command [namespace current]::Send
+		
 	button .tastebin.options_bar.clean \
 		-text [msgcat::mc Clean] -command [namespace current]::delContent
 		
@@ -178,11 +155,38 @@
 	pack .tastebin.options_bar \
 		-padx 3 -pady 2 -expand 1 -fill x
 		
-	pack .tastebin.options_bar.clean \
+	pack .tastebin.options_bar.send \
+		.tastebin.options_bar.clean \
 		.tastebin.options_bar.history \
 		.tastebin.options_bar.close \
-		 -padx 4 -side left -fill x -expand 1
+			-padx 4 -side left -fill x -expand 1
+}
+
+
+proc tastebin::initMenu { X Y } {
+	variable options
 	
+	set m .tastebin_popup_input
+	
+	if { [winfo exists $m] == 0 } {
+	
+		menu $m -tearoff 0
+				
+		foreach name $options(highlightsNames) {
+		
+			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
+			}
+			
+			$children add command -label $name \
+				-command [list [namespace current]::ChoiseLangCallback $name]
+		}
+	}
+	
+	tk_popup $m $X $Y
 }
 
 
@@ -196,22 +200,14 @@
 	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
+	
+	.tastebin.main_bar.lang configure -state normal
+	.tastebin.main_bar.lang delete 0 end
+	.tastebin.main_bar.lang insert 0 $value
+	.tastebin.main_bar.lang configure -state readonly
+	
 	set options(choised,lang) 1
 }
 	
@@ -225,18 +221,6 @@
 }
 
 
-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 
 	
@@ -244,6 +228,7 @@
 	set w ".tastebin.main_bar.txt"
 	
 	set code [$w get 0.0 end]
+	
 	if { [string length $code] < 5 } {
 		return [infoMessage \
 			[::msgcat::mc "Empty string."] \
@@ -260,11 +245,9 @@
 	if { [info exist options(choised,lang)] && $options(choised,lang) == 0 } {
 		set lang text
 	} else {
-		set lang [GetTrueLang [.tastebin.send_bar.lang get]]
+		set lang [GetTrueLang [.tastebin.main_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
@@ -294,7 +277,7 @@
 	$w insert 0.0 $data
 	http::cleanup $token
 	
-	putHistory "\[[clock format [clock seconds] -format "%R %p %D"]\] [.tastebin.send_bar.lang get] - $data"
+	putHistory "\[[clock format [clock seconds] -format "%R %p %D"]\] [.tastebin.main_bar.lang get] - $data"
 }
 
 
@@ -357,123 +340,11 @@
 	$w insert 0.0 [getHistory]
 }
 
-# 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
 	
+	GetHighlights
+	
 	hook::add finload_hook [list \
 		ifacetk::add_toolbar_button \
 			[image create photo -file \



More information about the Tkabber-dev mailing list