[Tkabber-dev] r1728 - trunk/tkabber

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sat Mar 14 16:40:15 MSK 2009


Author: sergei
Date: 2009-03-14 16:40:15 +0300 (Sat, 14 Mar 2009)
New Revision: 1728

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/chats.tcl
   trunk/tkabber/muc.tcl
Log:
	* chats.tcl, muc.tcl: Converted chat and conference menus into dynamic
	  ones (created just before posting) to make it easier to
	  enabling/disabling and adding/deleting items.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2009-03-13 21:23:41 UTC (rev 1727)
+++ trunk/tkabber/ChangeLog	2009-03-14 13:40:15 UTC (rev 1728)
@@ -1,3 +1,9 @@
+2009-03-14  Sergei Golovan  <sgolovan at nes.ru>
+
+	* chats.tcl, muc.tcl: Converted chat and conference menus into dynamic
+	  ones (created just before posting) to make it easier to
+	  enabling/disabling and adding/deleting items.
+
 2009-03-13  Sergei Golovan  <sgolovan at nes.ru>
 
 	* plugins/general/captcha.tcl: Renamed from challenge.tcl and added

Modified: trunk/tkabber/chats.tcl
===================================================================
--- trunk/tkabber/chats.tcl	2009-03-13 21:23:41 UTC (rev 1727)
+++ trunk/tkabber/chats.tcl	2009-03-14 13:40:15 UTC (rev 1728)
@@ -452,18 +452,20 @@
 	    pack $cw.status.desc -side left
 	}
     }
-    if {[cequal $type chat]} {
-	menubutton $cw.status.mb -text $jid \
-	    -anchor w \
-	    -menu $cw.status.mb.menu
-	create_user_menu $cw.status.mb.menu $chatid
-	pack $cw.status.mb -side left
+
+    set mb $cw.status.mb
+    set m $mb.menu
+    if {[string equal $type chat]} {
+	menubutton $mb -text $jid -anchor w -menu $m
+	menu $m -tearoff 0 \
+		-postcommand [namespace code [list create_user_menu $m $chatid]]
+	pack $mb -side left
     } else {
-        menubutton $cw.status.mb -text [::msgcat::mc "Subject:"] \
-	    -direction below \
-	    -menu $cw.status.mb.menu -relief flat
-	create_conference_menu $cw.status.mb.menu $chatid
-	pack $cw.status.mb -side left
+        menubutton $mb -text [::msgcat::mc "Subject:"] \
+		       -direction below -menu $m -relief flat
+	menu $m -tearoff 0 \
+		-postcommand [namespace code [list create_conference_menu $m $chatid]]
+	pack $mb -side left
 
 	entry $cw.status.subject \
 	    -xscrollcommand [list [namespace current]::set_subject_tooltip $chatid]
@@ -819,7 +821,10 @@
 ##############################################################################
 
 proc chat::create_user_menu {m chatid} {
-    menu $m -tearoff 0
+    $m delete 0 end
+    foreach mm [winfo children $m] {
+	destroy $mm
+    }
 
     set xlib [get_xlib $chatid]
     set jid [get_jid $chatid]
@@ -830,7 +835,10 @@
 }
 
 proc chat::create_conference_menu {m chatid} {
-    menu $m -tearoff 0
+    $m delete 0 end
+    foreach mm [winfo children $m] {
+	destroy $mm
+    }
 
     set xlib [get_xlib $chatid]
     set jid [get_jid $chatid]

Modified: trunk/tkabber/muc.tcl
===================================================================
--- trunk/tkabber/muc.tcl	2009-03-13 21:23:41 UTC (rev 1727)
+++ trunk/tkabber/muc.tcl	2009-03-14 13:40:15 UTC (rev 1728)
@@ -114,37 +114,19 @@
 }
 
 hook::add roster_create_groupchat_user_menu_hook \
-    muc::add_groupchat_user_menu_items 39
+	  muc::add_groupchat_user_menu_items 39
 
 ###############################################################################
 
-proc muc::create_conference_menu_items {m xlib jid} {
-    set chatid [chat::chatid $xlib $jid]
+proc muc::add_muc_menu_items {m xlib group} {
+    if {![is_compatible $group]} {
+	set state disabled
+    } else {
+	set state normal
+    }
 
-    set idx [expr {[$m index end] + 1}]
+    set chatid [chat::chatid $xlib $group]
 
-    trace variable ::muc::muc_compatible($jid) w \
-	[list muc::add_conference_menu_items $m $chatid $idx]
-
-    bind $m <Destroy> [list trace vdelete ::muc::muc_compatible($jid) w \
-			    [list muc::add_conference_menu_items $m $chatid $idx]]
-
-}
-    
-hook::add chat_create_conference_menu_hook muc::create_conference_menu_items 37
-
-proc muc::add_conference_menu_items {m chatid idx args} {
-    set group [chat::get_jid $chatid]
-
-    if {![is_compatible $group] || ![winfo exists $m]} return
-
-    trace vdelete ::muc::muc_compatible($group) w \
-	[list muc::add_conference_menu_items $m $chatid $idx]
-
-    add_muc_menu_items $m $chatid $idx
-}
-
-proc muc::add_muc_menu_items {m chatid idx} {
     set mm [menu $m.muc -tearoff 0]
 
     $mm add command -label [::msgcat::mc "Configure room"] \
@@ -165,9 +147,11 @@
     $mm add command -label [::msgcat::mc "Destroy room"] \
 	-command [list muc::request_destruction_dialog $chatid "" ""]
 
-    $m insert $idx cascade -label [::msgcat::mc "MUC"] -menu $mm
+    $m add cascade -label [::msgcat::mc "MUC"] -menu $mm -state $state
 }
 
+hook::add chat_create_conference_menu_hook muc::add_muc_menu_items 37
+
 proc muc::disco_node_menu_setup {m bw tnode data parentdata} {
     lassign $data type xlib jid node
     switch -- $type {



More information about the Tkabber-dev mailing list