(iOS) Split some code from menu.m info functions for re-use.

This commit is contained in:
meancoot 2013-12-09 19:50:46 -05:00
parent 80cf0a798c
commit ea897f4e46

View File

@ -18,6 +18,28 @@
#include "apple/common/apple_input.h"
#include "menu.h"
/*********************************************/
/* RunActionSheet */
/* Creates and displays a UIActionSheet with */
/* buttons pulled from a RetroArch */
/* string_list structure. */
/*********************************************/
static void RunActionSheet(const char* title, const struct string_list* items, UIView* parent, id<UIActionSheetDelegate> delegate)
{
UIActionSheet* actionSheet = [UIActionSheet new];
actionSheet.title = @(title);
actionSheet.delegate = delegate;
for (int i = 0; i < items->size; i ++)
{
[actionSheet addButtonWithTitle:@(items->elems[i].data)];
}
actionSheet.cancelButtonIndex = [actionSheet addButtonWithTitle:@"Cancel"];
[actionSheet showInView:parent];
}
/*********************************************/
/* RAMenuBase */
/* A menu class that displays RAMenuItemBase */
@ -295,29 +317,15 @@
/* a setting to be set from a list of */
/* allowed choices. */
/*********************************************/
@interface RAMenuItemEnumSetting() <UIActionSheetDelegate>
@property (nonatomic) UIActionSheet* actionSheet;
@end
@interface RAMenuItemEnumSetting() <UIActionSheetDelegate> @end
@implementation RAMenuItemEnumSetting
- (void)wasSelectedOnTableView:(UITableView*)tableView ofController:(UIViewController*)controller
{
struct string_list* options = string_split(self.setting->values, "|");
self.actionSheet = [UIActionSheet new];
self.actionSheet.title = @(self.setting->short_description);
self.actionSheet.delegate = self;
for (int i = 0; i < options->size; i ++)
{
[self.actionSheet addButtonWithTitle:@(options->elems[i].data)];
}
self.actionSheet.cancelButtonIndex = [self.actionSheet addButtonWithTitle:@"Cancel"];
[self.actionSheet showInView:self.parentTable];
string_list_free(options);
struct string_list* items = string_split(self.setting->values, "|");
RunActionSheet(self.setting->short_description, items, self.parentTable, self);
string_list_free(items);
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
@ -327,8 +335,6 @@
setting_data_set_with_string_representation(self.setting, [actionSheet buttonTitleAtIndex:buttonIndex].UTF8String);
[self.parentTable reloadData];
}
self.actionSheet = nil;
}
@end
@ -762,20 +768,7 @@ static const void* const associated_core_key = &associated_core_key;
- (void)editValue:(uint32_t)index
{
self.currentIndex = index;
UIActionSheet* sheet = [UIActionSheet new];
sheet.title = @(core_option_get_desc(g_extern.system.core_options, index));
sheet.delegate = self;
struct string_list* values = core_option_get_vals(g_extern.system.core_options, index);
for (int i = 0; i != values->size; i ++)
[sheet addButtonWithTitle:@(values->elems[i].data)];
[sheet addButtonWithTitle:@"Cancel"];
sheet.cancelButtonIndex = sheet.numberOfButtons - 1;
[sheet showInView:self.tableView];
RunActionSheet(core_option_get_desc(g_extern.system.core_options, index), core_option_get_vals(g_extern.system.core_options, index), self.tableView, self);
}
- (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex