mirror of
https://github.com/libretro/RetroArch
synced 2025-03-28 19:20:35 +00:00
(iOS) RADirectoryList now takes a block for a callback, rather that a delegate.
This commit is contained in:
parent
7fe9ec647c
commit
a473154373
@ -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<RADirectoryListDelegate>)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);
|
||||
|
||||
|
@ -108,7 +108,7 @@
|
||||
/* Menu object that is displayed immediately */
|
||||
/* after startup. */
|
||||
/*********************************************/
|
||||
@interface RAMainMenu : RAMenuBase<RADirectoryListDelegate>
|
||||
@interface RAMainMenu : RAMenuBase
|
||||
@property (nonatomic) NSString* core;
|
||||
@end
|
||||
|
||||
|
@ -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() <RADirectoryListDelegate> @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
|
||||
|
||||
/*********************************************/
|
||||
|
@ -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<UIActionSheetDelegate>
|
||||
@property (nonatomic, weak) id<RADirectoryListDelegate> 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<RADirectoryListDelegate>)delegate;
|
||||
|
||||
- (id)initWithPath:(NSString*)path extensions:(const char*)extensions action:(void (^)(RADirectoryList* list, RADirectoryItem* item))action;
|
||||
- (void)browseTo:(NSString*)path;
|
||||
@end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user