[longomatch] Fix index selection after moving playlist items
- From: Andoni Morales Alastruey <amorales src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [longomatch] Fix index selection after moving playlist items
- Date: Wed, 11 Feb 2015 15:59:33 +0000 (UTC)
commit 181b09b85f8e77789243af8bef5da88871a88357
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date: Wed Feb 11 16:56:40 2015 +0100
Fix index selection after moving playlist items
LongoMatch.Core/Store/Playlists/Playlist.cs | 19 ++++++++++++++++++-
LongoMatch.GUI/Gui/TreeView/PlayListTreeView.cs | 23 +++++++++++++++++------
2 files changed, 35 insertions(+), 7 deletions(-)
---
diff --git a/LongoMatch.Core/Store/Playlists/Playlist.cs b/LongoMatch.Core/Store/Playlists/Playlist.cs
index 3f3a338..e8204bc 100644
--- a/LongoMatch.Core/Store/Playlists/Playlist.cs
+++ b/LongoMatch.Core/Store/Playlists/Playlist.cs
@@ -51,6 +51,18 @@ namespace LongoMatch.Core.Store.Playlists
return indexSelection;
}
}
+
+ public IPlaylistElement Selected {
+ get {
+ if (Elements.Count == 0) {
+ return null;
+ }
+ if (indexSelection >= Elements.Count) {
+ indexSelection = 0;
+ }
+ return Elements [indexSelection];
+ }
+ }
#endregion
#region Public methods
public IPlaylistElement Next ()
@@ -103,7 +115,12 @@ namespace LongoMatch.Core.Store.Playlists
public void SetActive (IPlaylistElement play)
{
- indexSelection = Elements.IndexOf (play);
+ int newIndex;
+
+ newIndex = Elements.IndexOf (play);
+ if (newIndex >= 0) {
+ indexSelection = Elements.IndexOf (play);
+ }
}
public bool HasNext ()
diff --git a/LongoMatch.GUI/Gui/TreeView/PlayListTreeView.cs b/LongoMatch.GUI/Gui/TreeView/PlayListTreeView.cs
index 31e72a0..0bb5092 100644
--- a/LongoMatch.GUI/Gui/TreeView/PlayListTreeView.cs
+++ b/LongoMatch.GUI/Gui/TreeView/PlayListTreeView.cs
@@ -249,9 +249,10 @@ namespace LongoMatch.Gui.Component
TreeViewDropPosition pos;
Playlist destPlaylist;
IPlaylistElement destElement;
+ TreeStore store = Model as TreeStore;
if (GetDestRowAtPos (x, y, out path, out pos)) {
- Model.GetIter (out iter, path);
+ store.GetIter (out iter, path);
FillElementAndPlaylist (iter, out destPlaylist, out destElement);
/* Moving playlists */
@@ -260,25 +261,35 @@ namespace LongoMatch.Gui.Component
project.Playlists.Insert (path.Indices [0], dragSourcePlaylist);
if (pos == TreeViewDropPosition.Before ||
pos == TreeViewDropPosition.IntoOrBefore) {
- (Model as TreeStore).MoveBefore (selectedIter, iter);
+ store.MoveBefore (selectedIter, iter);
} else {
- (Model as TreeStore).MoveAfter (selectedIter, iter);
+ store.MoveAfter (selectedIter, iter);
}
} else {
/* For elements moves can happen between 2 playlists and
Move{Before|After}
* requires iter to have the same parent */
TreeIter newIter;
+ IPlaylistElement srcCurrent, dstCurrent;
+
if (pos == TreeViewDropPosition.Before ||
pos == TreeViewDropPosition.IntoOrBefore) {
newIter = (Model as TreeStore).InsertNodeBefore (iter);
} else {
newIter = (Model as TreeStore).InsertNodeAfter (iter);
}
- Model.SetValue (newIter, 0, dragSourceElement);
- (Model as TreeStore).Remove (ref selectedIter);
+ store.SetValue (newIter, 0, dragSourceElement);
+ store.Remove (ref selectedIter);
+
+ srcCurrent = dragSourcePlaylist.Selected;
+ dstCurrent = destPlaylist.Selected;
dragSourcePlaylist.Elements.Remove (dragSourceElement);
- destPlaylist.Elements.Insert (path.Indices [1], dragSourceElement);
+ destPlaylist.Elements.Insert (store.GetPath (newIter).Indices [1],
dragSourceElement);
+
+ if (dragSourcePlaylist != destPlaylist) {
+ dragSourcePlaylist.SetActive (srcCurrent);
+ }
+ destPlaylist.SetActive (dstCurrent);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]