[Tkabber-dev] r431 - in trunk/plugins: . boldnicks boldnicks/msgs

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Mon Oct 25 04:14:33 MSD 2010


Author: Rejjin
Date: 2010-10-25 04:14:33 +0400 (Mon, 25 Oct 2010)
New Revision: 431

Added:
   trunk/plugins/boldnicks/
   trunk/plugins/boldnicks/INSTALL
   trunk/plugins/boldnicks/README
   trunk/plugins/boldnicks/boldnicks.tcl
   trunk/plugins/boldnicks/msgs/
   trunk/plugins/boldnicks/msgs/ru.msg
Log:
"Bold Nicks" plugin (when you turn the corresponding option) 
starts to use the bold style for nicks in chat rooms. There are 
options changes the cursor and underline when you hover on 
nickname. Plugin dynamically unload.

Added: trunk/plugins/boldnicks/INSTALL
===================================================================
--- trunk/plugins/boldnicks/INSTALL	                        (rev 0)
+++ trunk/plugins/boldnicks/INSTALL	2010-10-25 00:14:33 UTC (rev 431)
@@ -0,0 +1,12 @@
+As usually, copy this directory under the ~/.tkabber/plugins 
+directory so that you get a hierarchy like this:
+
+  ~/.tkabber/plugins
+  ~/.tkabber/plugins/boldnicks/
+  ~/.tkabber/plugins/boldnicks/boldnicks.tcl
+  ~/.tkabber/plugins/boldnicks/README
+  ~/.tkabber/plugins/boldnicks/INSTALL
+  ~/.tkabber/plugins/boldnicks/msgs/
+  ~/.tkabber/plugins/boldnicks/msgs/ru.msg
+  
+Restart Tkabber, to get the plugin loaded.
\ No newline at end of file

Added: trunk/plugins/boldnicks/README
===================================================================
--- trunk/plugins/boldnicks/README	                        (rev 0)
+++ trunk/plugins/boldnicks/README	2010-10-25 00:14:33 UTC (rev 431)
@@ -0,0 +1,13 @@
+"Bold Nicks" plugin for Tkabber.
+
+1. Usage. 
+
+"Bold Nicks" plugin (when you turn the corresponding option) 
+starts to use the bold style for nicks in chat rooms. There are 
+options changes the cursor and underline when you hover on 
+nickname. Plugin dynamically unload.
+
+2. Author.
+
+Renji <webrenji at gmail.com>
+XMPP: rejjin at jabber.dk
\ No newline at end of file

Added: trunk/plugins/boldnicks/boldnicks.tcl
===================================================================
--- trunk/plugins/boldnicks/boldnicks.tcl	                        (rev 0)
+++ trunk/plugins/boldnicks/boldnicks.tcl	2010-10-25 00:14:33 UTC (rev 431)
@@ -0,0 +1,165 @@
+# "Bold Nicks" plugin for Tkabber.
+# Renji <webrenji at gmail.com>
+# 4:08 25.10.2010
+
+namespace eval boldnicks {
+	variable options
+	
+	::msgcat::mcload [file join [file dirname [info script]] msgs]
+	
+	custom::defgroup Plugins [::msgcat::mc "Plugins options."] \
+	-group Tkabber	
+	
+    custom::defgroup "Bold Nicks" [::msgcat::mc "\"Bold Nicks\" plugin options"] \
+	-group Plugins	
+	
+	custom::defvar options(use_bold_style) 1 \
+	[::msgcat::mc "Use bold style for nicks"] \
+	-group "Bold Nicks" -type boolean \
+	-command [namespace current]::change_options
+	
+	custom::defvar options(change_cursor) 1 \
+	[::msgcat::mc "Change cursor when mouse is hover nick"] \
+	-group "Bold Nicks" -type boolean \
+	-command [namespace current]::change_options
+	
+	custom::defvar options(emphasize_when_hover) 1 \
+	[::msgcat::mc "Use underline when cursor is hover on nickname"] \
+	-group "Bold Nicks" -type boolean \
+	-command [namespace current]::change_options
+	
+	if {![::plugins::is_registered boldnicks]} {
+		::plugins::register boldnicks \
+				-namespace [namespace current] \
+				-source [info script] \
+				-description [::msgcat::mc "Whether the \"Bold Nicks\" plugin is loaded"] \
+				-loadcommand [namespace code load] \
+				-unloadcommand [namespace code unload]
+		return
+	}
+	
+	proc load {} {
+		hook::add draw_message_hook \
+		[namespace current]::check_nick 60
+		
+		hook::add open_chat_post_hook \
+		[namespace current]::chat_add
+		
+		hook::add close_chat_post_hook \
+		[namespace current]::chat_delete
+		
+		chats_state_config active
+	}
+	
+	proc unload {} {
+		hook::remove draw_message_hook \
+		[namespace current]::check_nick 60
+		
+		hook::remove open_chat_post_hook \
+		[namespace current]::chat_add
+		
+		hook::remove close_chat_post_hook \
+		[namespace current]::chat_delete
+		
+		chats_state_config deactive
+	}
+}
+
+proc boldnicks::chats_state_config {state} {
+	variable chat_nicks
+	
+	foreach chatid [chat::opened] {
+		set w [chat::chat_win $chatid]
+		switch -- $state {
+			active {
+				chat_add $chatid {}
+				foreach tag [lsearch -all -glob -inline [$w tag names] NICK-*] {
+					if [regsub -- "NICK-" $tag "" nick] {
+					set_bold $chatid $nick
+					lappend chat_nicks($chatid) $nick
+					}
+				}
+			}
+			deactive {
+				foreach nick $chat_nicks($chatid) {
+					$w tag configure NICK-$nick -font ChatFont
+					$w tag bind NICK-$nick <Any-Enter> {}
+					$w tag bind NICKMSG-$nick <Any-Enter> {}
+					$w tag bind NICK-$nick <Any-Leave> {}
+					$w tag bind NICKMSG-$nick <Any-Leave> {}
+					chat_delete $chatid
+				}
+			}
+		}
+	}
+}
+
+proc boldnicks::change_options {args} {
+    variable chat_nicks
+    foreach chatid [chat::opened] {
+		if {[winfo exists [chat::chat_win $chatid]]} {
+			foreach nick $chat_nicks($chatid) {set_bold $chatid $nick}
+		}
+	}
+}
+
+proc boldnicks::chat_add {chatid type} {
+    variable chat_nicks
+
+    set chat_nicks($chatid) {}
+}
+
+proc boldnicks::chat_delete {chatid} {
+    variable chat_nicks
+
+    catch {unset chat_nicks($chatid)}
+}
+
+proc boldnicks::check_nick {chatid from type body x} {
+	variable chat_nicks
+	
+    set xlib [chat::get_xlib $chatid]
+    set nick [chat::get_nick $xlib $from $type]
+	
+	if {[lsearch -exact $chat_nicks($chatid) $nick] < 0} {
+		lappend chat_nicks($chatid) $nick
+		set_bold $chatid $nick
+    }
+}
+
+proc boldnicks::set_bold {chatid nick} {
+	variable options
+
+    if {[catch {set w [chat::chat_win $chatid]}] || ![winfo exists $w]} {
+	return
+	}
+
+    if {$options(use_bold_style)} {  
+		$w tag configure NICK-$nick -font ChatBoldFont
+		$w tag configure NICKMSG-$nick -font ChatBoldFont
+	} else {
+		$w tag configure NICK-$nick -font ChatFont
+		$w tag configure NICKMSG-$nick -font ChatFont
+	}
+	
+	$w tag bind NICK-$nick <Any-Enter> \
+		[list [namespace current]::mouse_on_nick yes $w NICK-$nick]
+	$w tag bind NICKMSG-$nick <Any-Enter> \
+		[list [namespace current]::mouse_on_nick yes $w NICKMSG-$nick]
+		
+	$w tag bind NICK-$nick <Any-Leave> \
+		[list [namespace current]::mouse_on_nick no $w NICK-$nick]
+	$w tag bind NICKMSG-$nick <Any-Leave> \
+		[list [namespace current]::mouse_on_nick no $w NICKMSG-$nick]
+}
+
+proc boldnicks::mouse_on_nick {bool w tag} {
+	variable options
+
+	$w tag configure $tag -underline \
+		[expr {$options(emphasize_when_hover) && $bool ? \
+			1 : [lindex [$w tag configure $tag -underline] 3]}]
+	$w configure -cursor \
+		[expr {$options(change_cursor) && $bool ? \
+			[option get $w urlcursor Text] : [lindex [$w configure -cursor] 3]}]
+}
\ No newline at end of file

Added: trunk/plugins/boldnicks/msgs/ru.msg
===================================================================
--- trunk/plugins/boldnicks/msgs/ru.msg	                        (rev 0)
+++ trunk/plugins/boldnicks/msgs/ru.msg	2010-10-25 00:14:33 UTC (rev 431)
@@ -0,0 +1,5 @@
+::msgcat::mcset ru "\"Bold Nicks\" plugin options" "\"Bold Nicks\" настройки плагина"
+::msgcat::mcset ru "Use bold style for nicks" "Использовать жирный стиль для ников"
+::msgcat::mcset ru "Change cursor when mouse is hover nick" "Менять курсор мыши при наведении на ник"
+::msgcat::mcset ru "Use underline when cursor is hover on nickname" "Подчёркивать ник при наведении курсора"
+::msgcat::mcset ru "Whether the \"Bold Nicks\" plugin is loaded" "Определяет, загружен ли прлагин \"Bold Nicks\""
\ No newline at end of file



More information about the Tkabber-dev mailing list