banshee r3105 - in trunk/banshee: . src/Core/Banshee.ThickClient src/Core/Banshee.ThickClient/Banshee.Sources.Gui



Author: abock
Date: Thu Jan 31 00:10:59 2008
New Revision: 3105
URL: http://svn.gnome.org/viewvc/banshee?rev=3105&view=rev

Log:
2008-01-30  Aaron Bockover  <abock gnome org>

    * src/Core/Banshee.ThickClient/Banshee.Sources.Gui/CellEditEntry.cs:
    * src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceRowRenderer.cs:
    * src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView.cs:
    * src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView_DragAndDrop.cs:
    Lots of clean up/reorg of the SourceView code to make it easier to
    read and manage; split all of the drag and drop code into a separate
    file and SourceView is now a partial class



Added:
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView_DragAndDrop.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/CellEditEntry.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceRowRenderer.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp
   trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/CellEditEntry.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/CellEditEntry.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/CellEditEntry.cs	Thu Jan 31 00:10:59 2008
@@ -48,10 +48,6 @@
             MaxLength = 256;
         }
         
-        protected CellEditEntry (System.IntPtr ptr) : base (ptr)
-        {
-        }
-        
         protected override bool OnFocusOutEvent (Gdk.EventFocus focus)
         {
             FinishEditing ();

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceRowRenderer.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceRowRenderer.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceRowRenderer.cs	Thu Jan 31 00:10:59 2008
@@ -43,30 +43,23 @@
         public SourceView view;
         public TreePath path;
 
-        public SourceRowRenderer()
+        public SourceRowRenderer ()
         {
         }
         
-        protected SourceRowRenderer(System.IntPtr ptr) : base(ptr)
+        private StateType RendererStateToWidgetState (CellRendererState flags)
         {
+            return (CellRendererState.Selected & flags).Equals (CellRendererState.Selected)
+                ? StateType.Selected
+                : StateType.Normal;
         }
         
-        private StateType RendererStateToWidgetState(CellRendererState flags)
-        {
-            StateType state = StateType.Normal;
-            if((CellRendererState.Selected & flags).Equals(
-                CellRendererState.Selected))
-                state = StateType.Selected;
-            return state;
-        }
-        
-        public override void GetSize(Widget widget, ref Gdk.Rectangle cell_area,
+        public override void GetSize (Widget widget, ref Gdk.Rectangle cell_area,
             out int x_offset, out int y_offset, out int width, out int height)
         {        
-               int text_x, text_y, text_w, text_h;
+            int text_x, text_y, text_w, text_h;
    
-               base.GetSize(widget, ref cell_area, out text_x, out text_y, 
-                   out text_w, out text_h);
+            base.GetSize (widget, ref cell_area, out text_x, out text_y, out text_w, out text_h);
                 
             x_offset = 0;
             y_offset = 0;
@@ -74,145 +67,156 @@
             height = text_h + 5;
         }
         
-        protected override void Render(Gdk.Drawable drawable, 
-            Widget widget, Gdk.Rectangle background_area, 
-            Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, 
-            CellRendererState flags)
-        {
-            int titleLayoutWidth, titleLayoutHeight;
-            int countLayoutWidth, countLayoutHeight;
-            int maxTitleLayoutWidth;
-            
-            if(source == null) {
+        protected override void Render (Gdk.Drawable drawable, Widget widget, Gdk.Rectangle background_area, 
+            Gdk.Rectangle cell_area, Gdk.Rectangle expose_area, CellRendererState flags)
+        {
+            if (source == null) {
                 return;
             }
             
-            bool path_selected = view.Selection.PathIsSelected (path);
+            bool path_selected = view.Selection.PathIsSelected (path);            
+            StateType state = RendererStateToWidgetState (flags);
             
             if (path_selected) {
                 Gdk.Rectangle rect = background_area;
                 rect.X -= 2;
                 rect.Width += 4;
+                
                 // clear the standard GTK selection and focus
                 drawable.DrawRectangle (widget.Style.BaseGC (StateType.Normal), true, rect);
                 
                 // draw the hot cairo selection
-                view.Graphics.DrawRowSelection (view.Cr, background_area.X + 1, background_area.Y + 1, 
-                    background_area.Width - 2, background_area.Height - 2);
-            } else if(path != null && path.Equals (view.HighlightedPath)) {
+                if (!view.EditingRow) { 
+                    view.Graphics.DrawRowSelection (view.Cr, background_area.X + 1, background_area.Y + 1, 
+                        background_area.Width - 2, background_area.Height - 2);
+                }
+            } else if (path != null && path.Equals (view.HighlightedPath)) {
                 drawable.DrawRectangle (widget.Style.BackgroundGC (StateType.Selected), false,
                     new Gdk.Rectangle (background_area.X + 1, background_area.Y + 1, 
                         background_area.Width - 3, background_area.Height - 4));
             }
             
-            bool hideCounts = source.Count <= 0;
+            int title_layout_width = 0, title_layout_height = 0;
+            int count_layout_width = 0, count_layout_height = 0;
+            int max_title_layout_width;
             
-            StateType state = RendererStateToWidgetState(flags);
-            Pixbuf icon = null;
+            bool hide_counts = source.Count <= 0;
             
-            icon = source.Properties.Get<Gdk.Pixbuf>("IconPixbuf");
-            if(icon == null) {
-                Type icon_type = source.Properties.GetType("IconName");
-                
-                if(icon_type == typeof(string)) {
-                    icon = Banshee.Gui.IconThemeUtils.LoadIcon(22, source.Properties.GetString("IconName"));
-                } else if(icon_type == typeof(string [])) {
-                    icon = Banshee.Gui.IconThemeUtils.LoadIcon(22, source.Properties.GetStringList("IconName"));
-                }
-                
-                if(icon == null) {
-                    icon = Banshee.Gui.IconThemeUtils.LoadIcon(22, "image-missing");
-                }
-                
-                if(icon != null) {
-                    source.Properties.Set<Gdk.Pixbuf>("IconPixbuf", icon);
-                }
-            }
+            Pixbuf icon = ResolveSourceIcon (source);
             
-            Pango.Layout titleLayout = new Pango.Layout(widget.PangoContext);
-            Pango.Layout countLayout = new Pango.Layout(widget.PangoContext);
-            
-            FontDescription fd = widget.PangoContext.FontDescription.Copy();
+            FontDescription fd = widget.PangoContext.FontDescription.Copy ();
             fd.Weight = (ISource)ServiceManager.PlaybackController.Source == (ISource)source 
                 ? Pango.Weight.Bold 
                 : Pango.Weight.Normal;
-            
-            if(Italicized) {
+
+            if (Italicized) {
                 fd.Style = Pango.Style.Italic;
-                hideCounts = true;
+                hide_counts = true;
+            }
+            
+            Pango.Layout title_layout = new Pango.Layout (widget.PangoContext);
+            Pango.Layout count_layout = null;
+            
+            if (!hide_counts) {
+                count_layout = new Pango.Layout (widget.PangoContext);
+                count_layout.FontDescription = fd;
+                count_layout.SetMarkup (String.Format ("<span size=\"small\">({0})</span>", source.Count));
+                count_layout.GetPixelSize (out count_layout_width, out count_layout_height);
             }
 
-            countLayout.FontDescription = fd;
-            countLayout.SetMarkup("<span size=\"small\">(" + source.Count + ")</span>");
-            countLayout.GetPixelSize(out countLayoutWidth, out countLayoutHeight);
-            
-            maxTitleLayoutWidth = cell_area.Width - (icon == null ? 0 : icon.Width) - countLayoutWidth - 10;
-            
-            titleLayout.FontDescription = fd;
-            titleLayout.Width = (int)((maxTitleLayoutWidth) * Pango.Scale.PangoScale);
-            titleLayout.Ellipsize = EllipsizeMode.End;
-            titleLayout.SetText(source.Name);
-            titleLayout.GetPixelSize(out titleLayoutWidth, out titleLayoutHeight);
+            max_title_layout_width = cell_area.Width - (icon == null ? 0 : icon.Width) - count_layout_width - 10;
             
-            Gdk.GC mainGC = widget.Style.TextGC(state);
+            title_layout.FontDescription = fd;
+            title_layout.Width = (int)(max_title_layout_width * Pango.Scale.PangoScale);
+            title_layout.Ellipsize = EllipsizeMode.End;
+            title_layout.SetText (source.Name);
+            title_layout.GetPixelSize (out title_layout_width, out title_layout_height);
+            
+            Gdk.GC main_gc = widget.Style.TextGC (state);
 
-            if(icon != null) {
-                drawable.DrawPixbuf(mainGC, icon, 0, 0, 
-                    cell_area.X + 0, 
-                    cell_area.Y + ((cell_area.Height - icon.Height) / 2) + 1,
-                    icon.Width, icon.Height,
-                    RgbDither.None, 0, 0);
+            if (icon != null) {
+                drawable.DrawPixbuf (main_gc, icon, 0, 0, 
+                    cell_area.X + 0, cell_area.Y + ((cell_area.Height - icon.Height) / 2) + 1,
+                    icon.Width, icon.Height, RgbDither.None, 0, 0);
             }
             
-            drawable.DrawLayout(mainGC, 
+            drawable.DrawLayout (main_gc, 
                 cell_area.X + (icon == null ? 0 : icon.Width) + 6, 
-                cell_area.Y + ((cell_area.Height - titleLayoutHeight) / 2) + 1, 
-                titleLayout);
+                cell_area.Y + ((cell_area.Height - title_layout_height) / 2) + 1, 
+                title_layout);
             
-            if(hideCounts) {
+            if (hide_counts) {
                 return;
             }
                 
-            Gdk.GC modGC = widget.Style.TextGC(state);
-            if(!state.Equals(StateType.Selected)) {
-                modGC = new Gdk.GC(drawable);
-                modGC.Copy(widget.Style.TextGC(state));
-                Gdk.Color fgcolor = widget.Style.Foreground(state);
-                Gdk.Color bgcolor = widget.Style.Background(state);
-                modGC.RgbFgColor = Hyena.Gui.GtkUtilities.ColorBlend(fgcolor, bgcolor);
-                modGC.RgbBgColor = fgcolor;
+            Gdk.GC mod_gc = widget.Style.TextGC (state);
+            if (!state.Equals (StateType.Selected)) {
+                Gdk.Color fgcolor = widget.Style.Foreground (state);
+                Gdk.Color bgcolor = widget.Style.Background (state);
+                
+                mod_gc = new Gdk.GC (drawable);
+                mod_gc.Copy (widget.Style.TextGC (state));
+                mod_gc.RgbFgColor = Hyena.Gui.GtkUtilities.ColorBlend (fgcolor, bgcolor);
+                mod_gc.RgbBgColor = fgcolor;
             } 
             
-            drawable.DrawLayout(modGC,
-                (cell_area.X + cell_area.Width) - countLayoutWidth - 2,
-                cell_area.Y + ((cell_area.Height - countLayoutHeight) / 2) + 1,
-                countLayout);
+            drawable.DrawLayout (mod_gc,
+                (cell_area.X + cell_area.Width) - count_layout_width - 2,
+                cell_area.Y + ((cell_area.Height - count_layout_height) / 2) + 1,
+                count_layout);
+        }
+        
+        private Gdk.Pixbuf ResolveSourceIcon (Source source)
+        {
+            Hyena.Data.PropertyStore properties = source.Properties;
+            Gdk.Pixbuf icon = source.Properties.Get<Gdk.Pixbuf> ("IconPixbuf");
+            
+            if (icon != null) {
+                return icon;
+            }
+            
+            Type icon_type = properties.GetType ("IconName");
+                
+            if(icon_type == typeof (string)) {
+                icon = Banshee.Gui.IconThemeUtils.LoadIcon (22, properties.GetString ("IconName"));
+            } else if (icon_type == typeof (string [])) {
+                icon = Banshee.Gui.IconThemeUtils.LoadIcon (22, properties.GetStringList ("IconName"));
+            }
+                
+            if (icon == null) {
+                icon = Banshee.Gui.IconThemeUtils.LoadIcon (22, "image-missing");
+            }
+                
+            if (icon != null) {
+                properties.Set<Gdk.Pixbuf> ("IconPixbuf", icon);
+            }
+            
+            return icon;
         }
         
-        public override CellEditable StartEditing(Gdk.Event evnt , Widget widget, 
-            string path, Gdk.Rectangle background_area, Gdk.Rectangle cell_area, 
-            CellRendererState flags)
+        public override CellEditable StartEditing (Gdk.Event evnt , Widget widget, string path, 
+            Gdk.Rectangle background_area, Gdk.Rectangle cell_area, CellRendererState flags)
         {
-            CellEditEntry text = new CellEditEntry();
+            CellEditEntry text = new CellEditEntry ();
             text.EditingDone += OnEditDone;
             text.Text = source.Name;
             text.path = path;
-            text.Show();
+            text.Show ();
             
             view.EditingRow = true;
             
             return text;
         }
         
-        private void OnEditDone(object o, EventArgs args)
+        private void OnEditDone (object o, EventArgs args)
         {
             CellEditEntry edit = (CellEditEntry)o;
-            if(view == null) {
+            if (view == null) {
                 return;
             }
             
             view.EditingRow = false;
-            view.UpdateRow(new TreePath(edit.path), edit.Text);
+            view.UpdateRow (new TreePath (edit.path), edit.Text);
         }
     }
 }

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView.cs	Thu Jan 31 00:10:59 2008
@@ -27,94 +27,94 @@
 //
 
 using System;
-using System.Collections.Generic;
-using Mono.Unix;
 using Gtk;
-using Gdk;
 using Cairo;
 
-using Hyena.Gui;
 using Hyena.Data.Gui;
 
 using Banshee.ServiceStack;
 using Banshee.Sources;
+
 using Banshee.Gui;
-using Banshee.Gui.DragDrop;
-using Banshee.Playlist;
-using Banshee.Collection;
 
 namespace Banshee.Sources.Gui
 {
-    public class SourceView : TreeView
+    // Note: This is a partial class - the drag and drop code is split
+    //       out into a separate file to make this class more manageable.
+    //       See SourceView_DragAndDrop.cs for the DnD code.
+
+    public partial class SourceView : TreeView
     {
-        //private Source newPlaylistSource = new PlaylistSource(-1);
-        private TreeIter newPlaylistIter = TreeIter.Zero;
-        private bool newPlaylistVisible = false;
+        //private Source new_playlist_source = new PlaylistSource(-1);
+        private TreeIter new_playlist_iter = TreeIter.Zero;
+        private bool new_playlist_visible = false;
         
+        private SourceRowRenderer renderer;
         private ListViewGraphics graphics;
         private Cairo.Context cr;
         
         private TreeStore store;
         private TreeViewColumn focus_column;
-        private SourceRowRenderer renderer;
         private TreePath highlight_path;
-        private int currentTimeout = -1;
-        
-        private static TargetEntry [] dnd_source_entries = new TargetEntry [] {
-            Banshee.Gui.DragDrop.DragDropTarget.Source
-        };
-            
-        private static TargetEntry [] dnd_dest_entries = new TargetEntry [] {
-            Banshee.Gui.DragDrop.DragDropTarget.TrackInfoObjects,
-            Banshee.Gui.DragDrop.DragDropTarget.Source
-        };
-    
+        private int current_timeout = -1;
+        private bool editing_row = false;
+
         public event EventHandler SourceDoubleClicked;
     
-        public SourceView()
+        public SourceView ()
+        {
+            BuildColumns ();
+            BuildModel ();
+            ConfigureDragAndDrop ();
+            RefreshList ();
+            ConnectEvents ();
+        }
+        
+#region Setup Methods        
+        
+        private void BuildColumns ()
         {
             // Hidden expander column
-            TreeViewColumn col = new TreeViewColumn();
+            TreeViewColumn col = new TreeViewColumn ();
             col.Visible = false;
-            AppendColumn(col);
+            AppendColumn (col);
             ExpanderColumn = col;
         
-            focus_column = new TreeViewColumn();
-            renderer = new SourceRowRenderer();
-            focus_column.Title = Catalog.GetString("Source");
-            focus_column.PackStart(renderer, true);
-            focus_column.SetCellDataFunc(renderer, new TreeCellDataFunc(SourceCellDataFunc));
-            AppendColumn(focus_column);
+            focus_column = new TreeViewColumn ();
+            renderer = new SourceRowRenderer ();
+            focus_column.PackStart (renderer, true);
+            focus_column.SetCellDataFunc (renderer, new TreeCellDataFunc (SourceCellDataFunc));
+            AppendColumn (focus_column);
             
-            store = new TreeStore(typeof(Source), typeof(int));
+            HeadersVisible = false;
+        }
+        
+        private void BuildModel ()
+        {
+            store = new TreeStore (typeof (Source), typeof (int));
             store.SetSortColumnId (1, SortType.Ascending);
             store.ChangeSortColumn ();
             Model = store;
-            HeadersVisible = false;
-            
-            EnableModelDragSource(Gdk.ModifierType.Button1Mask | Gdk.ModifierType.Button3Mask,
-                dnd_source_entries, DragAction.Copy | DragAction.Move);
+        }
         
-            EnableModelDragDest(dnd_dest_entries, DragAction.Copy | DragAction.Move);
-            
-            RefreshList();
-
-            ServiceManager.SourceManager.SourceAdded += delegate(SourceAddedArgs args) {
-                AddSource(args.Source);
+        private void ConnectEvents ()
+        {
+            ServiceManager.SourceManager.SourceAdded += delegate (SourceAddedArgs args) {
+                AddSource (args.Source);
             };
             
-            ServiceManager.SourceManager.SourceRemoved += delegate(SourceEventArgs args) {
-                RemoveSource(args.Source);
+            ServiceManager.SourceManager.SourceRemoved += delegate (SourceEventArgs args) {
+                RemoveSource (args.Source);
             };
             
-            ServiceManager.SourceManager.ActiveSourceChanged += delegate(SourceEventArgs args) {
-                ResetSelection();
+            ServiceManager.SourceManager.ActiveSourceChanged += delegate (SourceEventArgs args) {
+                ResetSelection ();
             };
             
-            ServiceManager.SourceManager.SourceUpdated += delegate(SourceEventArgs args) {
+            ServiceManager.SourceManager.SourceUpdated += delegate (SourceEventArgs args) {
                 TreeIter iter = FindSource (args.Source);
                 store.SetValue (iter, 1, args.Source.Order);
-                QueueDraw();
+                QueueDraw ();
             };
             
             ServiceManager.PlaybackController.SourceChanged += delegate {
@@ -122,6 +122,10 @@
             };
         }
         
+#endregion
+
+#region Gtk.Widget Overrides
+        
         protected override void OnRealized ()
         {
             base.OnRealized ();
@@ -129,8 +133,54 @@
             graphics = new ListViewGraphics (this);
             graphics.RefreshColors ();
         }
+
+        protected override bool OnButtonPressEvent (Gdk.EventButton evnt)
+        {
+            TreePath path;
+            
+            if (evnt.Button == 1) {
+                ResetHighlight ();
+            }
+            
+            if (!GetPathAtPos ((int)evnt.X, (int)evnt.Y, out path)) {
+                return true;
+            }
+
+            Source source = GetSource (path);
+            
+            if (evnt.Button == 1) {
+                if (!source.CanActivate) {
+                    if (!source.Expanded) {
+                        ExpandRow (path, false);
+                    } else {
+                        CollapseRow (path);
+                    }
+                    return false;
+                }
+                
+                if (ServiceManager.SourceManager.ActiveSource != source) {
+                    ServiceManager.SourceManager.SetActiveSource (source);
+                }
+                
+                if (evnt.Type == Gdk.EventType.TwoButtonPress) {
+                    OnSourceDoubleClicked ();
+                }
+            } else if (evnt.Button == 3) {
+                HighlightPath (path);
+                OnPopupMenu ();
+                return true;
+            }
+            
+            return base.OnButtonPressEvent(evnt);
+        }
+
+        protected override bool OnPopupMenu ()
+        {
+            ServiceManager.Get<InterfaceActionService> ().SourceActions["SourceContextMenuAction"].Activate ();
+            return true;
+        }
         
-        protected override bool OnExposeEvent (EventExpose evnt)
+        protected override bool OnExposeEvent (Gdk.EventExpose evnt)
         {
             try {
                 cr = Gdk.CairoHelper.Create (evnt.Window);
@@ -142,80 +192,148 @@
             }
         }
 
-        private TreeIter FindSource(Source source)
+#endregion
+
+#region Gtk.TreeView Overrides
+        
+        protected override void OnRowExpanded (TreeIter iter, TreePath path)
+        {
+            base.OnRowExpanded (iter, path);
+            GetSource (iter).Expanded = true;
+        }
+        
+        protected override void OnRowCollapsed (TreeIter iter, TreePath path)
+        {
+            base.OnRowCollapsed (iter, path);
+            GetSource (iter).Expanded = false;
+        }
+        
+        protected override void OnCursorChanged ()
+        {
+            if (current_timeout < 0) {
+                current_timeout = (int)GLib.Timeout.Add (200, OnCursorChangedTimeout);
+            }
+        }
+        
+        private bool OnCursorChangedTimeout ()
+        {
+            TreeIter iter;
+            TreeModel model;
+            
+            current_timeout = -1;
+            
+            if (!Selection.GetSelected (out model, out iter)) {
+                return false;
+            }
+            
+            Source new_source = store.GetValue (iter, 0) as Source;
+            if (ServiceManager.SourceManager.ActiveSource == new_source) {
+                return false;
+            }
+            
+            ServiceManager.SourceManager.SetActiveSource (new_source);
+            
+            QueueDraw ();
+
+            return false;
+        }
+        
+#endregion
+
+#region Source <-> Iter Methods
+
+        public Source GetSource (TreeIter iter)
+        {
+            return store.GetValue (iter, 0) as Source;
+        }
+        
+        public Source GetSource (TreePath path)
+        {
+            TreeIter iter;
+        
+            if (store.GetIter (out iter, path)) {
+                return GetSource (iter);
+            }
+        
+            return null;
+        }
+
+        private TreeIter FindSource (Source source)
         {
             TreeIter iter = TreeIter.Zero;
-            store.GetIterFirst(out iter);
-            return FindSource(source, iter);
+            store.GetIterFirst (out iter);
+            return FindSource (source, iter);
         }
         
-        private TreeIter FindSource(Source source, TreeIter iter)
+        private TreeIter FindSource (Source source, TreeIter iter)
         {
-            if(!store.IterIsValid(iter)) {
+            if (!store.IterIsValid (iter)) {
                 return TreeIter.Zero;
             }
             
             do {
-                if((store.GetValue(iter, 0) as Source) == source) {
+                if ((store.GetValue (iter, 0) as Source) == source) {
                     return iter;
                 }
                 
-                if(store.IterHasChild(iter)) {
+                if (store.IterHasChild (iter)) {
                     TreeIter citer = TreeIter.Zero;
-                    store.IterChildren(out citer, iter);
-                    TreeIter result = FindSource(source, citer);
-                    if(!result.Equals(TreeIter.Zero)) {
+                    store.IterChildren (out citer, iter);
+                    TreeIter result = FindSource (source, citer);
+                    
+                    if (!result.Equals (TreeIter.Zero)) {
                         return result;
                     }
                 }
-            } while(store.IterNext(ref iter));
+            } while (store.IterNext (ref iter));
             
             return TreeIter.Zero;
         }
-        
-        private void AddSource(Source source)
+
+#endregion
+
+#region Add/Remove Sources / SourceManager interaction
+
+        private void AddSource (Source source)
         {
-            AddSource(source, TreeIter.Zero);
+            AddSource (source, TreeIter.Zero);
         }
 
-        private void AddSource(Source source, TreeIter parent)
+        private void AddSource (Source source, TreeIter parent)
         {
             // Don't add duplicates
-            if(!FindSource(source).Equals(TreeIter.Zero))
+            if (!FindSource (source).Equals (TreeIter.Zero)) {
                 return;
-
+            }
+            
             // Don't add a child source before its parent
-            if(parent.Equals(TreeIter.Zero) && source.Parent != null)
+            if (parent.Equals (TreeIter.Zero) && source.Parent != null) {
                 return;
-
+            }
+            
             int position = source.Order;
             
-            TreeIter iter = parent.Equals(TreeIter.Zero)
-                ? store.InsertNode(position) 
-                : store.InsertNode(parent, position);
-            
-            store.SetValue(iter, 0, source);
-            store.SetValue(iter, 1, source.Order);
-
-            lock(source.Children) {
-                foreach(Source s in source.Children) {
-                    AddSource(s, iter);
+            TreeIter iter = parent.Equals (TreeIter.Zero)
+                ? store.InsertNode (position) 
+                : store.InsertNode (parent, position);
+            
+            store.SetValue (iter, 0, source);
+            store.SetValue (iter, 1, source.Order);
+
+            lock (source.Children) {
+                foreach (Source child in source.Children) {
+                    AddSource (child, iter);
                 }
             }
 
-            source.ChildSourceAdded += delegate(SourceEventArgs e) {
-                AddSource(e.Source, iter);
-            };
-
-            source.ChildSourceRemoved += delegate(SourceEventArgs e) {
-                RemoveSource(e.Source);
-            };
+            source.ChildSourceAdded += delegate (SourceEventArgs e) { AddSource (e.Source, iter); };
+            source.ChildSourceRemoved += delegate (SourceEventArgs e) { RemoveSource(e.Source); };
            
-            if(source.Expanded || (source.AutoExpand != null && source.AutoExpand.Value)) {
-                Expand(iter);
+            if (source.Expanded || (source.AutoExpand != null && source.AutoExpand.Value)) {
+                Expand (iter);
             }
             
-            if (source.Parent != null ) {
+            if (source.Parent != null) {
                 if (source.Parent.AutoExpand) {
                     Expand (FindSource (source.Parent));
                 }
@@ -224,39 +342,43 @@
             UpdateView ();
         }
 
-        private void RemoveSource(Source source)
+        private void RemoveSource (Source source)
         {
-            TreeIter iter = FindSource(source);
-            if(!iter.Equals(TreeIter.Zero)) {
-                store.Remove(ref iter);
+            TreeIter iter = FindSource (source);
+            if (!iter.Equals (TreeIter.Zero)) {
+                store.Remove (ref iter);
             }
 
-            UpdateView();
+            UpdateView ();
         }
     
-        private void Expand(TreeIter iter)
+        private void Expand (TreeIter iter)
         {
-            TreePath path = store.GetPath(iter);
-            ExpandRow(path, true);
+            TreePath path = store.GetPath (iter);
+            ExpandRow (path, true);
         }
-    
-        private void RefreshList()
+        
+        private void RefreshList ()
         {
-            store.Clear();
-            foreach(Source source in ServiceManager.SourceManager.Sources) {
-                AddSource(source);
+            store.Clear ();
+            foreach (Source source in ServiceManager.SourceManager.Sources) {
+                AddSource (source);
             }
         }
 
-        private bool UpdateView()
+#endregion
+
+#region List/View Utility Methods
+
+        private bool UpdateView ()
         {
-            for(int i = 0, m = store.IterNChildren(); i < m; i++) {
+            for (int i = 0, m = store.IterNChildren (); i < m; i++) {
                 TreeIter iter = TreeIter.Zero;
-                if(!store.IterNthChild(out iter, i)) {
+                if (!store.IterNthChild (out iter, i)) {
                     continue;
                 }
                 
-                if(store.IterNChildren(iter) > 0) {
+                if (store.IterNChildren (iter) > 0) {
                     ExpanderColumn = Columns[1];
                     return true;
                 }
@@ -266,362 +388,84 @@
             return false;
         }
         
-        protected override void OnRowExpanded(TreeIter iter, TreePath path)
-        {
-            base.OnRowExpanded(iter, path);
-            GetSource(iter).Expanded = true;
-        }
-        
-        protected override void OnRowCollapsed(TreeIter iter, TreePath path)
-        {
-            base.OnRowCollapsed(iter, path);
-            GetSource(iter).Expanded = false;
-        }
-        
-        protected void SourceCellDataFunc(TreeViewColumn tree_column,
-            CellRenderer cell, TreeModel tree_model, TreeIter iter)
-        {
-            SourceRowRenderer renderer = (SourceRowRenderer)cell;
-            renderer.view = this;
-            renderer.source = (Source)store.GetValue(iter, 0);
-            renderer.path = store.GetPath (iter);
-            
-            if(renderer.source == null) {
-                return;
-            }
-            
-            renderer.Selected = renderer.source.Equals(ServiceManager.SourceManager.ActiveSource);
-            //renderer.Italicized = renderer.source.Equals(newPlaylistSource);
-            renderer.Sensitive = renderer.source.CanActivate;
-        }
-        
-        internal void UpdateRow(TreePath path, string text)
+        internal void UpdateRow (TreePath path, string text)
         {
             TreeIter iter;
             
-            if(!store.GetIter(out iter, path)) {
+            if (!store.GetIter (out iter, path)) {
                 return;
             }
             
-            Source source = store.GetValue(iter, 0) as Source;
-            source.Rename(text);
+            Source source = store.GetValue (iter, 0) as Source;
+            source.Rename (text);
         }
         
-        public void BeginRenameSource(Source source)
+        public void BeginRenameSource (Source source)
         {
-            TreeIter iter = FindSource(source);
-            if(iter.Equals(TreeIter.Zero)) {
+            TreeIter iter = FindSource (source);
+            if (iter.Equals (TreeIter.Zero)) {
                 return;
             }
+            
             renderer.Editable = true;
-            SetCursor(store.GetPath(iter), focus_column, true);
+            SetCursor (store.GetPath (iter), focus_column, true);
             renderer.Editable = false;
         }
-
-        protected override bool OnButtonPressEvent(Gdk.EventButton evnt)
-        {
-            TreePath path;
-            
-            if (evnt.Button == 1) {
-                ResetHighlight ();
-            }
-            
-            if(!GetPathAtPos((int)evnt.X, (int)evnt.Y, out path)) {
-                return true;
-            }
-
-            Source source = GetSource(path);
-            if(evnt.Button == 1) {
-                if(!source.CanActivate) {
-                    if(!source.Expanded) {
-                        ExpandRow(path, false);
-                    } else {
-                        CollapseRow(path);
-                    }
-                    return false;
-                }
-                
-                if(ServiceManager.SourceManager.ActiveSource != source) {
-                    ServiceManager.SourceManager.SetActiveSource(source);
-                }
-                
-                if(evnt.Type == EventType.TwoButtonPress) {
-                    OnSourceDoubleClicked();
-                }
-                
-            } else if(evnt.Button == 3) {
-                HighlightPath(path);
-                OnPopupMenu ();
-                return true;
-            }
-            
-            return base.OnButtonPressEvent(evnt);
-        }
-
-        protected override bool OnPopupMenu ()
-        {
-            ServiceManager.Get<InterfaceActionService> ().SourceActions["SourceContextMenuAction"].Activate ();
-            return true;
-        }
-
-        protected override void OnCursorChanged()
-        {
-            if(currentTimeout < 0) {
-                currentTimeout = (int)GLib.Timeout.Add(200, OnCursorChangedTimeout);
-            }
-        }
         
-        private bool OnCursorChangedTimeout()
+        private void SourceCellDataFunc (TreeViewColumn tree_column, CellRenderer cell,  
+            TreeModel tree_model, TreeIter iter)
         {
-            TreeIter iter;
-            TreeModel model;
-            
-            currentTimeout = -1;
-            
-            if(!Selection.GetSelected(out model, out iter)) {
-                return false;
-            }
-            
-            Source new_source = store.GetValue(iter, 0) as Source;
-            if(ServiceManager.SourceManager.ActiveSource == new_source) {
-                return false;
-            }
-            
-            ServiceManager.SourceManager.SetActiveSource(new_source);
-            
-            QueueDraw();
-
-            return false;
-        }
-        
-        protected virtual void OnSourceDoubleClicked()
-        {
-            EventHandler handler = SourceDoubleClicked;
-            if(handler != null) {
-                handler(this, new EventArgs());
-            }
-        }
-
-        protected override void OnDragBegin(Gdk.DragContext context)
-        {
-            /*if(HighlightedSource.IsDragSource || HighlightedSource is IImportSource) {
-                base.OnDragBegin(context);
-            }*/
-        }
-        
-        protected override void OnDragDataGet(Gdk.DragContext context, SelectionData selectionData,
-            uint info, uint time)
-        {
-            switch((DragDropTargetType)info) {
-                case DragDropTargetType.Source:
-                    new DragDropList<Source>(HighlightedSource, selectionData, context.Targets[0]);
-                    break;
-                default:
-                    return;
-            }
-            
-            base.OnDragDataGet(context, selectionData, info, time);
-        }
-        
-        protected override bool OnDragMotion(Gdk.DragContext context, int x, int y, uint time)
-        {
-            /*if(Gtk.Drag.GetSourceWidget(context) == this 
-                && !HighlightedSource.IsDragSource && !(HighlightedSource is IImportSource)) {
-                return false;
-            }
-        
-            base.OnDragMotion(context, x, y, time);
-            SetDragDestRow(null, TreeViewDropPosition.IntoOrAfter);
-            Gdk.Drag.Status(context, Gdk.DragAction.Copy, time);
-
-            // FIXME: We need to handle this nicer
-            if(Gtk.Drag.GetSourceWidget(context) != this && 
-                !(ServiceManager.SourceManager.ActiveSource is LibrarySource ||
-                ServiceManager.SourceManager.ActiveSource is PlaylistSource ||
-                ServiceManager.SourceManager.ActiveSource is Banshee.SmartPlaylist.SmartPlaylistSource ||
-                ServiceManager.SourceManager.ActiveSource is IImportable)) {
-                return false;
-            }
-        
-            if(!newPlaylistVisible && Gtk.Drag.GetSourceWidget(context) != this) {
-                TreeIter library = FindSource(LibrarySource.Instance);
-                newPlaylistIter = store.AppendNode(library);
-                store.SetValue(newPlaylistIter, 0, newPlaylistSource);
-                store.SetValue(newPlaylistIter, 1, 999);
-                newPlaylistVisible = true;
-
-                UpdateView();
-                Expand(library);
-            }
-        
-            TreePath path;
-            TreeViewDropPosition pos;
-            
-            if(GetDestRowAtPos(x, y, out path, out pos)) {
-                Source source = GetSource(path);
-                
-                if(source == ServiceManager.SourceManager.ActiveSource) {
-                    return false;
-                }
-                
-                SetDragDestRow(path, TreeViewDropPosition.IntoOrAfter);
-                
-                if((source is LibrarySource && (ServiceManager.SourceManager.ActiveSource is IImportable 
-                    || ServiceManager.SourceManager.ActiveSource is IImportSource)) ||
-                    (source is PlaylistSource) || (source is DapSource) || source.AcceptsInput) {
-                    return true;
-                }
-
-                Gdk.Drag.Status(context, 0, time);
-                return true;
-            }*/
-            
-            return true;
-        }
-        
-        private Source final_drag_source = null;
-        private uint final_drag_start_time = 0;
-    
-        protected override void OnDragLeave(Gdk.DragContext context, uint time)
-        {
-            /*TreePath path;
-            TreeViewDropPosition pos;
-            GetDragDestRow (out path, out pos);
-
-            if(path == null) {
-                path = store.GetPath(newPlaylistIter);
-            }
+            SourceRowRenderer renderer = (SourceRowRenderer)cell;
+            renderer.view = this;
+            renderer.source = (Source)store.GetValue (iter, 0);
+            renderer.path = store.GetPath (iter);
             
-            final_drag_source = GetSource (path);
-            final_drag_start_time = context.StartTime;
-        
-            if(newPlaylistVisible) {
-                store.Remove(ref newPlaylistIter);
-                newPlaylistVisible = false;
-                UpdateView();
-            }*/
-        }
-
-        protected override void OnDragDataReceived(Gdk.DragContext context, int x, int y,
-            Gtk.SelectionData selectionData, uint info, uint time)
-        {
-            /*if(Gtk.Drag.GetSourceWidget(context) == this) {
-                DragDropList<Source> sources = selectionData;
-                if(sources.Count <= 0) { 
-                    return;
-                }
-                
-                Source source = sources[0];
-                
-                if(source is IImportSource && final_drag_source is LibrarySource) {
-                    (source as IImportSource).Import();
-                    Gtk.Drag.Finish(context, true, false, time);
-                } else if(final_drag_source != null && source.IsDragSource && 
-                    final_drag_source.AcceptsSourceDrop) {
-                    final_drag_source.SourceDrop(source);
-                    Gtk.Drag.Finish(context, true, false, time);
-                } else {
-                    Gtk.Drag.Finish(context, false, false, time);
-                }
-                
+            if (renderer.source == null) {
                 return;
             }
             
-            if(final_drag_start_time == context.StartTime) {
-                PlaylistSource playlist_remove_on_failure = null;
-                try {
-                    DragDropList<TrackInfo> dnd_transfer = selectionData;
-                    TrackDropOperation(final_drag_source, dnd_transfer, out playlist_remove_on_failure);
-                } catch(Exception e) {
-                    if(playlist_remove_on_failure != null) {
-                        playlist_remove_on_failure.Unmap();
-                        playlist_remove_on_failure = null;
-                    }
-                    
-                    LogCore.Instance.PushError(Catalog.GetString("Could not import tracks"), e.Message);
-                }
-            }
-            
-            if(newPlaylistVisible) {
-                store.Remove(ref newPlaylistIter);
-                newPlaylistVisible = false;
-                UpdateView();
-            }
-        
-            Gtk.Drag.Finish(context, true, false, time);*/
-        }
-        
-        private void TrackDropOperation(Source source, IList<TrackInfo> tracks, 
-            out PlaylistSource newPlaylist)
-        {
-            newPlaylist = null;
-            
-            /*if(source is LibrarySource && ServiceManager.SourceManager.ActiveSource is IImportable) {
-                IImportable import_source = ServiceManager.SourceManager.ActiveSource as IImportable;
-                import_source.Import(tracks);
-            } else if(source is PlaylistSource && ServiceManager.SourceManager.ActiveSource is IImportable) {
-                IImportable import_source = ServiceManager.SourceManager.ActiveSource as IImportable;
-                PlaylistSource playlist = null;
-                    
-                if(source == newPlaylistSource) {
-                    playlist = new PlaylistSource();
-                    LibrarySource.Instance.AddChildSource(playlist);
-                    newPlaylist = playlist;
-                } else {
-                    playlist = source as PlaylistSource;
-                }
-                    
-                import_source.Import(tracks, playlist);
-            } else if(source == newPlaylistSource) {
-                PlaylistSource playlist = new PlaylistSource();
-                playlist.AddTrack(tracks);
-                playlist.Rename(PlaylistUtil.GoodUniqueName(playlist.Tracks));
-                playlist.Commit();
-                LibrarySource.Instance.AddChildSource(playlist);
-                UpdateView();
-            } else if(source is PlaylistSource || source is DapSource || source.AcceptsInput) {
-                source.AddTrack(tracks);
-                source.Commit();
-            }*/
-        }
-        
-        public Source GetSource(TreeIter iter)
-        {
-            return store.GetValue(iter, 0) as Source;
-        }
-        
-        public Source GetSource(TreePath path)
-        {
-            TreeIter iter;
-        
-            if(store.GetIter(out iter, path)) {
-                return GetSource(iter);
-            }
-        
-            return null;
+            renderer.Selected = renderer.source.Equals (ServiceManager.SourceManager.ActiveSource);
+            //renderer.Italicized = renderer.source.Equals (new_playlist_source);
+            renderer.Sensitive = renderer.source.CanActivate;
         }
         
-        private void ResetSelection()
+        private void ResetSelection ()
         {
             TreeIter iter = FindSource (ServiceManager.SourceManager.ActiveSource);
             
-            if(!iter.Equals(TreeIter.Zero)){
-                Selection.SelectIter(iter);
+            if (!iter.Equals (TreeIter.Zero)){
+                Selection.SelectIter (iter);
             }
         }
         
-        public void HighlightPath(TreePath path)
+        public void HighlightPath (TreePath path)
         {
             highlight_path = path;
             QueueDraw ();
         }
         
-        public void ResetHighlight()
+        public void ResetHighlight ()
         {   
             highlight_path = null;
             QueueDraw ();
         }
         
+#endregion
+
+#region Virtual Methods
+        
+        protected virtual void OnSourceDoubleClicked ()
+        {
+            EventHandler handler = SourceDoubleClicked;
+            if (handler != null) {
+                handler (this, EventArgs.Empty);
+            }
+        }
+
+#endregion
+
+#region Public Properties
+                
         public Source HighlightedSource {
             get {
                 TreeModel model;
@@ -631,10 +475,22 @@
                     return null;
                 }
                     
-                return store.GetValue(iter, 0) as Source;
+                return store.GetValue (iter, 0) as Source;
+            }
+        }
+
+        public bool EditingRow {
+            get { return editing_row; }
+            set { 
+                editing_row = value;
+                QueueDraw (); 
             }
         }
         
+#endregion
+
+#region Internal Properties
+      
         internal TreePath HighlightedPath {
             get { return highlight_path; }
         }
@@ -647,10 +503,7 @@
             get { return graphics; }
         }
 
-        private bool editing_row = false;
-        public bool EditingRow {
-            get { return editing_row; }
-            set { editing_row = value; }
-        }
+#endregion        
+
     }
 }

Added: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView_DragAndDrop.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView_DragAndDrop.cs	Thu Jan 31 00:10:59 2008
@@ -0,0 +1,244 @@
+//
+// SourceView_DragAndDrop.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 2005-2008 Novell, Inc.
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+
+using System;
+using System.Collections.Generic;
+
+using Gtk;
+using Gdk;
+
+using Banshee.Collection;
+using Banshee.Playlist;
+
+using Banshee.Gui.DragDrop;
+
+namespace Banshee.Sources.Gui
+{
+    public partial class SourceView
+    {
+        private static TargetEntry [] dnd_source_entries = new TargetEntry [] {
+            Banshee.Gui.DragDrop.DragDropTarget.Source
+        };
+            
+        private static TargetEntry [] dnd_dest_entries = new TargetEntry [] {
+            Banshee.Gui.DragDrop.DragDropTarget.TrackInfoObjects,
+            Banshee.Gui.DragDrop.DragDropTarget.Source
+        };
+    
+            
+        private void ConfigureDragAndDrop ()
+        {
+            EnableModelDragSource (Gdk.ModifierType.Button1Mask | Gdk.ModifierType.Button3Mask,
+                dnd_source_entries, DragAction.Copy | DragAction.Move);
+        
+            EnableModelDragDest (dnd_dest_entries, DragAction.Copy | DragAction.Move);
+        }
+        
+        protected override void OnDragBegin (Gdk.DragContext context)
+        {
+            /*if(HighlightedSource.IsDragSource || HighlightedSource is IImportSource) {
+                base.OnDragBegin(context);
+            }*/
+        }
+        
+        protected override void OnDragDataGet (Gdk.DragContext context, SelectionData selectionData,
+            uint info, uint time)
+        {
+            switch ((DragDropTargetType)info) {
+                case DragDropTargetType.Source:
+                    new DragDropList<Source> (HighlightedSource, selectionData, context.Targets[0]);
+                    break;
+                default:
+                    return;
+            }
+            
+            base.OnDragDataGet (context, selectionData, info, time);
+        }
+        
+        protected override bool OnDragMotion (Gdk.DragContext context, int x, int y, uint time)
+        {
+            /*if(Gtk.Drag.GetSourceWidget(context) == this 
+                && !HighlightedSource.IsDragSource && !(HighlightedSource is IImportSource)) {
+                return false;
+            }
+        
+            base.OnDragMotion(context, x, y, time);
+            SetDragDestRow(null, TreeViewDropPosition.IntoOrAfter);
+            Gdk.Drag.Status(context, Gdk.DragAction.Copy, time);
+
+            // FIXME: We need to handle this nicer
+            if(Gtk.Drag.GetSourceWidget(context) != this && 
+                !(ServiceManager.SourceManager.ActiveSource is LibrarySource ||
+                ServiceManager.SourceManager.ActiveSource is PlaylistSource ||
+                ServiceManager.SourceManager.ActiveSource is Banshee.SmartPlaylist.SmartPlaylistSource ||
+                ServiceManager.SourceManager.ActiveSource is IImportable)) {
+                return false;
+            }
+        
+            if(!new_playlist_visible && Gtk.Drag.GetSourceWidget(context) != this) {
+                TreeIter library = FindSource(LibrarySource.Instance);
+                new_playlist_iter = store.AppendNode(library);
+                store.SetValue(new_playlist_iter, 0, new_playlist_source);
+                store.SetValue(new_playlist_iter, 1, 999);
+                new_playlist_visible = true;
+
+                UpdateView();
+                Expand(library);
+            }
+        
+            TreePath path;
+            TreeViewDropPosition pos;
+            
+            if(GetDestRowAtPos(x, y, out path, out pos)) {
+                Source source = GetSource(path);
+                
+                if(source == ServiceManager.SourceManager.ActiveSource) {
+                    return false;
+                }
+                
+                SetDragDestRow(path, TreeViewDropPosition.IntoOrAfter);
+                
+                if((source is LibrarySource && (ServiceManager.SourceManager.ActiveSource is IImportable 
+                    || ServiceManager.SourceManager.ActiveSource is IImportSource)) ||
+                    (source is PlaylistSource) || (source is DapSource) || source.AcceptsInput) {
+                    return true;
+                }
+
+                Gdk.Drag.Status(context, 0, time);
+                return true;
+            }*/
+            
+            return true;
+        }
+        
+        private Source final_drag_source = null;
+        private uint final_drag_start_time = 0;
+    
+        protected override void OnDragLeave (Gdk.DragContext context, uint time)
+        {
+            /*TreePath path;
+            TreeViewDropPosition pos;
+            GetDragDestRow (out path, out pos);
+
+            if(path == null) {
+                path = store.GetPath(new_playlist_iter);
+            }
+            
+            final_drag_source = GetSource (path);
+            final_drag_start_time = context.StartTime;
+        
+            if(new_playlist_visible) {
+                store.Remove(ref new_playlist_iter);
+                new_playlist_visible = false;
+                UpdateView();
+            }*/
+        }
+
+        protected override void OnDragDataReceived (Gdk.DragContext context, int x, int y,
+            Gtk.SelectionData selectionData, uint info, uint time)
+        {
+            /*if(Gtk.Drag.GetSourceWidget(context) == this) {
+                DragDropList<Source> sources = selectionData;
+                if(sources.Count <= 0) { 
+                    return;
+                }
+                
+                Source source = sources[0];
+                
+                if(source is IImportSource && final_drag_source is LibrarySource) {
+                    (source as IImportSource).Import();
+                    Gtk.Drag.Finish(context, true, false, time);
+                } else if(final_drag_source != null && source.IsDragSource && 
+                    final_drag_source.AcceptsSourceDrop) {
+                    final_drag_source.SourceDrop(source);
+                    Gtk.Drag.Finish(context, true, false, time);
+                } else {
+                    Gtk.Drag.Finish(context, false, false, time);
+                }
+                
+                return;
+            }
+            
+            if(final_drag_start_time == context.StartTime) {
+                PlaylistSource playlist_remove_on_failure = null;
+                try {
+                    DragDropList<TrackInfo> dnd_transfer = selectionData;
+                    TrackDropOperation(final_drag_source, dnd_transfer, out playlist_remove_on_failure);
+                } catch(Exception e) {
+                    if(playlist_remove_on_failure != null) {
+                        playlist_remove_on_failure.Unmap();
+                        playlist_remove_on_failure = null;
+                    }
+                    
+                    LogCore.Instance.PushError(Catalog.GetString("Could not import tracks"), e.Message);
+                }
+            }
+            
+            if(new_playlist_visible) {
+                store.Remove(ref new_playlist_iter);
+                new_playlist_visible = false;
+                UpdateView();
+            }
+        
+            Gtk.Drag.Finish(context, true, false, time);*/
+        }
+        
+        private void TrackDropOperation (Source source, IList<TrackInfo> tracks, out PlaylistSource newPlaylist)
+        {
+            newPlaylist = null;
+            
+            /*if(source is LibrarySource && ServiceManager.SourceManager.ActiveSource is IImportable) {
+                IImportable import_source = ServiceManager.SourceManager.ActiveSource as IImportable;
+                import_source.Import(tracks);
+            } else if(source is PlaylistSource && ServiceManager.SourceManager.ActiveSource is IImportable) {
+                IImportable import_source = ServiceManager.SourceManager.ActiveSource as IImportable;
+                PlaylistSource playlist = null;
+                    
+                if(source == new_playlist_source) {
+                    playlist = new PlaylistSource();
+                    LibrarySource.Instance.AddChildSource(playlist);
+                    newPlaylist = playlist;
+                } else {
+                    playlist = source as PlaylistSource;
+                }
+                    
+                import_source.Import(tracks, playlist);
+            } else if(source == new_playlist_source) {
+                PlaylistSource playlist = new PlaylistSource();
+                playlist.AddTrack(tracks);
+                playlist.Rename(PlaylistUtil.GoodUniqueName(playlist.Tracks));
+                playlist.Commit();
+                LibrarySource.Instance.AddChildSource(playlist);
+                UpdateView();
+            } else if(source is PlaylistSource || source is DapSource || source.AcceptsInput) {
+                source.AddTrack(tracks);
+                source.Commit();
+            }*/
+        }
+    }
+}

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.ThickClient.mdp	Thu Jan 31 00:10:59 2008
@@ -78,6 +78,7 @@
     <File name="Banshee.Equalizer.Gui/EqualizerWindow.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Sources.Gui/CellEditEntry.cs" subtype="Code" buildaction="Compile" />
     <File name="Banshee.Sources.Gui/SourceRowRenderer.cs" subtype="Code" buildaction="Compile" />
+    <File name="Banshee.Sources.Gui/SourceView_DragAndDrop.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Project" localcopy="False" refto="Hyena.Gui" />

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Makefile.am	Thu Jan 31 00:10:59 2008
@@ -61,7 +61,8 @@
 	Banshee.Library.Gui/ImportDialog.cs \
 	Banshee.Sources.Gui/CellEditEntry.cs \
 	Banshee.Sources.Gui/SourceRowRenderer.cs \
-	Banshee.Sources.Gui/SourceView.cs
+	Banshee.Sources.Gui/SourceView.cs \
+	Banshee.Sources.Gui/SourceView_DragAndDrop.cs
 
 RESOURCES =  \
 	Banshee.ThickClient.addin.xml \



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