]> git.sesse.net Git - vlc/commitdiff
Fix the search field in OSX playlist
authorBenjamin Pracht <bigben@videolan.org>
Wed, 1 Dec 2004 21:50:17 +0000 (21:50 +0000)
committerBenjamin Pracht <bigben@videolan.org>
Wed, 1 Dec 2004 21:50:17 +0000 (21:50 +0000)
extras/MacOSX/Resources/English.lproj/MainMenu.nib/classes.nib
extras/MacOSX/Resources/English.lproj/MainMenu.nib/info.nib
extras/MacOSX/Resources/English.lproj/MainMenu.nib/objects.nib
modules/gui/macosx/playlist.h
modules/gui/macosx/playlist.m

index 23646ce864443e6ae7ca23b99855d5f15339bfe8..ac65dfd49bb847421ee68dfa139b244e4701f508 100644 (file)
             SUPERCLASS = NSObject; 
         }, 
         {
-            ACTIONS = {handlePopUp = id; }; 
+            ACTIONS = {handlePopUp = id; searchItem = id; }; 
             CLASS = VLCPlaylist; 
             LANGUAGE = ObjC; 
             OUTLETS = {
                 "o_outline_view" = id; 
                 "o_random_ckb" = id; 
                 "o_search_field" = id; 
-                "o_search_keyword" = id; 
                 "o_status_field" = id; 
                 "o_tc_author" = id; 
                 "o_tc_duration" = id; 
index a715693b69aed6288e9668a0ead9ac3451f0927d..86bf1bda4185eceac1533d88d75554c95a670617 100644 (file)
@@ -3,13 +3,13 @@
 <plist version="1.0">
 <dict>
        <key>IBDocumentLocation</key>
-       <string>23 -174 505 517 0 0 1024 746 </string>
+       <string>45 176 505 517 0 0 1024 746 </string>
        <key>IBEditorPositions</key>
        <dict>
                <key>1617</key>
                <string>542 480 104 149 0 0 1024 746 </string>
                <key>2197</key>
-               <string>259 330 596 367 0 0 1024 746 </string>
+               <string>237 313 596 367 0 0 1024 746 </string>
                <key>29</key>
                <string>84 667 419 44 0 0 1024 746 </string>
                <key>915</key>
index a7b4cd623ac5d6556f15529818881456b4eb9850..9bb47834420da1e642ce7f152fda57f3526bc6cb 100644 (file)
Binary files a/extras/MacOSX/Resources/English.lproj/MainMenu.nib/objects.nib and b/extras/MacOSX/Resources/English.lproj/MainMenu.nib/objects.nib differ
index cfef7b42d75580936d08bf947e1e5ccf1c7a7dda..a6e1450fd4e16ec41492ea0995b269a13df0a698 100644 (file)
 
     NSImage *o_descendingSortingImage;
     NSImage *o_ascendingSortingImage;
+
+    NSMutableDictionary * o_outline_dict;
+
+    bool b_selected_item_met;
 }
 
 - (IBAction)handlePopUp:(id)sender;
+- (IBAction)searchItem:(id)sender;
 
 - (void)initStrings;
 
index 9ef3f4dec227f1241d55d2b3d0cd5e0c2fdfb219..13ef565ea813dc980bf28316c2a8a866621167e9 100644 (file)
@@ -173,6 +173,8 @@ belongs to an Apple hidden private API, and then can "disapear" at any time*/
         o_descendingSortingImage = nil;
     }
 
+    o_outline_dict = [[NSMutableDictionary alloc] init];
+
     [self initStrings];
     //[self playlistUpdated];
 }
@@ -364,6 +366,126 @@ belongs to an Apple hidden private API, and then can "disapear" at any time*/
      [self playlistUpdated];
 }
 
+- (NSMutableArray *)subSearchItem:(playlist_item_t *)p_item
+{
+    playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
+                                                       FIND_ANYWHERE );
+    playlist_item_t * p_selected_item;
+    int i_current, i_selected_row;
+
+    if (!p_playlist)
+        return NULL;
+
+    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 (i_current = 0; i_current < p_item->i_children ; i_current++)
+    {
+        char * psz_temp;
+        NSString * o_current_name, * o_current_author;
+
+        vlc_mutex_lock( &p_playlist->object_lock );
+        o_current_name = [NSString stringWithUTF8String:
+            p_item->pp_children[i_current]->input.psz_name];
+        psz_temp = playlist_ItemGetInfo(p_item ,_("Meta-information"),_("Author") );
+        o_current_author = [NSString stringWithUTF8String: psz_temp];
+        free( psz_temp);
+        vlc_mutex_unlock( &p_playlist->object_lock );
+
+        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)
+        {
+            vlc_object_release(p_playlist);
+            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))
+        {
+            vlc_object_release(p_playlist);
+            /*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)
+            {
+                vlc_object_release(p_playlist);
+                [o_result insertObject: [NSValue valueWithPointer:
+                                p_item->pp_children[i_current]] atIndex:0];
+                return o_result;
+            }
+        }
+    }
+    vlc_object_release(p_playlist);
+    return NULL;
+}
+
+- (IBAction)searchItem:(id)sender
+{
+    playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
+                                                       FIND_ANYWHERE );
+    playlist_view_t * p_view;
+    id o_result;
+
+    unsigned int i;
+    int i_row = -1;
+
+    b_selected_item_met = NO;
+
+    if( p_playlist == NULL )
+        return;
+
+    p_view = playlist_ViewFind( p_playlist, VIEW_SIMPLE );
+
+    if (p_view)
+    {
+        /*First, only search after the selected item:*
+         *(b_selected_item_met = NO)                 */
+        o_result = [self subSearchItem:p_view->p_root];
+        if (o_result == NULL)
+        {
+            /* If the first search failed, search again from the beginning */
+            o_result = [self subSearchItem:p_view->p_root];
+        }
+        if (o_result != NULL)
+        {
+            for (i = 0 ; i < [o_result 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: [o_result count] - 1 ]
+                            pointerValue]]]];
+        }
+        if (i_row > -1)
+        {
+            [o_outline_view selectRow:i_row byExtendingSelection: NO];
+            [o_outline_view scrollRowToVisible: i_row];
+        }
+    }
+    vlc_object_release(p_playlist);
+
+}
+
 @end
 
 @implementation VLCPlaylist (NSOutlineViewDataSource)
@@ -394,8 +516,6 @@ belongs to an Apple hidden private API, and then can "disapear" at any time*/
     vlc_object_release( p_playlist );
     if( i_return == -1 ) i_return = 0;
     msg_Dbg( p_playlist, "I have %d children", i_return );
-    [o_status_field setStringValue: [NSString stringWithFormat:
-                                _NS("%i items in playlist"), i_return]];
     return i_return;
 }
 
@@ -405,6 +525,8 @@ belongs to an Apple hidden private API, and then can "disapear" at any time*/
     playlist_item_t *p_return = NULL;
     playlist_t * p_playlist = vlc_object_find( VLCIntf, VLC_OBJECT_PLAYLIST,
                                                        FIND_ANYWHERE );
+    NSValue * o_value;
+
     if( p_playlist == NULL )
         return nil;
 
@@ -427,7 +549,15 @@ belongs to an Apple hidden private API, and then can "disapear" at any time*/
 
     vlc_object_release( p_playlist );
     msg_Dbg( p_playlist, "childitem with index %d", index );
-    return [[NSValue valueWithPointer: p_return] retain];
+
+    o_value = [NSValue valueWithPointer: p_return];
+
+    [o_outline_dict setObject:o_value forKey:[NSString stringWithFormat:@"%p",                                                                      p_return]];
+//    [o_status_field setStringValue: [NSString stringWithFormat:
+//                        _NS("%i items in playlist"), [o_outline_dict count]]];
+
+    return o_value;
+
 }
 
 /* is the item expandable */