[Tkabber-dev] r1663 - in trunk/tkabber: . plugins/roster

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Feb 15 15:42:05 MSK 2009


Author: sergei
Date: 2009-02-15 15:42:05 +0300 (Sun, 15 Feb 2009)
New Revision: 1663

Modified:
   trunk/tkabber/ChangeLog
   trunk/tkabber/plugins/roster/metacontacts.tcl
Log:
	* plugins/roster/metacontacts.tcl: Made windows titles and messages
	  more clear and added drag'n'drop which allows metacontact items
	  reordering.


Modified: trunk/tkabber/ChangeLog
===================================================================
--- trunk/tkabber/ChangeLog	2009-02-15 11:22:02 UTC (rev 1662)
+++ trunk/tkabber/ChangeLog	2009-02-15 12:42:05 UTC (rev 1663)
@@ -13,6 +13,10 @@
 	* plugins/roster/metacontacts.tcl: Fixed keyboard traversal of
 	  metacontact window and started to implement items reordering.
 
+	* plugins/roster/metacontacts.tcl: Made windows titles and messages
+	  more clear and added drag'n'drop which allows metacontact items
+	  reordering.
+
 2009-02-14  Sergei Golovan  <sgolovan at nes.ru>
 
 	* chats.tcl, ifacetk/iroster.tcl: Adapted to a new syntax of roster

Modified: trunk/tkabber/plugins/roster/metacontacts.tcl
===================================================================
--- trunk/tkabber/plugins/roster/metacontacts.tcl	2009-02-15 11:22:02 UTC (rev 1662)
+++ trunk/tkabber/plugins/roster/metacontacts.tcl	2009-02-15 12:42:05 UTC (rev 1663)
@@ -198,7 +198,7 @@
 	      -cancel 1
 
     $w add -text [::msgcat::mc "Store"] \
-	   -command [namespace code [list edit_enddialog $xlib $w $tag]]
+	   -command [namespace code [list edit_enddialog $w $xlib $tag]]
 
     $w add -text [::msgcat::mc "Cancel"] \
 	   -command [list destroy $w]
@@ -213,13 +213,13 @@
     pack $sw -side top -expand yes -fill both -in $f -pady 1m -padx 1m
     $sw setwidget $lf
 
-    bind $lf <3> [namespace code [list select_and_popup_menu %W %x %y]]
+    bind $lf <3> [namespace code [list select_and_popup_menu %W [double% $xlib] %x %y]]
 
     set addentry [entry $tools.addentry]
     set additem [button $tools.additem \
 		     -text [::msgcat::mc "Add JID"] \
 		     -command \
-		     [namespace code [list add_jid_entry $lf $addentry]]]
+		     [namespace code [list add_jid_entry $lf $xlib $addentry]]]
     pack $additem -side right -padx 1m
     pack $addentry -side left -padx 1m -fill x -expand yes
 
@@ -233,17 +233,31 @@
 	$lf insert end $jid
     }
 
+    fix_dialog_title $lf $xlib
+
     focus $lf
 
-    DropSite::register $lf -dropcmd [namespace code [list dropcmd]] \
+    DropSite::register $lf -dropcmd [namespace code [list dropcmd $xlib]] \
 			   -droptypes {JID}
 
-    DragSite::register $lf -draginitcmd [namespace code [list draginitcmd]]
+    DragSite::register $lf -draginitcmd [namespace code [list draginitcmd $xlib]]
 
     $w draw
 }
 
-proc metacontacts::edit_enddialog {xlib w tag} {
+proc metacontacts::fix_dialog_title {f xlib} {
+    set w [winfo toplevel $f]
+
+    if {[$f size] > 0} {
+	set jid [$f get 0]
+	$w configure -title [::msgcat::mc "Edit %s's Metacontact" \
+					  [::roster::get_label $xlib $jid]]
+    } else {
+	$w configure -title [::msgcat::mc "Edit Metacontact"]
+    }
+}
+
+proc metacontacts::edit_enddialog {w xlib tag} {
     variable contacts
 
     $w itemconfigure 0 -state disabled
@@ -255,15 +269,40 @@
     redraw_roster
 }
 
-proc metacontacts::dropcmd {target source X Y op type data} {
-    add_jid $target [lindex $data 1]
+proc metacontacts::dropcmd {xlib target source X Y op type data} {
+    set x [expr {$X - [winfo rootx $target]}]
+    set y [expr {$Y - [winfo rooty $target]}]
+
+    set bbox [$target bbox @$x,$y]
+    if {$y > [lindex $bbox 1] + [lindex $bbox 3]} {
+	set index end
+    } else {
+	set index [$target index @$x,$y]
+    }
+
+    add_jid $target $xlib [lindex $data 1] $index
 }
 
-proc metacontacts::draginitcmd {target x y top} {
-    return {}
+proc metacontacts::draginitcmd {xlib target X Y top} {
+    set x [expr {$X - [winfo rootx $target]}]
+    set y [expr {$Y - [winfo rooty $target]}]
+
+    set bbox [$target bbox @$x,$y]
+    if {$y > [lindex $bbox 1] + [lindex $bbox 3]} {
+	return {}
+    } else {
+	set jid [$target get [$target index @$x,$y]]
+	set data [list $xlib $jid \
+		       [::roster::itemconfig $xlib $jid -category] \
+		       [::roster::itemconfig $xlib $jid -subtype] \
+		       [::roster::itemconfig $xlib $jid -name] {} \
+		       {}]
+
+	return [list JID {move} $data]
+    }
 }
 
-proc metacontacts::select_and_popup_menu {f x y} {
+proc metacontacts::select_and_popup_menu {f xlib x y} {
     set index [$f index @$x,$y]
     $f selection clear 0 end
     $f selection set $index
@@ -274,31 +313,41 @@
 
     menu $m -tearoff 0
     $m add command -label [::msgcat::mc "Remove from metacontact"] \
-		   -command [list $f delete $index]
+		   -command [namespace code [list delete_jid $f $xlib $index]]
 
     tk_popup $m [winfo pointerx .] [winfo pointery .]
 }
 
-proc metacontacts::add_jid_entry {f entry} {
+proc metacontacts::add_jid_entry {f xlib entry} {
     set item [$entry get]
     $entry delete 0 end
 
     add_jid $f $item
 }
 
-proc metacontacts::add_jid {f item} {
+proc metacontacts::add_jid {f xlib item {index end}} {
     set values [$f get 0 end]
-    if {[lsearch -exact $values $item] < 0} {
-	lappend values $item
+    if {[set idx [lsearch -exact $values $item]] >= 0} {
+	set values [lreplace $values $idx $idx]
     }
 
+    set values [linsert $values $index $item]
+
     set index [lsearch -exact $values $item]
 
     $f delete 0 end
     eval [list $f insert end] $values
     $f selection set $index
+
+    fix_dialog_title $f $xlib
 }
 
+proc metacontacts::delete_jid {f xlib index} {
+    $f delete $index
+
+    fix_dialog_title $f $xlib
+}
+
 proc metacontacts::confirm_delete {xlib tag} {
     variable contacts
 
@@ -308,6 +357,15 @@
 	destroy $w
     }
 
+    if {![info exists contacts($xlib,jids,$tag)] || \
+	    [llength $contacts($xlib,jids,$tag)] == 0} {
+	set message [::msgcat::mc "Are you sure to delete metacontact?"]
+    } else {
+	set jid [lindex $contacts($xlib,jids,$tag) 0]
+	set message [::msgcat::mc "Are you sure to delete %s's metacontact?" \
+				  [::roster::get_label $xlib $jid]]
+    }
+
     set res [MessageDlg .metacontact_delete \
 			-aspect 50000 \
 			-icon warning \
@@ -315,7 +373,7 @@
 			-buttons {yes no} \
 			-default 1 \
 			-cancel 1 \
-			-message [::msgcat::mc "Are you sure to delete this metacontact?"]]
+			-message $message]
 
     if {$res == 0} {
 	if {[set idx [lsearch -exact $contacts($xlib,tags) $tag]] >= 0} {



More information about the Tkabber-dev mailing list