]> git.sesse.net Git - vlc/commitdiff
macosx: Use core-provided playlist search functionality
authorDavid Fuhrmann <dfuhrmann@videolan.org>
Sun, 30 Nov 2014 10:21:54 +0000 (11:21 +0100)
committerDavid Fuhrmann <dfuhrmann@videolan.org>
Tue, 30 Dec 2014 15:10:48 +0000 (16:10 +0100)
This removes the old own-made search functionality and replaces
it by a version the user would expect (i.e. actually hiding non-
found entries).

close #6049

modules/gui/macosx/PLModel.h
modules/gui/macosx/PLModel.m
modules/gui/macosx/playlist.h
modules/gui/macosx/playlist.m

index 3a1b36c094bb154b2be565b472ff2b95cb923146..8239f59248f2c08bdc44225e940be787c40e313d 100644 (file)
@@ -56,8 +56,7 @@ typedef enum {
 
 - (void)sortForColumn:(NSString *)o_column withMode:(int)i_mode;
 
-
-
+- (void)searchUpdate:(NSString *)o_search;
 
 
 @end
index a9222d218d1f1e3f30e6d867fab82ed3cb89db35..0aa3177a211ab08df8d69eccc6a8e8467886bc62 100644 (file)
     [self currentRootType] == ROOT_TYPE_PLAYLIST;
 }
 
-
-
 - (void)rebuildPLItem:(PLItem *)o_item
 {
     [o_item clear];
     playlist_item_t *p_item = playlist_ItemGetById(p_playlist, [o_item plItemId]);
     if (p_item) {
+        int currPos = 0;
         for(int i = 0; i < p_item->i_children; ++i) {
-            PLItem *o_child = [[[PLItem alloc] initWithPlaylistItem:p_item->pp_children[i] parent:o_item] autorelease];
-            [o_item addChild:o_child atPos:i];
+            playlist_item_t *p_child = p_item->pp_children[i];
+
+            if (p_child->i_flags & PLAYLIST_DBL_FLAG)
+                continue;
+
+            PLItem *o_child = [[[PLItem alloc] initWithPlaylistItem:p_child parent:o_item] autorelease];
+            [o_item addChild:o_child atPos:currPos++];
 
-            if (p_item->pp_children[i]->i_children >= 0) {
+            if (p_child->i_children >= 0) {
                 [self rebuildPLItem:o_child];
             }
 
     PL_UNLOCK;
 }
 
+- (void)searchUpdate:(NSString *)o_search
+{
+    PL_LOCK;
+    playlist_item_t *p_root = playlist_ItemGetById(p_playlist, [_rootItem plItemId]);
+    if (!p_root) {
+        PL_UNLOCK;
+        return;
+    }
+    playlist_LiveSearchUpdate(p_playlist, p_root, [o_search UTF8String],
+                              true);
+    [self rebuildPLItem:_rootItem];
+    [_outlineView reloadData];
+    PL_UNLOCK;
+}
+
 @end
 
 #pragma mark -
index c6f833258c256df0fbe84e6a54f79e429cf0dbf4..f79f7b27534bcbd20a256178effb25c3da2db4de 100644 (file)
 - (playlist_item_t *)currentPlaylistRoot;
 - (void)reloadStyles;
 
-- (void)searchfieldChanged:(NSNotification *)o_notification;
 - (NSMenu *)menuForEvent:(NSEvent *)o_event;
 
 - (IBAction)searchItem:(id)sender;
index e9273969cece12488bac2cf983e7dc5bef2be217..ea9adf534c96550093f1c568730e6752516c934f 100644 (file)
     [self saveTableColumns];
 }
 
-- (void)searchfieldChanged:(NSNotification *)o_notification
-{
-    assert(0);
-    [o_search_field setStringValue:[[o_notification object] stringValue]];
-}
-
 - (void)initStrings
 {
     [o_mi_play setTitle: _NS("Play")];
 //    [self playlistUpdated];
 }
 
-- (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
-{
-    playlist_t *p_playlist = pl_Get(VLCIntf);
-    playlist_item_t *p_selected_item;
-    int i_selected_row;
-
-    i_selected_row = [o_outline_view selectedRow];
-    if (i_selected_row < 0)
-        i_selected_row = 0;
-
-    p_selected_item = (playlist_item_t *)[[o_outline_view itemAtRow: i_selected_row] pointerValue];
-
-    for (NSUInteger i_current = 0; i_current < p_item->i_children ; i_current++) {
-        char *psz_temp;
-        NSString *o_current_name, *o_current_author;
-
-        PL_LOCK;
-        o_current_name = [NSString stringWithUTF8String:p_item->pp_children[i_current]->p_input->psz_name];
-        psz_temp = input_item_GetInfo(p_item->p_input, _("Meta-information"),_("Artist"));
-        o_current_author = [NSString stringWithUTF8String:psz_temp];
-        free(psz_temp);
-        PL_UNLOCK;
-
-        if (p_selected_item == p_item->pp_children[i_current] && b_selected_item_met == NO)
-            b_selected_item_met = YES;
-        else if (p_selected_item == p_item->pp_children[i_current] && b_selected_item_met == YES)
-            return NULL;
-        else if (b_selected_item_met == YES &&
-                    ([o_current_name rangeOfString:[o_search_field
-                        stringValue] options:NSCaseInsensitiveSearch].length ||
-                      [o_current_author rangeOfString:[o_search_field
-                        stringValue] options:NSCaseInsensitiveSearch].length))
-            /*Adds the parent items in the result array as well, so that we can
-            expand the tree*/
-            return [NSMutableArray arrayWithObject: [NSValue valueWithPointer: p_item->pp_children[i_current]]];
-
-        if (p_item->pp_children[i_current]->i_children > 0) {
-            id o_result = [self subSearchItem:
-                                            p_item->pp_children[i_current]];
-            if (o_result != NULL) {
-                [o_result insertObject: [NSValue valueWithPointer:
-                                p_item->pp_children[i_current]] atIndex:0];
-                return o_result;
-            }
-        }
-    }
-    return NULL;
-}
-
 - (IBAction)searchItem:(id)sender
 {
-    playlist_t * p_playlist = pl_Get(VLCIntf);
-    id o_result;
-
-    int i_row = -1;
-
-    b_selected_item_met = NO;
-
-    /* First, only search after the selected item:
-     * (b_selected_item_met = NO) */
-    o_result = [self subSearchItem:[self currentPlaylistRoot]];
-    if (o_result == NULL)
-        /* If the first search failed, search again from the beginning */
-        o_result = [self subSearchItem:[self currentPlaylistRoot]];
-
-    if (o_result != NULL) {
-        int i_start;
-        if ([[o_result objectAtIndex:0] pointerValue] == p_playlist->p_local_category)
-            i_start = 1;
-        else
-            i_start = 0;
-        NSUInteger count = [o_result count];
-
-        for (NSUInteger i = i_start ; i < count - 1 ; i++) {
-            [o_outline_view expandItem: [o_outline_dict objectForKey:
-                        [NSString stringWithFormat: @"%p",
-                        [[o_result objectAtIndex:i] pointerValue]]]];
-        }
-        i_row = [o_outline_view rowForItem: [o_outline_dict objectForKey:
-                        [NSString stringWithFormat: @"%p",
-                        [[o_result objectAtIndex:count - 1 ]
-                        pointerValue]]]];
-    }
-    if (i_row > -1) {
-        [o_outline_view selectRowIndexes:[NSIndexSet indexSetWithIndex:i_row] byExtendingSelection:NO];
-        [o_outline_view scrollRowToVisible: i_row];
-    }
+    [[self model] searchUpdate:[o_search_field stringValue]];
 }
 
 - (IBAction)recursiveExpandNode:(id)sender