From e1d698155977bba22e878f4d22afb9b57c017b3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcelo=20Munhoz=20P=C3=A9los?= Date: Mon, 8 Jul 2013 22:28:17 -0300 Subject: [PATCH 1/6] Changes iOS directory to apple in gitignore. --- .gitignore | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index f483ccc30b..0c2ecdafe2 100644 --- a/.gitignore +++ b/.gitignore @@ -46,6 +46,6 @@ profile DerivedData .idea/ *.hmap -ios/tmp -ios/modules/*.dylib -ios/*.mobileprovision +apple/tmp +apple/modules/*.dylib +apple/*.mobileprovision From af3bef602fc988cc42c4d1fb4ef7769825c3770e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcelo=20Munhoz=20P=C3=A9los?= Date: Mon, 8 Jul 2013 23:13:20 -0300 Subject: [PATCH 2/6] Removes file icon from ROM list. --- apple/iOS/browser.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apple/iOS/browser.m b/apple/iOS/browser.m index 38ee180681..9c6648a812 100644 --- a/apple/iOS/browser.m +++ b/apple/iOS/browser.m @@ -139,12 +139,17 @@ - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { RADirectoryItem* path = (RADirectoryItem*)[self itemForIndexPath:indexPath]; + static NSString *CellIdentifier = @"path"; - UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:@"path"]; - cell = (cell != nil) ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"path"]; + UITableViewCell* cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; + cell = (cell != nil) ? cell : [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; cell.textLabel.text = [path.path lastPathComponent]; cell.accessoryType = (path.isDirectory) ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone; - cell.imageView.image = [UIImage imageNamed:(path.isDirectory) ? @"ic_dir" : @"ic_file"]; + + if (path.isDirectory) { + cell.imageView.image = [UIImage imageNamed:@"ic_dir"]; + } + return cell; } From 1d99eac1ec6f5ea964f061f441bb1ed791e2f843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcelo=20Munhoz=20P=C3=A9los?= Date: Mon, 8 Jul 2013 23:55:55 -0300 Subject: [PATCH 3/6] Implements delete in ROM list. --- apple/iOS/browser.m | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/apple/iOS/browser.m b/apple/iOS/browser.m index 9c6648a812..318e5b751e 100644 --- a/apple/iOS/browser.m +++ b/apple/iOS/browser.m @@ -158,6 +158,21 @@ return _sectionNames; } +- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath { + if (editingStyle == UITableViewCellEditingStyleDelete) { + NSFileManager *fileManager = [NSFileManager defaultManager]; + RADirectoryItem *path = (RADirectoryItem*)[self itemForIndexPath:indexPath]; + + BOOL didRemoveItem = [fileManager removeItemAtPath:path.path error:nil]; + + if (didRemoveItem) { + [self refresh]; + } else { + apple_display_alert(@"Not possible to delete file.", 0); + } + } +} + @end @implementation RAModuleList From 622702eb923e2aaaaac640f1b6e2f0b6bab91c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcelo=20Munhoz=20Pe=CC=81los?= Date: Tue, 9 Jul 2013 16:51:02 -0300 Subject: [PATCH 4/6] Adds new Folder option in ROM list. --- apple/iOS/browser.m | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/apple/iOS/browser.m b/apple/iOS/browser.m index 318e5b751e..deee63ebfb 100644 --- a/apple/iOS/browser.m +++ b/apple/iOS/browser.m @@ -42,10 +42,9 @@ NSString* ragPath = [rootPath stringByAppendingPathComponent:@"RetroArchGames"]; RADirectoryList* list = [RADirectoryList directoryListForPath:path_is_directory(ragPath.UTF8String) ? ragPath : rootPath]; - list.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Refresh" - style:UIBarButtonItemStyleBordered - target:list - action:@selector(refresh)]; + + list.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"New Folder" style:UIBarButtonItemStyleBordered target:list action:@selector(createNewFolder)]; + return list; } @@ -173,6 +172,27 @@ } } +- (void)createNewFolder { + UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Enter new folder name" message:@"" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; + alertView.alertViewStyle = UIAlertViewStylePlainTextInput; + [alertView show]; +} + +- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { + NSString *text = [[alertView textFieldAtIndex:0] text]; + + if (buttonIndex == 1 && ![text isEqualToString:@""]) { + NSString *directoryPath = [_path stringByAppendingPathComponent:text]; + BOOL didCreateFolder = [[NSFileManager defaultManager] createDirectoryAtPath:directoryPath withIntermediateDirectories:YES attributes:nil error:nil]; + + if (didCreateFolder) { + [self refresh]; + } else { + apple_display_alert(@"Not possible to create folder.", 0); + } + } +} + @end @implementation RAModuleList From acfa16089e4305d343e3d5ffa1617e78b2e65ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcelo=20Munhoz=20P=C3=A9los?= Date: Thu, 11 Jul 2013 23:40:40 -0300 Subject: [PATCH 5/6] Implements file move option in ROM list. --- apple/iOS/browser.m | 124 +++++++++++++++++++++++++++++++++++++++++--- apple/iOS/views.h | 15 +++++- 2 files changed, 131 insertions(+), 8 deletions(-) diff --git a/apple/iOS/browser.m b/apple/iOS/browser.m index deee63ebfb..fc038996e1 100644 --- a/apple/iOS/browser.m +++ b/apple/iOS/browser.m @@ -22,11 +22,6 @@ #include "conf/config_file.h" #include "file.h" -@interface RADirectoryItem : NSObject -@property (strong) NSString* path; -@property bool isDirectory; -@end - @implementation RADirectoryItem @end @@ -147,11 +142,32 @@ if (path.isDirectory) { cell.imageView.image = [UIImage imageNamed:@"ic_dir"]; + cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + } else { + cell.imageView.image = nil; + cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; } return cell; } +- (void)tableView:(UITableView*)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath*)indexPath { + self.selectedItem = [self itemForIndexPath:indexPath]; + UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; + UIActionSheet *menu = [[UIActionSheet alloc] initWithTitle:cell.textLabel.text delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Move", nil]; + + [menu showInView:[self view]]; +} + +- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { + if (buttonIndex == 0) { + RAFoldersList *foldersListViewController = [[RAFoldersList alloc] initWithFilePath:self.selectedItem.path]; + UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:foldersListViewController]; + + [self presentViewController:navigationController animated:YES completion:nil]; + } +} + - (NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView { return _sectionNames; @@ -167,7 +183,7 @@ if (didRemoveItem) { [self refresh]; } else { - apple_display_alert(@"Not possible to delete file.", 0); + apple_display_alert(@"It was not possible to delete file.", 0); } } } @@ -188,7 +204,7 @@ if (didCreateFolder) { [self refresh]; } else { - apple_display_alert(@"Not possible to create folder.", 0); + apple_display_alert(@"It was not possible to create folder.", 0); } } } @@ -262,4 +278,98 @@ return cell; } +@end + +@implementation RAFoldersList { + NSMutableArray *directories; + NSString *currentDirectoryPath, *selectedFilePath, *fileName; +} + +- (id)initWithFilePath:(NSString *)path +{ + self = [super initWithStyle:UITableViewStyleGrouped]; + + selectedFilePath = path; + NSFileManager *fileManager = [NSFileManager defaultManager]; + fileName = [fileManager displayNameAtPath:path]; + currentDirectoryPath = [path stringByDeletingLastPathComponent]; + NSArray *files = [fileManager contentsOfDirectoryAtPath:currentDirectoryPath error:nil]; + directories = [[NSMutableArray alloc] init]; + + for (int i = 0; i < files.count; i++) { + NSString *filePath = [currentDirectoryPath stringByAppendingPathComponent:files[i]]; + + BOOL isDir; + if ([fileManager fileExistsAtPath:filePath isDirectory:&isDir] && isDir) { + [directories addObject:files[i]]; + } + } + + [self setTitle:[@"Move " stringByAppendingString:fileName]]; + + return self; +} + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(dismissViewController)]; +} + +- (void) dismissViewController +{ + [self dismissViewControllerAnimated:YES completion:nil]; +} + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return directories.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + static NSString *CellIdentifier = @"Directory"; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; + + if (cell == nil) { + cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; + } + + cell.textLabel.text = directories[indexPath.row]; + + return cell; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; + NSString *directoryPath = [currentDirectoryPath stringByAppendingPathComponent:cell.textLabel.text]; + NSString *newPath = [directoryPath stringByAppendingPathComponent:fileName]; + + BOOL didMove = [[NSFileManager defaultManager] moveItemAtPath:selectedFilePath toPath:newPath error:nil]; + + if (didMove) { + NSArray *viewsControllers = [[self presentingViewController] childViewControllers]; + + // Searches for RADirectoryList instance and call the refresh method + for (int i = 0; i < viewsControllers.count; i++) { + if ([viewsControllers[i] isKindOfClass:[RADirectoryList class]]) { + [viewsControllers[i] refresh]; + break; + } + } + } else { + apple_display_alert(@"It was not possible to move the file", 0); + } + + [self dismissViewController]; +} + + @end diff --git a/apple/iOS/views.h b/apple/iOS/views.h index 47da854e63..5b058b2ede 100644 --- a/apple/iOS/views.h +++ b/apple/iOS/views.h @@ -32,7 +32,15 @@ @end // browser.m -@interface RADirectoryList : RATableViewController +@interface RADirectoryItem : NSObject +@property (strong) NSString* path; +@property bool isDirectory; +@end + +// browser.m +@interface RADirectoryList : RATableViewController +@property (nonatomic, weak) RADirectoryItem *selectedItem; + + (id)directoryListAtBrowseRoot; + (id)directoryListForPath:(NSString*)path; - (id)initWithPath:(NSString*)path; @@ -43,6 +51,11 @@ - (id)initWithGame:(NSString*)path; @end +// browser.m +@interface RAFoldersList : UITableViewController +- (id) initWithFilePath:(NSString *)path; +@end + // RAModuleInfo.m @interface RAModuleInfoList : RATableViewController - (id)initWithModuleInfo:(RAModuleInfo*)info; From edc710d124ac7ada93546e36cdb9b425d1e34641 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcelo=20Munhoz=20P=C3=A9los?= Date: Sat, 13 Jul 2013 00:05:21 -0300 Subject: [PATCH 6/6] Add toolbar in Rom's list to accommodate refresh and new folder buttons. --- apple/RetroArch/main.m | 4 +++- apple/iOS/browser.m | 20 ++++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/apple/RetroArch/main.m b/apple/RetroArch/main.m index 228051767c..a0fd5ead18 100644 --- a/apple/RetroArch/main.m +++ b/apple/RetroArch/main.m @@ -212,7 +212,7 @@ int main(int argc, char *argv[]) { UIWindow* _window; - bool _isGameTop; + bool _isGameTop, _isRomList; uint32_t _settingMenusInBackStack; uint32_t _enabledOrientations; @@ -272,11 +272,13 @@ int main(int argc, char *argv[]) - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { _isGameTop = [viewController isKindOfClass:[RAGameView class]]; + _isRomList = [viewController isKindOfClass:[RADirectoryList class]]; [[UIApplication sharedApplication] setStatusBarHidden:_isGameTop withAnimation:UIStatusBarAnimationNone]; [[UIApplication sharedApplication] setIdleTimerDisabled:_isGameTop]; self.navigationBarHidden = _isGameTop; + [self setToolbarHidden:!_isRomList animated:YES]; self.topViewController.navigationItem.rightBarButtonItem = [self createSettingsButton]; } diff --git a/apple/iOS/browser.m b/apple/iOS/browser.m index fc038996e1..13a9ea10b4 100644 --- a/apple/iOS/browser.m +++ b/apple/iOS/browser.m @@ -35,11 +35,7 @@ { NSString* rootPath = RetroArch_iOS.get.documentsDirectory; NSString* ragPath = [rootPath stringByAppendingPathComponent:@"RetroArchGames"]; - RADirectoryList* list = [RADirectoryList directoryListForPath:path_is_directory(ragPath.UTF8String) ? ragPath : rootPath]; - - list.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"New Folder" style:UIBarButtonItemStyleBordered target:list action:@selector(createNewFolder)]; - return list; } @@ -57,6 +53,22 @@ self = [super initWithStyle:UITableViewStylePlain]; self.title = path.lastPathComponent; self.hidesHeaders = YES; + + NSMutableArray *toolbarButtons = [[NSMutableArray alloc] initWithCapacity:3]; + + UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh)]; + refreshButton.style = UIBarButtonItemStyleBordered; + [toolbarButtons addObject:refreshButton]; + + UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil]; + [toolbarButtons addObject:flexibleSpace]; + + UIBarButtonItem *newFolderButton = [[UIBarButtonItem alloc] initWithTitle:@"New Folder" style:UIBarButtonItemStyleBordered target:self action:@selector(createNewFolder)]; + [toolbarButtons addObject:newFolderButton]; + + [[[RetroArch_iOS get] toolbar] setItems:toolbarButtons]; + [self setToolbarItems:toolbarButtons]; + [self refresh]; return self;