mirror of
https://github.com/libretro/RetroArch
synced 2025-02-21 18:40:09 +00:00
(iOS) Cleanups
This commit is contained in:
parent
94c65d23e3
commit
38fe0d0119
@ -146,7 +146,7 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
|
||||
static NSString* const cell_id = @"path_item";
|
||||
static NSString* const icon_types[2] = { @"ic_file", @"ic_dir" };
|
||||
uint32_t type_id = self.isDirectory ? 1 : 0;
|
||||
UITableViewCell* result = [tableView dequeueReusableCellWithIdentifier:cell_id];
|
||||
UITableViewCell *result = [tableView dequeueReusableCellWithIdentifier:cell_id];
|
||||
|
||||
if (!result)
|
||||
result = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cell_id];
|
||||
@ -169,10 +169,12 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
|
||||
|
||||
@implementation RADirectoryList
|
||||
|
||||
- (id)initWithPath:(NSString*)path extensions:(const char*)extensions action:(void (^)(RADirectoryList* list, RADirectoryItem* item))action
|
||||
- (id)initWithPath:(NSString*)path extensions:(const char*)extensions
|
||||
action:(void (^)(RADirectoryList* list, RADirectoryItem* item))action
|
||||
{
|
||||
if ((self = [super initWithStyle:UITableViewStylePlain]))
|
||||
{
|
||||
NSMutableArray *toolbarButtons;
|
||||
self.path = path ? path : NSHomeDirectory();
|
||||
self.chooseAction = action;
|
||||
self.extensions = extensions ? BOXSTRING(extensions) : 0;
|
||||
@ -180,12 +182,11 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
|
||||
|
||||
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:BOXSTRING("Up") style:UIBarButtonItemStyleBordered target:self
|
||||
action:@selector(gotoParent)];
|
||||
|
||||
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self
|
||||
action:@selector(cancelBrowser)];
|
||||
|
||||
// NOTE: The "App" and "Root" buttons aren't really needed for non-jailbreak devices.
|
||||
NSMutableArray* toolbarButtons = [NSMutableArray arrayWithObjects:
|
||||
/* NOTE: The "App" and "Root" buttons aren't really needed for non-jailbreak devices. */
|
||||
toolbarButtons = [NSMutableArray arrayWithObjects:
|
||||
[[UIBarButtonItem alloc] initWithTitle:BOXSTRING("Home") style:UIBarButtonItemStyleBordered target:self
|
||||
action:@selector(gotoHomeDir)],
|
||||
[[UIBarButtonItem alloc] initWithTitle:BOXSTRING("App") style:UIBarButtonItemStyleBordered target:self
|
||||
@ -242,6 +243,8 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
|
||||
|
||||
- (void)browseTo:(NSString*)path
|
||||
{
|
||||
NSString *i;
|
||||
struct string_list *contents = NULL;
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
self.path = path;
|
||||
@ -250,11 +253,11 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
|
||||
/* Need one array per section. */
|
||||
self.sections = [NSMutableArray array];
|
||||
|
||||
for (NSString* i in [self sectionIndexTitlesForTableView:self.tableView])
|
||||
for (i in [self sectionIndexTitlesForTableView:self.tableView])
|
||||
[self.sections addObject:[NSMutableArray arrayWithObject:i]];
|
||||
|
||||
/* List contents */
|
||||
struct string_list *contents = dir_list_new(self.path.UTF8String,
|
||||
contents = dir_list_new(self.path.UTF8String,
|
||||
settings->menu.navigation.browser.filter.supported_extensions_enable ? self.extensions.UTF8String : NULL, true);
|
||||
|
||||
if (contents)
|
||||
@ -268,21 +271,17 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
|
||||
if (self.forDirectory)
|
||||
[self.sections[0] addObject:[RAMenuItemBasic itemWithDescription:BOXSTRING("[ Use This Folder ]")
|
||||
action:^{ weakSelf.chooseAction(weakSelf, [RADirectoryItem directoryItemFromPath:path]); }]];
|
||||
|
||||
dir_list_sort(contents, true);
|
||||
|
||||
for (i = 0; i < contents->size; i ++)
|
||||
{
|
||||
const char* basename = path_basename(contents->elems[i].data);
|
||||
|
||||
uint32_t section = isalpha(basename[0]) ? (toupper(basename[0]) - 'A') + 2 : 1;
|
||||
const char *basename = path_basename(contents->elems[i].data);
|
||||
char is_directory = (contents->elems[i].attr.i == RARCH_DIRECTORY);
|
||||
section = is_directory ? 0 : section;
|
||||
uint32_t section = is_directory ? 0 : isalpha(basename[0]) ? (toupper(basename[0]) - 'A') + 2 : 1;
|
||||
|
||||
if (! ( self.forDirectory && ! is_directory )) {
|
||||
if (! ( self.forDirectory && ! is_directory ))
|
||||
[self.sections[section] addObject:[RADirectoryItem directoryItemFromElement:&contents->elems[i]]];
|
||||
}
|
||||
}
|
||||
|
||||
dir_list_free(contents);
|
||||
}
|
||||
@ -317,8 +316,8 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
|
||||
return names;
|
||||
}
|
||||
|
||||
// File management
|
||||
// Called as a selector from a toolbar button
|
||||
/* File management
|
||||
* Called as a selector from a toolbar button. */
|
||||
- (void)createNewFolder
|
||||
{
|
||||
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Enter new folder name") message:BOXSTRING("") delegate:self
|
||||
@ -328,7 +327,7 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
|
||||
[alertView show];
|
||||
}
|
||||
|
||||
// Called by the long press gesture recognizer
|
||||
/* Called by the long press gesture recognizer. */
|
||||
- (void)fileAction:(UILongPressGestureRecognizer*)gesture
|
||||
{
|
||||
if (gesture.state == UIGestureRecognizerStateBegan)
|
||||
@ -374,7 +373,9 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
|
||||
[self.navigationController pushViewController:[[RAFoldersList alloc] initWithFilePath:target] animated:YES];
|
||||
else if (!strcmp(action.UTF8String, "Rename"))
|
||||
{
|
||||
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Enter new name") message:@"" delegate:self cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil];
|
||||
UIAlertView* alertView = [[UIAlertView alloc]
|
||||
initWithTitle:BOXSTRING("Enter new name") message:@""
|
||||
delegate:self cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil];
|
||||
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
|
||||
alertView.tag = FA_MOVE;
|
||||
[alertView textFieldAtIndex:0].text = target.lastPathComponent;
|
||||
@ -383,10 +384,9 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
|
||||
#ifdef __IPHONE_7_0
|
||||
else if (!strcmp(action.UTF8String, "AirDrop") && (get_ios_version_major() >= 7))
|
||||
{
|
||||
// TODO: Zip if not already zipped
|
||||
|
||||
NSURL* url = [NSURL fileURLWithPath:self.selectedItem.path isDirectory:self.selectedItem.isDirectory];
|
||||
NSArray* items = [NSArray arrayWithObject:url];
|
||||
/* TODO: ZIP if not already zipped. */
|
||||
NSURL *url = [NSURL fileURLWithPath:self.selectedItem.path isDirectory:self.selectedItem.isDirectory];
|
||||
NSArray *items = [NSArray arrayWithObject:url];
|
||||
UIActivityViewController* avc = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
|
||||
|
||||
[self presentViewController:avc animated:YES completion:nil];
|
||||
@ -394,7 +394,7 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
|
||||
#endif
|
||||
else if (!strcmp(action.UTF8String, "Delete"))
|
||||
{
|
||||
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Really delete?") message:@"" delegate:self cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil];
|
||||
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Really delete?") message:@"" delegate:self cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil];
|
||||
alertView.tag = FA_DELETE;
|
||||
[alertView show];
|
||||
}
|
||||
@ -402,7 +402,8 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
|
||||
apple_display_alert("Action not supported.", "Action Failed");
|
||||
}
|
||||
|
||||
// Called by various alert views created in this class, the alertView.tag value is the action to take.
|
||||
/* Called by various alert views created in this class,
|
||||
* the alertView.tag value is the action to take. */
|
||||
- (void)alertView:(UIAlertView*)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
|
||||
{
|
||||
if (buttonIndex != alertView.firstOtherButtonIndex)
|
||||
@ -433,20 +434,23 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
|
||||
{
|
||||
if ((self = [super initWithStyle:UITableViewStyleGrouped]))
|
||||
{
|
||||
NSString *sourceItem;
|
||||
RAMenuItemBasic *parentItem;
|
||||
NSMutableArray *items;
|
||||
struct string_list* contents;
|
||||
RAFoldersList* __weak weakSelf = self;
|
||||
self.path = path;
|
||||
|
||||
// Parent item
|
||||
NSString* sourceItem = self.path.stringByDeletingLastPathComponent;
|
||||
/* Parent item */
|
||||
sourceItem = self.path.stringByDeletingLastPathComponent;
|
||||
|
||||
RAMenuItemBasic* parentItem = [RAMenuItemBasic itemWithDescription:BOXSTRING("<Parent>") association:sourceItem.stringByDeletingLastPathComponent
|
||||
parentItem = [RAMenuItemBasic itemWithDescription:BOXSTRING("<Parent>") association:sourceItem.stringByDeletingLastPathComponent
|
||||
action:^(id userdata){ [weakSelf moveInto:userdata]; } detail:NULL];
|
||||
[self.sections addObject:@[BOXSTRING(""), parentItem]];
|
||||
|
||||
|
||||
// List contents
|
||||
struct string_list* contents = dir_list_new([self.path stringByDeletingLastPathComponent].UTF8String, NULL, true);
|
||||
NSMutableArray* items = [NSMutableArray arrayWithObject:BOXSTRING("")];
|
||||
/* List contents */
|
||||
contents = dir_list_new([self.path stringByDeletingLastPathComponent].UTF8String, NULL, true);
|
||||
items = [NSMutableArray arrayWithObject:BOXSTRING("")];
|
||||
|
||||
if (contents)
|
||||
{
|
||||
@ -458,18 +462,15 @@ static void file_action(enum file_action action, NSString* source, NSString* tar
|
||||
if (contents->elems[i].attr.i == RARCH_DIRECTORY)
|
||||
{
|
||||
const char* basename = path_basename(contents->elems[i].data);
|
||||
|
||||
RAMenuItemBasic* item = [RAMenuItemBasic itemWithDescription:BOXSTRING(basename) association:BOXSTRING(contents->elems[i].data)
|
||||
action:^(id userdata){ [weakSelf moveInto:userdata]; } detail:NULL];
|
||||
[items addObject:item];
|
||||
}
|
||||
}
|
||||
|
||||
dir_list_free(contents);
|
||||
}
|
||||
|
||||
[self setTitle:[BOXSTRING("Move ") stringByAppendingString: self.path.lastPathComponent]];
|
||||
|
||||
[self.sections addObject:items];
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ extern float apple_gfx_ctx_get_native_scale(void);
|
||||
/* Input helpers: This is kept here because it needs ObjC */
|
||||
static void handle_touch_event(NSArray* touches)
|
||||
{
|
||||
NSUInteger i;
|
||||
unsigned i;
|
||||
driver_t *driver = driver_get_ptr();
|
||||
apple_input_data_t *apple = (apple_input_data_t*)driver->input_data;
|
||||
float scale = apple_gfx_ctx_get_native_scale();
|
||||
@ -126,7 +126,7 @@ static void handle_touch_event(NSArray* touches)
|
||||
|
||||
for (i = 0; i < touches.count && (apple->touch_count < MAX_TOUCHES); i++)
|
||||
{
|
||||
UITouch* touch = [touches objectAtIndex:i];
|
||||
UITouch *touch = [touches objectAtIndex:i];
|
||||
|
||||
if (touch.view != [RAGameView get].view)
|
||||
continue;
|
||||
@ -178,19 +178,20 @@ enum
|
||||
|
||||
- (id)_keyCommandForEvent:(UIEvent*)event
|
||||
{
|
||||
NSUInteger i;
|
||||
// This gets called twice with the same timestamp for each keypress, that's fine for polling
|
||||
// but is bad for business with events.
|
||||
/* This gets called twice with the same timestamp
|
||||
* for each keypress, that's fine for polling
|
||||
* but is bad for business with events. */
|
||||
static double last_time_stamp;
|
||||
|
||||
if (last_time_stamp == event.timestamp)
|
||||
return [super _keyCommandForEvent:event];
|
||||
last_time_stamp = event.timestamp;
|
||||
|
||||
// If the _hidEvent is null, [event _keyCode] will crash. (This happens with the on screen keyboard.)
|
||||
/* If the _hidEvent is null, [event _keyCode] will crash.
|
||||
* (This happens with the on screen keyboard). */
|
||||
if (event._hidEvent)
|
||||
{
|
||||
NSString* ch = (NSString*)event._privateInput;
|
||||
NSString *ch = (NSString*)event._privateInput;
|
||||
uint32_t character = 0;
|
||||
uint32_t mod = 0;
|
||||
|
||||
@ -203,7 +204,9 @@ enum
|
||||
|
||||
if (ch && ch.length != 0)
|
||||
{
|
||||
unsigned i;
|
||||
character = [ch characterAtIndex:0];
|
||||
|
||||
apple_input_keyboard_event(event._isKeyDown,
|
||||
(uint32_t)event._keyCode, 0, mod,
|
||||
RETRO_DEVICE_KEYBOARD);
|
||||
@ -235,12 +238,17 @@ enum
|
||||
if (!(get_ios_version_major() >= 7) && [event respondsToSelector:@selector(_gsEvent)])
|
||||
{
|
||||
// Stolen from: http://nacho4d-nacho4d.blogspot.com/2012/01/catching-keyboard-events-in-ios.html
|
||||
const uint8_t* eventMem = objc_unretainedPointer([event performSelector:@selector(_gsEvent)]);
|
||||
const uint8_t *eventMem = objc_unretainedPointer([event performSelector:@selector(_gsEvent)]);
|
||||
int eventType = eventMem ? *(int*)&eventMem[8] : 0;
|
||||
|
||||
if (eventType == GSEVENT_TYPE_KEYDOWN || eventType == GSEVENT_TYPE_KEYUP)
|
||||
switch (eventType)
|
||||
{
|
||||
case GSEVENT_TYPE_KEYDOWN:
|
||||
case GSEVENT_TYPE_KEYUP:
|
||||
apple_input_keyboard_event(eventType == GSEVENT_TYPE_KEYDOWN,
|
||||
*(uint16_t*)&eventMem[0x3C], 0, 0, RETRO_DEVICE_KEYBOARD);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -278,14 +286,14 @@ void notify_content_loaded(void)
|
||||
- (void)applicationDidFinishLaunching:(UIApplication *)application
|
||||
{
|
||||
driver_t *driver = NULL;
|
||||
|
||||
apple_platform = self;
|
||||
|
||||
[self setDelegate:self];
|
||||
|
||||
if (rarch_main(0, NULL))
|
||||
apple_rarch_exited();
|
||||
|
||||
// Setup window
|
||||
/* Setup window */
|
||||
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
|
||||
[self.window makeKeyAndVisible];
|
||||
|
||||
@ -360,9 +368,9 @@ void notify_content_loaded(void)
|
||||
|
||||
-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
|
||||
{
|
||||
NSString* filename = (NSString*)url.path.lastPathComponent;
|
||||
NSString *filename = (NSString*)url.path.lastPathComponent;
|
||||
NSError *error = nil;
|
||||
|
||||
NSError* error = nil;
|
||||
[[NSFileManager defaultManager] moveItemAtPath:[url path] toPath:[self.documentsDirectory stringByAppendingPathComponent:filename] error:&error];
|
||||
|
||||
if (error)
|
||||
|
Loading…
x
Reference in New Issue
Block a user