From: Benjamin Pracht Date: Wed, 1 Dec 2004 21:50:17 +0000 (+0000) Subject: Fix the search field in OSX playlist X-Git-Tag: 0.8.2~1571 X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=ec5590ea0a127b9ff783097cc4d40216a15376d7;p=vlc Fix the search field in OSX playlist --- diff --git a/extras/MacOSX/Resources/English.lproj/MainMenu.nib/classes.nib b/extras/MacOSX/Resources/English.lproj/MainMenu.nib/classes.nib index 23646ce864..ac65dfd49b 100644 --- a/extras/MacOSX/Resources/English.lproj/MainMenu.nib/classes.nib +++ b/extras/MacOSX/Resources/English.lproj/MainMenu.nib/classes.nib @@ -402,7 +402,7 @@ SUPERCLASS = NSObject; }, { - ACTIONS = {handlePopUp = id; }; + ACTIONS = {handlePopUp = id; searchItem = id; }; CLASS = VLCPlaylist; LANGUAGE = ObjC; OUTLETS = { @@ -412,7 +412,6 @@ "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; diff --git a/extras/MacOSX/Resources/English.lproj/MainMenu.nib/info.nib b/extras/MacOSX/Resources/English.lproj/MainMenu.nib/info.nib index a715693b69..86bf1bda41 100644 --- a/extras/MacOSX/Resources/English.lproj/MainMenu.nib/info.nib +++ b/extras/MacOSX/Resources/English.lproj/MainMenu.nib/info.nib @@ -3,13 +3,13 @@ IBDocumentLocation - 23 -174 505 517 0 0 1024 746 + 45 176 505 517 0 0 1024 746 IBEditorPositions 1617 542 480 104 149 0 0 1024 746 2197 - 259 330 596 367 0 0 1024 746 + 237 313 596 367 0 0 1024 746 29 84 667 419 44 0 0 1024 746 915 diff --git a/extras/MacOSX/Resources/English.lproj/MainMenu.nib/objects.nib b/extras/MacOSX/Resources/English.lproj/MainMenu.nib/objects.nib index a7b4cd623a..9bb4783442 100644 Binary files a/extras/MacOSX/Resources/English.lproj/MainMenu.nib/objects.nib and b/extras/MacOSX/Resources/English.lproj/MainMenu.nib/objects.nib differ diff --git a/modules/gui/macosx/playlist.h b/modules/gui/macosx/playlist.h index cfef7b42d7..a6e1450fd4 100644 --- a/modules/gui/macosx/playlist.h +++ b/modules/gui/macosx/playlist.h @@ -49,9 +49,14 @@ 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; diff --git a/modules/gui/macosx/playlist.m b/modules/gui/macosx/playlist.m index 9ef3f4dec2..13ef565ea8 100644 --- a/modules/gui/macosx/playlist.m +++ b/modules/gui/macosx/playlist.m @@ -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 */