From a473154373823182c5a745013ccff79bd6148119 Mon Sep 17 00:00:00 2001 From: meancoot Date: Thu, 26 Dec 2013 01:43:10 -0500 Subject: [PATCH] (iOS) RADirectoryList now takes a block for a callback, rather that a delegate. --- apple/iOS/browser.m | 14 ++++------ apple/iOS/menu.h | 2 +- apple/iOS/menu.m | 68 ++++++++++++++++++++++----------------------- apple/iOS/views.h | 15 +++++----- 4 files changed, 46 insertions(+), 53 deletions(-) diff --git a/apple/iOS/browser.m b/apple/iOS/browser.m index 2341bed703..a93820bace 100644 --- a/apple/iOS/browser.m +++ b/apple/iOS/browser.m @@ -134,23 +134,19 @@ static void file_action(enum file_action action, NSString* source, NSString* tar if (self.isDirectory) [(id)controller browseTo:self.path]; else - [[(id)controller directoryDelegate] directoryList:controller itemWasSelected:self]; + [(id)controller chooseAction]((id)controller, self); } @end @implementation RADirectoryList -{ - NSString* _path; - NSString* _extensions; -} -- (id)initWithPath:(NSString*)path extensions:(const char*)extensions delegate:(id)delegate +- (id)initWithPath:(NSString*)path extensions:(const char*)extensions action:(void (^)(RADirectoryList* list, RADirectoryItem* item))action { if ((self = [super initWithStyle:UITableViewStylePlain])) { _path = path ? path : NSHomeDirectory(); - _directoryDelegate = delegate; + _chooseAction = action; _extensions = extensions ? BOXSTRING(extensions) : 0; self = [super initWithStyle:UITableViewStylePlain]; @@ -241,10 +237,10 @@ static void file_action(enum file_action action, NSString* source, NSString* tar if (self.allowBlank) [self.sections[0] addObject:[RAMenuItemBasic itemWithDescription:@"[ Use Empty Path ]" - action:^{ [weakSelf.directoryDelegate directoryList:weakSelf itemWasSelected:nil]; }]]; + action:^{ weakSelf.chooseAction(weakSelf, nil); }]]; if (self.forDirectory) [self.sections[0] addObject:[RAMenuItemBasic itemWithDescription:@"[ Use This Folder ]" - action:^{ [weakSelf.directoryDelegate directoryList:weakSelf itemWasSelected:[RADirectoryItem directoryItemFromPath:path]]; }]]; + action:^{ weakSelf.chooseAction(weakSelf, [RADirectoryItem directoryItemFromPath:path]); }]]; dir_list_sort(contents, true); diff --git a/apple/iOS/menu.h b/apple/iOS/menu.h index 9a17c6543c..c8031160f8 100644 --- a/apple/iOS/menu.h +++ b/apple/iOS/menu.h @@ -108,7 +108,7 @@ /* Menu object that is displayed immediately */ /* after startup. */ /*********************************************/ -@interface RAMainMenu : RAMenuBase +@interface RAMainMenu : RAMenuBase @property (nonatomic) NSString* core; @end diff --git a/apple/iOS/menu.m b/apple/iOS/menu.m index d5f536dd2a..3a0ef5d82d 100644 --- a/apple/iOS/menu.m +++ b/apple/iOS/menu.m @@ -300,13 +300,28 @@ static void RunActionSheet(const char* title, const struct string_list* items, U /* A menu item that displays and allows */ /* browsing for a path setting. */ /*********************************************/ -@interface RAMenuItemPathSetting() @end +@interface RAMenuItemPathSetting() @end @implementation RAMenuItemPathSetting - (void)wasSelectedOnTableView:(UITableView*)tableView ofController:(UIViewController*)controller { + RAMenuItemPathSetting __weak* weakSelf = self; + NSString* path = [BOXSTRING(self.setting->value.string) stringByDeletingLastPathComponent]; - RADirectoryList* list = [[RADirectoryList alloc] initWithPath:path extensions:self.setting->values delegate:self]; + RADirectoryList* list = [[RADirectoryList alloc] initWithPath:path extensions:self.setting->values action: + ^(RADirectoryList* list, RADirectoryItem* item) + { + if (!list.allowBlank && !item) + return; + + if (list.forDirectory && !item.isDirectory) + return; + + setting_data_set_with_string_representation(weakSelf.setting, item ? item.path.UTF8String : ""); + [[list navigationController] popViewControllerAnimated:YES]; + + [weakSelf.parentTable reloadData]; + }]; list.allowBlank = (self.setting->flags & SD_FLAG_ALLOW_EMPTY); list.forDirectory = (self.setting->flags & SD_FLAG_PATH_DIR); @@ -314,22 +329,6 @@ static void RunActionSheet(const char* title, const struct string_list* items, U [controller.navigationController pushViewController:list animated:YES]; } -- (bool)directoryList:(RADirectoryList*)list itemWasSelected:(RADirectoryItem *)path -{ - if (!list.allowBlank && !path) - return false; - - if (list.forDirectory && !path.isDirectory) - return false; - - setting_data_set_with_string_representation(self.setting, path ? path.path.UTF8String : ""); - [[list navigationController] popViewControllerAnimated:YES]; - - [self.parentTable reloadData]; - - return true; -} - @end /*********************************************/ @@ -535,10 +534,22 @@ static void RunActionSheet(const char* title, const struct string_list* items, U - (void)loadGame { NSString* rootPath = RetroArch_iOS.get.documentsDirectory; - NSString* ragPath = [rootPath stringByAppendingPathComponent:@"RetroArchGames"]; - NSString* target = path_is_directory(ragPath.UTF8String) ? ragPath : rootPath; - - [self.navigationController pushViewController:[[RADirectoryList alloc] initWithPath:target extensions:NULL delegate:self] animated:YES]; + + RAMainMenu __weak* weakSelf = self; + + RADirectoryList* list = [[RADirectoryList alloc] initWithPath:RetroArch_iOS.get.documentsDirectory extensions:NULL action: + ^(RADirectoryList *list, RADirectoryItem *item) + { + if (item && !item.isDirectory) + { + if (weakSelf.core) + apple_run_core(weakSelf.core, item.path.UTF8String); + else + [weakSelf chooseCoreWithPath:item.path]; + } + }]; + + [self.navigationController pushViewController:list animated:YES]; } - (void)loadHistory @@ -547,19 +558,6 @@ static void RunActionSheet(const char* title, const struct string_list* items, U [self.navigationController pushViewController:[[RAHistoryMenu alloc] initWithHistoryPath:history_path] animated:YES]; } -- (bool)directoryList:(id)list itemWasSelected:(RADirectoryItem*)path -{ - if (path && !path.isDirectory) - { - if (self.core) - apple_run_core(self.core, path.path.UTF8String); - else - [self chooseCoreWithPath:path.path]; - } - - return true; -} - @end /*********************************************/ diff --git a/apple/iOS/views.h b/apple/iOS/views.h index bbfbdfa65d..7c28f1e9a0 100644 --- a/apple/iOS/views.h +++ b/apple/iOS/views.h @@ -20,12 +20,6 @@ #include "core_info.h" -// browser.m -@class RADirectoryItem; -@protocol RADirectoryListDelegate -- (bool)directoryList:(id)list itemWasSelected:(RADirectoryItem*)path; -@end - #include "menu.h" // browser.m @@ -35,11 +29,16 @@ @end @interface RADirectoryList : RAMenuBase -@property (nonatomic, weak) id directoryDelegate; @property (nonatomic, weak) RADirectoryItem* selectedItem; + +@property (nonatomic, copy) void (^chooseAction)(RADirectoryList* list, RADirectoryItem* item); +@property (nonatomic, copy) NSString* path; +@property (nonatomic, copy) NSString* extensions; + @property (nonatomic) bool allowBlank; @property (nonatomic) bool forDirectory; -- (id)initWithPath:(NSString*)path extensions:(const char*)extensions delegate:(id)delegate; + +- (id)initWithPath:(NSString*)path extensions:(const char*)extensions action:(void (^)(RADirectoryList* list, RADirectoryItem* item))action; - (void)browseTo:(NSString*)path; @end