[banshee] Keep the playing song visible in the track list
- From: Gabriel Burt <gburt src gnome org>
- To: svn-commits-list gnome org
- Subject: [banshee] Keep the playing song visible in the track list
- Date: Wed, 1 Jul 2009 16:11:02 +0000 (UTC)
commit db62ad34cc928e932a77c0bb9773a04e4be0c229
Author: Alexander Kojevnikov <alexander kojevnikov com>
Date: Wed Jul 1 11:07:00 2009 -0500
Keep the playing song visible in the track list
Signed-off-by: Gabriel Burt <gabriel burt gmail com>
.../Banshee.Collection.Gui/BaseTrackListView.cs | 60 +++++++++++++++++++-
.../Banshee.Collection.Gui/TrackFilterListView.cs | 6 ++
.../ListView/ListView_Interaction.cs | 26 ++++++++-
.../Hyena.Data.Gui/ListView/ListView_Model.cs | 13 ----
.../Hyena.Data.Gui/ListView/ListView_Windowing.cs | 2 +-
5 files changed, 89 insertions(+), 18 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/BaseTrackListView.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/BaseTrackListView.cs
index 50b5690..0d21bc4 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/BaseTrackListView.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/BaseTrackListView.cs
@@ -34,6 +34,7 @@ using Hyena.Data;
using Hyena.Data.Gui;
using Hyena.Gui;
+using Banshee.Collection.Database;
using Banshee.Sources;
using Banshee.ServiceStack;
using Banshee.MediaEngine;
@@ -51,7 +52,8 @@ namespace Banshee.Collection.Gui
RowSensitivePropertyName = "CanPlay";
RowBoldPropertyName = "IsPlaying";
- ServiceManager.PlayerEngine.ConnectEvent (OnPlayerEvent, PlayerEvent.StateChange);
+ ServiceManager.PlayerEngine.ConnectEvent (
+ OnPlayerEvent, PlayerEvent.StartOfStream | PlayerEvent.StateChange);
ForceDragSourceSet = true;
IsEverReorderable = true;
@@ -88,10 +90,62 @@ namespace Banshee.Collection.Gui
ServiceManager.Get<InterfaceActionService> ().TrackActions["TrackContextMenuAction"].Activate ();
return true;
}
-
+
+ private string user_query;
+ protected override void OnModelReloaded ()
+ {
+ base.OnModelReloaded ();
+
+ var model = Model as IFilterable;
+ if (model != null && user_query != model.UserQuery) {
+ // Make sure selected tracks are visible as the user edits the query.
+ CenterOnSelection ();
+ user_query = model.UserQuery;
+ }
+ }
+
private void OnPlayerEvent (PlayerEventArgs args)
{
- QueueDraw ();
+ if (args.Event == PlayerEvent.StartOfStream) {
+ UpdateSelection ();
+ } else if (args.Event == PlayerEvent.StateChange) {
+ QueueDraw ();
+ }
+ }
+
+ private TrackInfo current_track;
+ private void UpdateSelection ()
+ {
+ TrackInfo old_track = current_track;
+ current_track = ServiceManager.PlayerEngine.CurrentTrack;
+
+ var track_model = Model as TrackListModel;
+ if (track_model == null) {
+ return;
+ }
+
+ if (Selection.Count > 1) {
+ return;
+ }
+
+ int old_index = Selection.FirstIndex;
+ TrackInfo selected_track = Selection.Count == 1 ? track_model[old_index] : null;
+ if (selected_track != null && !selected_track.TrackEqual (old_track)) {
+ return;
+ }
+
+ int current_index = track_model.IndexOf (current_track);
+ if (current_index == -1) {
+ return;
+ }
+
+ Selection.Clear (false);
+ Selection.QuietSelect (current_index);
+ Selection.FocusedIndex = current_index;
+
+ if (old_index == -1 || IsRowVisible (old_index)) {
+ CenterOn (current_index);
+ }
}
#region Drag and Drop
diff --git a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/TrackFilterListView.cs b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/TrackFilterListView.cs
index 67b347b..259188d 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/TrackFilterListView.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Collection.Gui/TrackFilterListView.cs
@@ -52,6 +52,12 @@ namespace Banshee.Collection.Gui
RowActivated += OnRowActivated;
}
+ protected override void OnModelReloaded ()
+ {
+ base.OnModelReloaded ();
+ CenterOnSelection ();
+ }
+
protected virtual void OnRowActivated (object o, EventArgs args)
{
ServiceManager.PlaybackController.NextSource = (ServiceManager.SourceManager.ActiveSource as Banshee.Sources.ITrackModelSource);
diff --git a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs
index d744725..1b44fee 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Interaction.cs
@@ -784,7 +784,31 @@ namespace Hyena.Data.Gui
{
ScrollTo (index - RowsInView/2 + 1);
}
-
+
+ public bool IsRowVisible (int index)
+ {
+ double y = GetYAtRow (index);
+ return vadjustment.Value <= y && y < vadjustment.Value + vadjustment.PageSize;
+ }
+
+ protected void CenterOnSelection ()
+ {
+ if (Selection != null && Selection.Count > 0 && !Selection.AllSelected) {
+ bool selection_in_view = false;
+ int first_row = GetRowAtY (0);
+ for (int i = 0; i < RowsInView; i++) {
+ if (Selection.Contains (first_row + i)) {
+ selection_in_view = true;
+ break;
+ }
+ }
+
+ if (!selection_in_view) {
+ CenterOn (Selection.Ranges[0].Start);
+ }
+ }
+ }
+
protected override void OnSetScrollAdjustments (Adjustment hadj, Adjustment vadj)
{
if (hadj == null || vadj == null) {
diff --git a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Model.cs b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Model.cs
index b28793d..e9fe295 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Model.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Model.cs
@@ -88,19 +88,6 @@ namespace Hyena.Data.Gui
} else if (Model.Count <= RowsInView) {
// If our view fits all rows at once, make sure we're scrolled to the top
ScrollTo (0.0);
- } else if (Selection != null && Selection.Count > 0 && !Selection.AllSelected) {
- bool selection_in_view = false;
- int first_row = GetRowAtY (0);
- for (int i = 0; i < RowsInView; i++) {
- if (Selection.Contains (first_row + i)) {
- selection_in_view = true;
- break;
- }
- }
-
- if (!selection_in_view) {
- CenterOn (Selection.Ranges[0].Start);
- }
} else if (vadjustment != null) {
ScrollTo (vadjustment.Value);
}
diff --git a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Windowing.cs b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Windowing.cs
index e647abf..c9b3c0b 100644
--- a/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Windowing.cs
+++ b/src/Libraries/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Windowing.cs
@@ -175,7 +175,7 @@ namespace Hyena.Data.Gui
InvalidateList ();
}
- private int RowsInView {
+ protected int RowsInView {
get { return (int) Math.Ceiling ((list_rendering_alloc.Height + RowHeight) / (double) RowHeight); }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]