[Tkabber-dev] r385 - in trunk/plugins: . chattoolbar chattoolbar/pixmaps

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Sep 12 22:52:11 MSD 2010


Author: Rejjin
Date: 2010-09-12 22:52:10 +0400 (Sun, 12 Sep 2010)
New Revision: 385

Added:
   trunk/plugins/chattoolbar/
   trunk/plugins/chattoolbar/chattoolbar.tcl
   trunk/plugins/chattoolbar/pixmaps/
   trunk/plugins/chattoolbar/pixmaps/chattoolbar-setting.gif
Log:
Adds a field to the buttons on the message entry field. Manager is the buttons to enable/disable the specified button.

Added: trunk/plugins/chattoolbar/chattoolbar.tcl
===================================================================
--- trunk/plugins/chattoolbar/chattoolbar.tcl	                        (rev 0)
+++ trunk/plugins/chattoolbar/chattoolbar.tcl	2010-09-12 18:52:10 UTC (rev 385)
@@ -0,0 +1,331 @@
+namespace eval chattoolbar {
+
+	package require msgcat
+	::msgcat::mcload [file join [file dirname [info script]] msgs]
+	
+	variable options
+	custom::defgroup Plugins [::msgcat::mc "Plugins options."] -group Tkabber	
+    custom::defgroup ChatToolbar [::msgcat::mc "Chat Toolbar options"] -group Plugins	
+	custom::defvar options(add_toolbar_button) 1 [::msgcat::mc "Create button on toolbar"] -group ChatToolbar -type boolean
+	
+	trace add variable [namespace current]::options(using_for_groupchat) write [namespace current]::reload
+	trace add variable [namespace current]::options(using_for_chat) write [namespace current]::reload
+
+	image create photo chattoolbar-setting -file [file join [file dirname [info script]] pixmaps chattoolbar-setting.gif]
+	image create photo button-clear -file [file join [file dirname [info script]] pixmaps clear.gif]
+	
+	variable script_dir
+	set script_dir [file dirname [info script]]
+	
+	hook::add finload_hook [namespace current]::handle 100
+	hook::add open_chat_post_hook [namespace current]::on_join_conference 100
+}
+
+
+
+proc chattoolbar::handle { } {
+	init_toolbar_and_services_buttons
+	reload
+}
+
+
+
+proc chattoolbar::init_toolbar_and_services_buttons { } {
+	variable options
+	
+	if { $options(add_toolbar_button) } {
+		ifacetk::add_toolbar_button \
+			chattoolbar-setting \
+			[namespace current]::setting \
+			[::msgcat::mc "Chattoolbar setting"]
+	}
+	
+	[.mainframe getmenu plugins] add command \
+		-label [::msgcat::mc "Chattoolbar setting"] \
+		-command [namespace current]::setting
+}
+
+
+
+proc chattoolbar::on_join_conference { chatid type } {
+	variable options
+	
+	create_toolbar $chatid
+	
+	hook::run chattoolbar_hook $chatid
+}
+
+
+	
+proc chattoolbar::create_toolbar { chatid } {
+	set chatwin_toolbar [get_chattoolbar_frame $chatid]
+	
+	if { [winfo exist $chatwin_toolbar.tools] } {
+		destroy $chatwin_toolbar.tools
+	}
+	
+	set frame_tool [frame $chatwin_toolbar.tools -cursor arrow]
+	set bbox [ButtonBox $frame_tool.bbox -spacing 1 -padx 1 -pady 1]
+	
+	pack $chatwin_toolbar.tools -side bottom -fill both -pady 2
+	pack $bbox -side left
+}	
+	
+	
+	
+proc chattoolbar::get_chattoolbar_box chatid {
+	set chatwin [get_chattoolbar_frame $chatid]
+	return $chatwin.tools.bbox
+}
+
+
+
+proc chattoolbar::get_chattoolbar_box_frame chatid {
+	set chatwin [get_chattoolbar_frame $chatid]
+	return $chatwin.tools
+}
+
+
+
+proc chattoolbar::get_chattoolbar_frame chatid {
+	set chatwin [chat::winid $chatid]
+	return $chatwin.pw0.f0.frame
+}
+	
+	
+	
+proc chattoolbar::destroy_chattoolbar chatid {
+	destroy [get_chattoolbar_box_frame $chatid]
+}
+
+
+
+proc chattoolbar::setting { } {
+	variable options
+	
+	set w .chattoolbar_manager
+	
+	if { [winfo exists $w] } {
+		return
+	}
+	
+	add_win $w -title [::msgcat::mc "Chattoolbar manager"] \
+	    -tabtitle [::msgcat::mc "Chattoolbar setting"] \
+	    -raisecmd [list focus $w]
+	
+	set scw [ScrolledWindow $w.sw]
+	set text [text $w.buttonlist -wrap word \
+		-background [$w cget -background] \
+		-cursor arrow]
+		
+	$scw setwidget $text
+		
+	set btn [button $w.apply \
+			-text [::msgcat::mc "Apply changes"] \
+			-command [namespace current]::apply_changes] 	
+	
+	foreach button [get_chattoolbar_buttons] {
+		 set check [checkbutton $text.check_$button \
+			-text $options(buttons,$button,text) \
+			-variable [namespace current]::options(buttons,$button,enabled)]
+			
+		set image [label $text.image_$button -image $options(buttons,$button,image)]
+			
+		$text window create end -window $image
+		$text insert end "\n "
+		$text window create end -window $check
+		$text insert end "\n\n"
+		
+		bindscroll $check $text
+	}
+	
+	pack $scw -expand 1 -fill both
+	pack $btn -anchor se -pady 5 -padx 4
+	
+	$text configure -state disabled
+}
+
+
+
+proc chattoolbar::apply_changes { } {
+	save_buttons
+	reload
+} 
+
+
+
+proc chattoolbar::add_chattoolbar_buttons { name } {
+	variable options 
+	
+	if { [lsearch -exact [get_chattoolbar_buttons] $name] == -1 } {
+		lappend options(chattoolbar_buttons) $name
+	}
+}
+
+
+
+proc chattoolbar::get_chattoolbar_buttons { } {
+	variable options 
+	
+	if { [info exist options(chattoolbar_buttons)] } {
+		return $options(chattoolbar_buttons)
+	}
+}
+
+
+
+proc chattoolbar::is_chattoolbar_button { name } {
+	variable options 
+	
+	if { [info exist options(chattoolbar_buttons)] } {
+		if { [lsearch -exact [get_chattoolbar_buttons] $name] >= 0 } {
+			return 1
+		}
+	}
+	return 0
+}
+
+
+
+proc chattoolbar::add_button { name chatid icon command helptext } {
+	variable options
+	
+	if { $options(buttons,$name,enabled) } {
+		set bbox [get_chattoolbar_box $chatid]
+		$bbox add -image $icon \
+			  -highlightthickness 0 \
+			  -takefocus 0 \
+			  -relief link \
+			  -bd $::tk_borderwidth \
+			  -padx 2 \
+			  -pady 3 \
+			  -command $command \
+			  -helptext $helptext \
+			  -justify left
+		return [$bbox index end]
+	}
+}	
+	
+proc chattoolbar::register { name text image command { state 1 } } {
+	variable options
+	
+	if { [is_chattoolbar_button $name] == 0 } {
+		set options(buttons,$name,text) $text
+		set options(buttons,$name,image) $image
+		set options(buttons,$name,command) $command
+		set options(buttons,$name,enabled) $state
+		
+		add_chattoolbar_buttons $name
+		create_proc_hook $name
+		hook::add chattoolbar_hook [namespace current]::$name
+	}
+}
+	
+proc chattoolbar::reload { args } {
+	foreach chatid $chat::chats(opened) {
+		destroy_chattoolbar $chatid
+		on_join_conference $chatid {}
+	}
+}
+
+
+
+proc chattoolbar::save_buttons { } {
+	variable script_dir
+	variable options
+
+	if { [info exist options(chattoolbar_buttons)] == 0 } {
+		set options(chattoolbar_buttons) {}
+	}
+	
+	foreach name $options(chattoolbar_buttons) {
+		lappend stored_chattoolbar_buttons_list \
+			$name [list \
+				$options(buttons,$name,text) \
+				$options(buttons,$name,image) \
+				$options(buttons,$name,enabled) \
+				$options(buttons,$name,command)]
+	}
+	
+	set path [file join $script_dir buttons-cache]
+	set cache [open $path w]
+	puts $cache $stored_chattoolbar_buttons_list
+	close $cache
+}
+
+proc chattoolbar::load_buttons { } {
+	variable script_dir
+	variable options
+	
+	set path [file join $script_dir buttons-cache]
+	
+	if { [file exist $path] == 0 } {
+		return
+	}
+	
+	set cache [open $path r]
+	gets $cache stored_chattoolbar_buttons_list
+	close $cache
+	
+	foreach { name args } $stored_chattoolbar_buttons_list {
+		set options(buttons,$name,text) [lindex $args 0]
+		set options(buttons,$name,image) [lindex $args 1]
+		set options(buttons,$name,command) [lindex $args 3]
+		set options(buttons,$name,enabled) [lindex $args 2]
+		
+		add_chattoolbar_buttons $name
+		create_proc_hook $name
+		hook::add chattoolbar_hook [namespace current]::$name
+	}
+}
+
+proc chattoolbar::create_proc_hook { name } {
+	variable options
+	eval [format {
+		proc [namespace current]::%s chatid {
+			variable options
+			set name %s
+			[namespace current]::add_button $name \
+				$chatid $options(buttons,$name,image) \
+				$options(buttons,$name,command) \
+				$options(buttons,$name,text)
+		}
+	} $name $name]
+}
+
+[namespace current]::chattoolbar::load_buttons
+#########################################################################################
+
+proc chattoolbar::buttons { } {
+	variable script_dir
+	
+	if { [namespace exist ::plugins::tastebin] } {
+		register tastebin {Tastebin - pastebin uploader plugin} \
+			TastebinButton \
+			{::plugins::tastebin::SwitchState} 
+	}
+	
+	if { [namespace exist ::plugins::customstatus] } {
+		register customstatus [::msgcat::mc "Presence presets"] \
+			customstatus/chat-write \
+			{plugins::customstatus::post_menu [plugins::customstatus::recreate_menu]}
+	}
+
+	register add-user [::msgcat::mc "Add new user..."] \
+		toolbar/add-user \
+		{message::send_subscribe_dialog ""}
+	
+	register disco [::msgcat::mc "Service Discovery"] \
+		toolbar/disco \
+		{disco::browser::open_win "" ""}
+
+	register join-conference [::msgcat::mc "Join group..."] \
+		toolbar/join-conference \
+		{join_group_dialog ""}	
+		
+	register chattoolbar-setting [::msgcat::mc "Chattoolbar setting"] \
+		chattoolbar-setting \
+		plugins::chattoolbar::setting
+}
+
+hook::add finload_hook [namespace current]::chattoolbar::buttons 100

Added: trunk/plugins/chattoolbar/pixmaps/chattoolbar-setting.gif
===================================================================
(Binary files differ)


Property changes on: trunk/plugins/chattoolbar/pixmaps/chattoolbar-setting.gif
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream



More information about the Tkabber-dev mailing list