Merge pull request #257 from mpelos/master

Simple file managament for iOS
This commit is contained in:
Squarepusher 2013-07-13 13:29:11 -07:00
commit 586bcd1258
4 changed files with 195 additions and 18 deletions

6
.gitignore vendored
View File

@ -46,6 +46,6 @@ profile
DerivedData
.idea/
*.hmap
ios/tmp
ios/modules/*.dylib
ios/*.mobileprovision
apple/tmp
apple/modules/*.dylib
apple/*.mobileprovision

View File

@ -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];
}

View File

@ -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
@ -40,12 +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:@"Refresh"
style:UIBarButtonItemStyleBordered
target:list
action:@selector(refresh)];
return list;
}
@ -63,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;
@ -139,20 +145,82 @@
- (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"];
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;
}
- (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(@"It was not possible to delete file.", 0);
}
}
}
- (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(@"It was not possible to create folder.", 0);
}
}
}
@end
@implementation RAModuleList
@ -222,4 +290,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

View File

@ -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 <UIActionSheetDelegate>
@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;