blam r672 - trunk/src



Author: cmartin
Date: Sun Mar  8 21:42:12 2009
New Revision: 672
URL: http://svn.gnome.org/viewvc/blam?rev=672&view=rev

Log:
Start implementing DnD on the channel list.

Moving into and between groups works. Moving out of a group doesn't yet.

Modified:
   trunk/src/Application.cs
   trunk/src/ChannelCollection.cs
   trunk/src/ChannelGroup.cs
   trunk/src/ChannelList.cs

Modified: trunk/src/Application.cs
==============================================================================
--- trunk/src/Application.cs	(original)
+++ trunk/src/Application.cs	Sun Mar  8 21:42:12 2009
@@ -100,9 +100,10 @@
         Gnome.Client client = null;
 
 
-        enum TargetType {
+        public enum TargetType {
             String,
-            UriList
+            UriList,
+			Channel
         };
 
         public static TargetEntry[] DragEntries = new TargetEntry[] {

Modified: trunk/src/ChannelCollection.cs
==============================================================================
--- trunk/src/ChannelCollection.cs	(original)
+++ trunk/src/ChannelCollection.cs	Sun Mar  8 21:42:12 2009
@@ -271,7 +271,7 @@
         foreach(ChannelGroup group in Groups){
             if(group.Channels.Count == 0)
                     continue;
-            foreach(Channel channel in group.Channels){
+            foreach(IChannel channel in group.Channels){
                 TimeSpan span = DateTime.Now.Subtract(channel.LastRefreshed);
                 if(span.TotalSeconds >= refreshRate * 60){
                     QueueChannelRefresh(channel);

Modified: trunk/src/ChannelGroup.cs
==============================================================================
--- trunk/src/ChannelGroup.cs	(original)
+++ trunk/src/ChannelGroup.cs	Sun Mar  8 21:42:12 2009
@@ -39,7 +39,7 @@
                 if(Channels.Count == 0)
                     return nr;
 
-                foreach(Channel channel in Channels){
+                foreach(IChannel channel in Channels){
                     nr += channel.NrOfUnreadItems;
                 }
 
@@ -54,7 +54,7 @@
                 if(Channels.Count == 0)
                     return n;
 
-                foreach(Channel channel in Channels){
+                foreach(IChannel channel in Channels){
                     n += channel.NrOfItems;
                 }
                 

Modified: trunk/src/ChannelList.cs
==============================================================================
--- trunk/src/ChannelList.cs	(original)
+++ trunk/src/ChannelList.cs	Sun Mar  8 21:42:12 2009
@@ -37,6 +37,10 @@
 
         private IChannel LastChannel = null;
 
+        public static TargetEntry[] DragEntries = new TargetEntry[] {
+            new TargetEntry("channel", TargetFlags.Widget, (uint)Blam.Application.TargetType.Channel)
+       };
+
         public ChannelList(IList channels, IList groups)
         { 
             TreeViewColumn col;
@@ -85,6 +89,11 @@
             channelEnumerator = channels.GetEnumerator();
             groupEnumerator = groups.GetEnumerator();
 
+			EnableModelDragSource(ModifierType.Button1Mask, DragEntries, DragAction.Copy);
+			DragDataGet += DragDataGetHandler;
+			EnableModelDragDest(DragEntries, DragAction.Copy);
+			DragDataReceived += DragDataReceivedHandler;
+
             GLib.Idle.Add(new GLib.IdleHandler(IdleAdd));
         }
 
@@ -94,6 +103,34 @@
             (Model as TreeStore).SetSortColumnId(-1, SortType.Ascending);
         }
 
+		private void DragDataGetHandler(object o, DragDataGetArgs args)
+		{
+			ChannelList chlst = o as ChannelList;
+			args.RetVal = chlst.GetSelected();
+
+		}
+
+		private void DragDataReceivedHandler(object o, DragDataReceivedArgs args)
+		{
+			TreePath path;
+			TreeViewDropPosition pos;
+			TreeIter iter, tmp_iter;
+			IChannel chan = GetSelected();
+			tmp_iter = chan.Iter;
+			GetDestRowAtPos(args.X, args.Y, out path, out pos);
+			Model.GetIter(out iter, path);
+			ChannelGroup group = Model.GetValue(iter, 0) as ChannelGroup;
+
+			if(Model.GetValue(iter, 0) is Channel){
+				return; // A channel can't become a group.
+			}
+
+			chan.Iter = (Model as TreeStore).AppendValues(iter, chan);
+			group.Channels.Add(chan);
+			Model.EmitRowChanged(path, iter);
+			(Model as TreeStore).Remove(ref tmp_iter);
+		}
+
         private bool IdleAdd()
         {
             while (channelEnumerator.MoveNext ()) {
@@ -120,6 +157,7 @@
             TreeIter iter = (this.Model as TreeStore).AppendValues(channel);
             ChannelGroup group = channel as ChannelGroup;
             group.Iter = iter;
+			SetDragDestRow(Model.GetPath(iter), TreeViewDropPosition.IntoOrAfter);
 
             foreach(IChannel chan in group.Channels){
                 iter = (this.Model as TreeStore).AppendValues(group.Iter, chan);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]