[vlc-commits] macosx: select currently played item

David Fuhrmann git at videolan.org
Sun Mar 8 17:49:19 CET 2015


vlc | branch: master | David Fuhrmann <dfuhrmann at videolan.org> | Sat Mar  7 11:05:46 2015 +0100| [697314665b2c6507bed737159c0f07c2fff6890e] | committer: David Fuhrmann

macosx: select currently played item

And expand outline view tree if necessary.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=697314665b2c6507bed737159c0f07c2fff6890e
---

 modules/gui/macosx/PLModel.h  |    2 ++
 modules/gui/macosx/PLModel.m  |   12 ++++++++
 modules/gui/macosx/intf.m     |    3 +-
 modules/gui/macosx/playlist.h |    3 +-
 modules/gui/macosx/playlist.m |   62 +++++++++++++++++++----------------------
 5 files changed, 46 insertions(+), 36 deletions(-)

diff --git a/modules/gui/macosx/PLModel.h b/modules/gui/macosx/PLModel.h
index 01a1bd3..d6584ae 100644
--- a/modules/gui/macosx/PLModel.h
+++ b/modules/gui/macosx/PLModel.h
@@ -80,6 +80,8 @@ typedef enum {
 - (void)addItem:(int)i_item withParentNode:(int)i_node;
 - (void)removeItem:(int)i_item;
 
+- (PLItem *)currentlyPlayingItem;
+
 - (void)sortForColumn:(NSString *)o_column withMode:(int)i_mode;
 
 - (void)searchUpdate:(NSString *)o_search;
diff --git a/modules/gui/macosx/PLModel.m b/modules/gui/macosx/PLModel.m
index 27bce4b..3aec7d8 100644
--- a/modules/gui/macosx/PLModel.m
+++ b/modules/gui/macosx/PLModel.m
@@ -199,6 +199,18 @@
         [_outlineView reloadItem:o_parent reloadChildren:YES];
 }
 
+- (PLItem *)currentlyPlayingItem
+{
+    PLItem *item = nil;
+
+    PL_LOCK;
+    playlist_item_t *p_current = playlist_CurrentPlayingItem(p_playlist);
+    if (p_current)
+        item = [self findItemByPlaylistId:p_current->i_id];
+    PL_UNLOCK;
+    return item;
+}
+
 - (void)sortForColumn:(NSString *)o_column withMode:(int)i_mode
 {
     int i_column = 0;
diff --git a/modules/gui/macosx/intf.m b/modules/gui/macosx/intf.m
index 2df03a8..70a51e5 100644
--- a/modules/gui/macosx/intf.m
+++ b/modules/gui/macosx/intf.m
@@ -1356,6 +1356,8 @@ static bool f_appExit = false;
 
             p_input_changed = vlc_object_hold(p_current_input);
 
+            [[self playlist] currentlyPlayingItemChanged];
+
             [[self playlist] continuePlaybackWhereYouLeftOff:p_current_input];
 
             [[NSNotificationCenter defaultCenter] postNotificationName:VLCInputChangedNotification
@@ -1363,7 +1365,6 @@ static bool f_appExit = false;
         }
     }
 
-    [o_playlist updateRowSelection];
     [o_mainwindow updateWindow];
     [self updateDelays];
     [self updateMainMenu];
diff --git a/modules/gui/macosx/playlist.h b/modules/gui/macosx/playlist.h
index 29d1a26..1eb3d44 100644
--- a/modules/gui/macosx/playlist.h
+++ b/modules/gui/macosx/playlist.h
@@ -91,7 +91,8 @@
 - (void)playlistUpdated;
 - (void)outlineViewSelectionDidChange:(NSNotification *)notification;
 - (void)sortNode:(int)i_mode;
-- (void)updateRowSelection;
+
+- (void)currentlyPlayingItemChanged;
 
 - (BOOL)isSelectionEmpty;
 
diff --git a/modules/gui/macosx/playlist.m b/modules/gui/macosx/playlist.m
index 63069e0..2de60b7 100644
--- a/modules/gui/macosx/playlist.m
+++ b/modules/gui/macosx/playlist.m
@@ -354,42 +354,36 @@
     return [o_outline_view selectedRow] == -1;
 }
 
-- (void)updateRowSelection
+- (void)currentlyPlayingItemChanged
 {
-    // FIXME: unsafe
-    playlist_t *p_playlist = pl_Get(VLCIntf);
-    playlist_item_t *p_item, *p_temp_item;
-    NSMutableArray *o_array = [NSMutableArray array];
+    PLItem *item = [[self model] currentlyPlayingItem];
+    if (!item)
+        return;
 
-    // TODO Rework
-//    PL_LOCK;
-//    p_item = playlist_CurrentPlayingItem(p_playlist);
-//    if (p_item == NULL) {
-//        PL_UNLOCK;
-//        return;
-//    }
-//
-//    p_temp_item = p_item;
-//    while(p_temp_item->p_parent) {
-//        [o_array insertObject: [NSValue valueWithPointer: p_temp_item] atIndex: 0];
-//        p_temp_item = p_temp_item->p_parent;
-//    }
-//    PL_UNLOCK;
-//
-//    NSUInteger count = [o_array count];
-//    for (NSUInteger j = 0; j < count - 1; j++) {
-//        id o_item;
-//        if ((o_item = [o_outline_dict objectForKey:
-//                            [NSString stringWithFormat: @"%p",
-//                            [[o_array objectAtIndex:j] pointerValue]]]) != nil) {
-//            [o_outline_view expandItem: o_item];
-//        }
-//    }
-//
-//    id o_item = [o_outline_dict objectForKey:[NSString stringWithFormat: @"%p", p_item]];
-//    NSInteger i_index = [o_outline_view rowForItem:o_item];
-//    [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_index] byExtendingSelection:NO];
-//    [o_outline_view setNeedsDisplay:YES];
+    [[[VLCMain sharedInstance] info] updatePanelWithItem: [item input]];
+
+    // select item
+    NSInteger itemIndex = [o_outline_view rowForItem:item];
+    if (itemIndex < 0) {
+        // expand if needed
+        while (item != nil) {
+            PLItem *parent = [item parent];
+
+            if (![o_outline_view isExpandable: parent])
+                break;
+            if (![o_outline_view isItemExpanded: parent])
+                [o_outline_view expandItem: parent];
+            item = parent;
+        }
+
+        // search for row again
+        itemIndex = [o_outline_view rowForItem:item];
+        if (itemIndex < 0) {
+            return;
+        }
+    }
+
+    [o_outline_view selectRowIndexes: [NSIndexSet indexSetWithIndex: itemIndex] byExtendingSelection: NO];
 }
 
 - (IBAction)savePlaylist:(id)sender



More information about the vlc-commits mailing list