banshee r3395 - in trunk/banshee: . src/Core/Banshee.ThickClient/Banshee.Collection.Gui src/Core/Banshee.ThickClient/Banshee.Gui.DragDrop src/Core/Banshee.ThickClient/Banshee.Sources.Gui src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio src/Libraries/Hyena.Gui src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView



Author: abock
Date: Fri Mar  7 21:43:24 2008
New Revision: 3395
URL: http://svn.gnome.org/viewvc/banshee?rev=3395&view=rev

Log:
2008-03-07  Aaron Bockover  <abock gnome org>

    * src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_DragAndDrop.cs:
    Added another partial class for drag and drop specific stuff for the
    view; implement variable velocity scrolling when dragging rows in the
    view; it's awesome; added a Reorderable property, but it does not do
    anything yet (other than the awesome scrolling)

    * src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs:
    Moved some DnD code into the new partial class

    * src/Core/Banshee.ThickClient/Banshee.Collection.Gui/TrackListView.cs:
    Set Reorderable and ForceDragSourceSet properties

    * src/Core/Banshee.ThickClient/Banshee.Gui.DragDrop/DragDropTarget.cs:
    Removed the model selection target

    * src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView_DragAndDrop.cs:
    Use the model selection target from hyena

    * src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSourceContents.cs:
    Fixed a crasher/NRE



Added:
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_DragAndDrop.cs
Modified:
   trunk/banshee/ChangeLog
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/TrackListView.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.DragDrop/DragDropTarget.cs
   trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView_DragAndDrop.cs
   trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSourceContents.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs
   trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.mdp
   trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/TrackListView.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/TrackListView.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/TrackListView.cs	Fri Mar  7 21:43:24 2008
@@ -37,7 +37,6 @@
 using Hyena.Data.Gui;
 
 using Banshee.Gui;
-using Banshee.Gui.DragDrop;
 using Banshee.ServiceStack;
 using Banshee.MediaEngine;
 using Banshee.Collection;
@@ -99,6 +98,9 @@
                 overlay = new BetaReleaseViewOverlay (this);
                 overlay.Finished += OnOverlayFinished;
             }
+            
+            ForceDragSourceSet = true;
+            Reorderable = true;
         }
         
         private void OnOverlayFinished (object o, EventArgs args)
@@ -128,23 +130,15 @@
         
 #region Drag and Drop
 
-        private static TargetEntry [] dnd_source_entries = new TargetEntry [] {
-            DragDropTarget.ModelSelection
-        };
-
         protected override void OnDragSourceSet ()
         {
-            Gtk.Drag.SourceSet (this, Gdk.ModifierType.Button1Mask | Gdk.ModifierType.Button3Mask, 
-                dnd_source_entries, Gdk.DragAction.Copy | Gdk.DragAction.Move);
-            
+            base.OnDragSourceSet ();
             Drag.SourceSetIconName (this, "audio-x-generic");
         }
 
         protected override void OnDragDataGet (Gdk.DragContext context, SelectionData selection_data, uint info, uint time)
         {
-            DragDropTargetType type = (DragDropTargetType)info;
-            
-            if (type != DragDropTargetType.ModelSelection || Selection.Count <= 0) {
+            if (info != (int)ListViewDragDropTarget.TargetType.ModelSelection || Selection.Count <= 0) {
                 return;
             }
         }

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.DragDrop/DragDropTarget.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.DragDrop/DragDropTarget.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Gui.DragDrop/DragDropTarget.cs	Fri Mar  7 21:43:24 2008
@@ -33,7 +33,6 @@
 {
     public enum DragDropTargetType {
         Source,
-        ModelSelection,
         UriList
     };
         
@@ -43,10 +42,6 @@
             new TargetEntry ("application/x-banshee-source", TargetFlags.App, 
                 (uint)DragDropTargetType.Source);
 
-        public static readonly TargetEntry ModelSelection =
-            new TargetEntry ("application/x-banshee-model-selection", TargetFlags.App,
-                (uint)DragDropTargetType.ModelSelection);
-
         public static readonly TargetEntry UriList = 
             new TargetEntry ("text/uri-list", 0, (uint)DragDropTargetType.UriList);
     }

Modified: trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView_DragAndDrop.cs
==============================================================================
--- trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView_DragAndDrop.cs	(original)
+++ trunk/banshee/src/Core/Banshee.ThickClient/Banshee.Sources.Gui/SourceView_DragAndDrop.cs	Fri Mar  7 21:43:24 2008
@@ -51,7 +51,7 @@
             
         private static TargetEntry [] dnd_dest_entries = new TargetEntry [] {
             Banshee.Gui.DragDrop.DragDropTarget.Source,
-            Banshee.Gui.DragDrop.DragDropTarget.ModelSelection
+            Hyena.Data.Gui.ListViewDragDropTarget.ModelSelection
         };
         
         private Source new_playlist_source = new PlaylistSource (Catalog.GetString ("New Playlist"));

Modified: trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSourceContents.cs
==============================================================================
--- trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSourceContents.cs	(original)
+++ trunk/banshee/src/Extensions/Banshee.Lastfm/Banshee.Lastfm.Radio/LastfmSourceContents.cs	Fri Mar  7 21:43:24 2008
@@ -106,7 +106,9 @@
         {
             if (args.State == ConnectionState.Connected) {
                 Banshee.Base.ThreadAssist.ProxyToMain (delegate {
-                    UpdateForUser (lastfm.Account.UserName);
+                    if (lastfm != null && lastfm.Account != null) {
+                        UpdateForUser (lastfm.Account.UserName);
+                    }
                 });
             }
         }

Added: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_DragAndDrop.cs
==============================================================================
--- (empty file)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_DragAndDrop.cs	Fri Mar  7 21:43:24 2008
@@ -0,0 +1,166 @@
+//
+// ListView_DragAndDrop.cs
+//
+// Author:
+//   Aaron Bockover <abockover novell com>
+//
+// Copyright (C) 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 Gtk;
+
+namespace Hyena.Data.Gui
+{    
+    public static class ListViewDragDropTarget
+    {
+        public enum TargetType
+        {
+            ModelSelection
+        }
+        
+        public static readonly TargetEntry ModelSelection =
+            new TargetEntry ("application/x-hyena-data-model-selection", TargetFlags.App,
+                (uint)TargetType.ModelSelection);
+    }
+    
+    public partial class ListView<T> : Container
+    {
+        private static TargetEntry [] drag_drop_dest_entries = new TargetEntry [] {
+            ListViewDragDropTarget.ModelSelection
+        };
+        
+        protected static TargetEntry [] DragDropDestEntries {
+            get { return drag_drop_dest_entries; }
+        }
+        
+        private bool reorderable = false;
+        public bool Reorderable {
+            get { return reorderable; }
+            set {
+                reorderable = value;
+                OnDragSourceSet ();
+                OnDragDestSet ();
+            }
+        }
+        
+        private bool force_drag_source_set = false;
+        protected bool ForceDragSourceSet {
+            get { return force_drag_source_set; }
+            set {
+                force_drag_source_set = true;
+                OnDragSourceSet ();
+            }
+        }
+        
+        private bool force_drag_dest_set = false;
+        protected bool ForceDragDestSet {
+            get { return force_drag_dest_set; }
+            set {
+                force_drag_dest_set = true;
+                OnDragDestSet ();
+            }
+        }
+        
+        protected virtual void OnDragDestSet ()
+        {
+            if (ForceDragDestSet || Reorderable) {
+                Gtk.Drag.DestSet (this, DestDefaults.All, DragDropDestEntries, Gdk.DragAction.Move);
+            } else {
+                Gtk.Drag.DestUnset (this);
+            }
+        }
+        
+        protected virtual void OnDragSourceSet ()
+        {
+            if (ForceDragSourceSet || Reorderable) {
+                Gtk.Drag.SourceSet (this, Gdk.ModifierType.Button1Mask | Gdk.ModifierType.Button3Mask, 
+                    DragDropDestEntries, Gdk.DragAction.Copy | Gdk.DragAction.Move);
+            } else {
+                Gtk.Drag.SourceUnset (this);
+            }
+        }
+        
+        private uint drag_scroll_timeout_id;
+        private double drag_scroll_velocity;
+        private double drag_scroll_velocity_max = 100.0;
+        
+        private void StopDragScroll ()
+        {
+            drag_scroll_velocity = 0.0;
+            
+            if (drag_scroll_timeout_id > 0) {
+                GLib.Source.Remove (drag_scroll_timeout_id);
+                drag_scroll_timeout_id = 0;
+            }
+        }
+        
+        protected override bool OnDragMotion (Gdk.DragContext context, int x, int y, uint time)
+        {
+            if (!Reorderable) {
+                return false;
+            }
+            
+            double scroll_threshold = Allocation.Height * 0.2;
+            
+            if (y < scroll_threshold) {
+                drag_scroll_velocity = -1.0 + (y / scroll_threshold);
+            } else if (y > Allocation.Height - scroll_threshold) {
+                drag_scroll_velocity = 1.0 - ((Allocation.Height - y) / scroll_threshold);
+            } else {
+                StopDragScroll ();
+                return true;
+            }
+            
+            if (drag_scroll_timeout_id == 0) {
+                drag_scroll_timeout_id = GLib.Timeout.Add (50, OnDragScrollTimeout);
+            }
+            
+            return true;
+        }
+        
+        protected override void OnDragLeave (Gdk.DragContext context, uint time)
+        {
+            StopDragScroll ();
+        }
+        
+        protected override void OnDragEnd (Gdk.DragContext context)
+        {
+            StopDragScroll ();
+        }
+        
+        private bool OnDragScrollTimeout ()
+        {
+            double actual_velocity = drag_scroll_velocity * drag_scroll_velocity_max;
+            
+            if (vadjustment.Value + actual_velocity < vadjustment.Lower) {
+                vadjustment.Value = vadjustment.Lower;
+            } else if (vadjustment.Value + actual_velocity > vadjustment.Upper - vadjustment.PageSize) {
+                vadjustment.Value = vadjustment.Upper - vadjustment.PageSize;
+            } else {
+                vadjustment.Value += actual_velocity;
+            }
+            
+            return true;
+        }
+    }
+}

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs	Fri Mar  7 21:43:24 2008
@@ -443,14 +443,6 @@
 
 #endregion
 
-#region Drag and Drop
-
-        protected virtual void OnDragSourceSet ()
-        {
-        }
-        
-#endregion
-
 #region Adjustments & Scrolling
 
         private void UpdateAdjustments (Adjustment hadj, Adjustment vadj)

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.mdp
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.mdp	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Hyena.Gui.mdp	Fri Mar  7 21:43:24 2008
@@ -53,6 +53,7 @@
     <File name="Hyena.Gui.Theming/GtkColors.cs" subtype="Code" buildaction="Compile" />
     <File name="Hyena.Gui.Theming/ThemeContext.cs" subtype="Code" buildaction="Compile" />
     <File name="Hyena.Gui.Theming/GtkTheme.cs" subtype="Code" buildaction="Compile" />
+    <File name="Hyena.Data.Gui/ListView/ListView_DragAndDrop.cs" subtype="Code" buildaction="Compile" />
   </Contents>
   <References>
     <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

Modified: trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am
==============================================================================
--- trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am	(original)
+++ trunk/banshee/src/Libraries/Hyena.Gui/Makefile.am	Fri Mar  7 21:43:24 2008
@@ -11,6 +11,7 @@
 	Hyena.Data.Gui/ColumnHeaderCellText.cs \
 	Hyena.Data.Gui/IHeaderCell.cs \
 	Hyena.Data.Gui/ListView/ListView.cs \
+	Hyena.Data.Gui/ListView/ListView_DragAndDrop.cs \
 	Hyena.Data.Gui/ListView/ListView_Header.cs \
 	Hyena.Data.Gui/ListView/ListView_Interaction.cs \
 	Hyena.Data.Gui/ListView/ListView_Model.cs \



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