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

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Thu Sep 2 18:01:33 MSD 2010


Author: Rejjin
Date: 2010-09-02 18:01:33 +0400 (Thu, 02 Sep 2010)
New Revision: 378

Modified:
   trunk/plugins/tastebin/msgs/ru.msg
   trunk/plugins/tastebin/tastebin.tcl
Log:
modified files: tastebin.tcl and msgs/ru.msg
tastebin.tcl :
 + Menu on click right button
  + Cut, Copy, Paste, Undo, Redo, Select all
 + Fixed choise lang menu
 + Fixed history and format of time
 + Added menu command to Services-Plugins
 + Fixed errors with toolwindow and topmost options

Modified: trunk/plugins/tastebin/msgs/ru.msg
===================================================================
--- trunk/plugins/tastebin/msgs/ru.msg	2010-08-31 19:03:40 UTC (rev 377)
+++ trunk/plugins/tastebin/msgs/ru.msg	2010-09-02 14:01:33 UTC (rev 378)
@@ -10,4 +10,12 @@
 ::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 "Save state" "Сохранять состояние"
\ No newline at end of file
+::msgcat::mcset ru "Save state" "Сохранять состояние"
+::msgcat::mcset ru "Cut" "Вырезать"
+::msgcat::mcset ru "Copy" "Копировать"
+::msgcat::mcset ru "Paste" "Вставить"
+::msgcat::mcset ru "Undo" "Отмена"
+::msgcat::mcset ru "Redo" "Повтор"
+::msgcat::mcset ru "Select all" "Выделить всё"
+
+

Modified: trunk/plugins/tastebin/tastebin.tcl
===================================================================
--- trunk/plugins/tastebin/tastebin.tcl	2010-08-31 19:03:40 UTC (rev 377)
+++ trunk/plugins/tastebin/tastebin.tcl	2010-09-02 14:01:33 UTC (rev 378)
@@ -11,6 +11,9 @@
 	
 	set options(path) [file dirname [info script]]
 	
+	set options(topmost_exist) 0
+	set options(toolwindow_exist) 0
+	
 	::msgcat::mcload [file join $options(path) msgs]
 	
 	custom::defgroup Plugins \
@@ -28,14 +31,20 @@
 	custom::defvar options(save_history_to_file) 1 \
 		[::msgcat::mc "Save history to file"] \
 		-group Tastebin -type boolean
+		
+	if { [lsearch -exact [wm attributes .] -topmost] >= 0 } {
+		custom::defvar options(topmost) 1 \
+			[::msgcat::mc "Show on top of all windows"] \
+				-group Tastebin -type boolean
+		set options(topmost_exist) 1
+	}
 	
-	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
+	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
+	}
 }
 
 
@@ -79,12 +88,12 @@
 
 	toplevel .tastebin
 	
-	if { [lsearch -exact [wm attributes .tastebin] -topmost] >= 0 } {
+	if {  $options(topmost_exist) } {
 		wm attributes .tastebin -topmost $options(topmost) 
 	}
 	
-	if { [lsearch -exact [wm attributes .tastebin] -toolwindow] >= 0 } {
-		wm attributes .tastebin -topmost $options(toolwindow) 
+	if {  $options(toolwindow_exist) } {
+		wm attributes .tastebin -toolwindow $options(toolwindow) 
 	}
 
 	wm title .tastebin "Tastebin"
@@ -160,9 +169,81 @@
 		.tastebin.options_bar.history \
 		.tastebin.options_bar.close \
 			-padx 4 -side left -fill x -expand 1
+			
+	bind .tastebin.main_bar.txt <3> [list [namespace current]::create_menu %W %X %Y]
 }
 
+proc tastebin::create_menu { W X Y } {
+	set m $W.menu
+	
+	 if {[winfo exists $m]} {
+	destroy $m
+    }
 
+    menu $m -tearoff 0
+	
+	$m add command -label [::msgcat::mc "Cut"] \
+		-command  [list [namespace current]::cut $W]
+	$m add command -label [::msgcat::mc "Copy"] \
+		-command  [list [namespace current]::copy $W]
+	$m add command -label [::msgcat::mc "Paste"] \
+		-command  [list [namespace current]::paste $W]
+	$m add command -label [::msgcat::mc "Undo"] \
+		-command  [list [namespace current]::undo $W]
+	$m add command -label [::msgcat::mc "Redo"] \
+		-command  [list [namespace current]::redo $W]
+	$m add command -label [::msgcat::mc "Select all"] \
+		-command  [list [namespace current]::select_all $W]
+	
+	tk_popup $m $X $Y
+}
+
+proc tastebin::cut text {
+	if {![catch {set data [$text get sel.first sel.last]}]} {
+		clipboard clear -displayof $text
+		clipboard append -displayof $text $data
+		$text delete sel.first sel.last
+	}
+}
+
+proc tastebin::copy text {
+	if {![catch {set data [$text get sel.first sel.last]}]} {
+		clipboard clear -displayof $text
+		clipboard append -displayof $text $data
+	}
+}
+
+proc tastebin::undo text {
+	catch {$text edit undo}
+}
+
+proc tastebin::redo text {
+	catch {$text edit redo}
+}
+
+proc tastebin::select_all text {
+	$text tag add sel 1.0 end
+}
+
+proc tastebin::paste text {
+	global tcl_platform
+	if {![catch {::tk::GetSelection $text CLIPBOARD} sel]} {
+		set oldSeparator [$text cget -autoseparators]
+		if {$oldSeparator} {
+			$text configure -autoseparators 0
+			$text edit separator
+		}
+		if {[tk windowingsystem] ne "x11"} {
+			catch { $text delete sel.first sel.last }
+		}
+		$text insert insert $sel
+		if {$oldSeparator} {
+			$text edit separator
+			$text configure -autoseparators 1
+		}
+	}
+}
+
 proc tastebin::initMenu { X Y } {
 	variable options
 	
@@ -177,7 +258,8 @@
 			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]]
+				$m add cascade -menu $children \
+					-label "[string totitle [string index $name 0]]       "
 				menu $children -tearoff 0
 			}
 			
@@ -279,9 +361,10 @@
 	$w insert 0.0 $data
 	http::cleanup $token
 	
-	putHistory "\[[clock format [clock seconds] -format "%R %p %D"]\]\
-	[.tastebin.main_bar.lang get] - ${data}:\
-	 $log\n...\n[string repeat _ 20]\n\n"
+	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"
 }
 
 
@@ -344,17 +427,28 @@
 	$w insert 0.0 [getHistory]
 }
 
+proc tastebin::create_buttons { } {
+	ifacetk::add_toolbar_button TastebinButton \
+		[namespace current]::SwitchState "Tastebin"
+		
+	[.mainframe getmenu services] insert \
+		[::msgcat::mc "Plugins"] separator
+		
+	[.mainframe getmenu services] insert \
+		[::msgcat::mc "Plugins"] command \
+		-label Tastebin \
+		-command [namespace current]::SwitchState]
+}
+
 namespace eval tastebin {
 	variable options
 	
 	GetHighlights
-	
+		
 	image create photo TastebinButton -file \
 		[file join $options(path) image toolbar_icon.gif]
 		
-	hook::add finload_hook [list \
-		ifacetk::add_toolbar_button TastebinButton \
-				[namespace current]::SwitchState \
-					"Tastebin"]
+	hook::add finload_hook \
+		[namespace current]::create_buttons
 }
 	
\ No newline at end of file



More information about the Tkabber-dev mailing list