From 93e9616c6321120989c7c51c4183741a82ec0149 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 14 Jun 2015 20:02:01 +0200 Subject: [PATCH] (cocoatouch_browser.m) Cleanups --- ui/drivers/cocoa/cocoatouch_browser.m | 96 ++++++++++++++++----------- 1 file changed, 58 insertions(+), 38 deletions(-) diff --git a/ui/drivers/cocoa/cocoatouch_browser.m b/ui/drivers/cocoa/cocoatouch_browser.m index 794a8388bf..0625b70dc0 100644 --- a/ui/drivers/cocoa/cocoatouch_browser.m +++ b/ui/drivers/cocoa/cocoatouch_browser.m @@ -18,6 +18,7 @@ #include #include #include +#include #include "cocoa_common.h" #include "../../../content.h" @@ -429,6 +430,13 @@ static void file_action(enum file_action action, NSString* source, NSString* tar } } +#define FILEBROWSER_ACTION_UNZIP 0x0e3f899bU +#define FILEBROWSER_ACTION_MOVE 0x7c89307cU +#define FILEBROWSER_ACTION_RENAME 0xce87affdU +#define FILEBROWSER_ACTION_AIRDROP 0x8c6cdb56U +#define FILEBROWSER_ACTION_DELETE 0xadde7058U +#define FILEBROWSER_ACTION_CANCEL 0xab41f40bU + /* Called by the action sheet created in (void)fileAction: */ - (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { @@ -438,50 +446,62 @@ static void file_action(enum file_action action, NSString* source, NSString* tar const char *action_str = action.UTF8String; get_ios_version(&major, &minor); + + action_str_hash = djb2_calculate(action_str); (void)major; (void)minor; - - if (!strcmp(action_str, "Unzip")) - { - UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Enter target directory") message:@"" delegate:self - cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil]; - alertView.alertViewStyle = UIAlertViewStylePlainTextInput; - alertView.tag = FA_UNZIP; - [alertView textFieldAtIndex:0].text = [[target lastPathComponent] stringByDeletingPathExtension]; - [alertView show]; - } - else if (!strcmp(action_str, "Move")) - [self.navigationController pushViewController:[[RAFoldersList alloc] initWithFilePath:target] animated:YES]; - else if (!strcmp(action_str, "Rename")) - { - 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; - [alertView show]; - } -#ifdef __IPHONE_7_0 - else if (!strcmp(action_str, "AirDrop") && (major >= 7)) - { - /* 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]; - } -#endif - else if (!strcmp(action_str, "Delete")) + switch (action_str_hash) { - UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Really delete?") message:@"" delegate:self cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil]; - alertView.tag = FA_DELETE; - [alertView show]; + case FILEBROWSER_ACTION_UNZIP: + { + UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Enter target directory") message:@"" delegate:self + cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil]; + alertView.alertViewStyle = UIAlertViewStylePlainTextInput; + alertView.tag = FA_UNZIP; + [alertView textFieldAtIndex:0].text = [[target lastPathComponent] stringByDeletingPathExtension]; + [alertView show]; + } + break; + case FILEBROWSER_ACTION_MOVE: + [self.navigationController pushViewController:[[RAFoldersList alloc] initWithFilePath:target] animated:YES]; + break; + case FILEBROWSER_ACTION_RENAME: + { + 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; + [alertView show]; + } + break; + case FILEBROWSER_ACTION_AIRDROP: +#ifdef __IPHONE_7_0 + if ((major >= 7)) + { + /* 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]; + } +#endif + break; + case FILEBROWSER_ACTION_DELETE: + { + UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:BOXSTRING("Really delete?") message:@"" delegate:self cancelButtonTitle:BOXSTRING("Cancel") otherButtonTitles:BOXSTRING("OK"), nil]; + alertView.tag = FA_DELETE; + [alertView show]; + } + break; + case FILEBROWSER_ACTION_CANCEL: + apple_display_alert("Action not supported.", "Action Failed"); + break; } - else if (!strcmp(action_str, "Cancel")) /* Zip */ - apple_display_alert("Action not supported.", "Action Failed"); } /* Called by various alert views created in this class,