ios: Use a UINavigationController to manage file browser history.

This commit is contained in:
meancoot 2013-02-08 15:43:19 -05:00
parent 675468e9d6
commit 7b3ebc3078
7 changed files with 86 additions and 47 deletions

View File

@ -13,6 +13,7 @@
962979F616C43B9500E6DCE0 /* ic_dir.png in Resources */ = {isa = PBXBuildFile; fileRef = 962979F416C43B9500E6DCE0 /* ic_dir.png */; };
962979F716C43B9500E6DCE0 /* ic_file.png in Resources */ = {isa = PBXBuildFile; fileRef = 962979F516C43B9500E6DCE0 /* ic_file.png */; };
96297A0116C4767F00E6DCE0 /* dirent_list.c in Sources */ = {isa = PBXBuildFile; fileRef = 962979FF16C4767F00E6DCE0 /* dirent_list.c */; };
96297A0516C4996400E6DCE0 /* browser.m in Sources */ = {isa = PBXBuildFile; fileRef = 96297A0416C4996400E6DCE0 /* browser.m */; };
96AFAE2A16C1D4EA009DE44C /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96AFAE2916C1D4EA009DE44C /* UIKit.framework */; };
96AFAE2C16C1D4EA009DE44C /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96AFAE2B16C1D4EA009DE44C /* Foundation.framework */; };
96AFAE2E16C1D4EA009DE44C /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 96AFAE2D16C1D4EA009DE44C /* CoreGraphics.framework */; };
@ -89,6 +90,8 @@
962979F516C43B9500E6DCE0 /* ic_file.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ic_file.png; path = "../android/phoenix/res/drawable-xhdpi/ic_file.png"; sourceTree = "<group>"; };
962979FF16C4767F00E6DCE0 /* dirent_list.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = dirent_list.c; sourceTree = "<group>"; };
96297A0016C4767F00E6DCE0 /* dirent_list.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = dirent_list.h; sourceTree = "<group>"; };
96297A0316C4996400E6DCE0 /* browser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = browser.h; sourceTree = "<group>"; };
96297A0416C4996400E6DCE0 /* browser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = browser.m; sourceTree = "<group>"; };
96AFAE2516C1D4EA009DE44C /* RetroArch.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = RetroArch.app; sourceTree = BUILT_PRODUCTS_DIR; };
96AFAE2916C1D4EA009DE44C /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
96AFAE2B16C1D4EA009DE44C /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
@ -345,6 +348,8 @@
96CF015B16C2F72900ABF9C9 /* ios_input.c */,
9629797516C3CD2400E6DCE0 /* dirlist.h */,
9629797616C3CD2400E6DCE0 /* dirlist.m */,
96297A0316C4996400E6DCE0 /* browser.h */,
96297A0416C4996400E6DCE0 /* browser.m */,
);
path = RetroArch;
sourceTree = "<group>";
@ -793,6 +798,7 @@
962979ED16C3E86F00E6DCE0 /* gameview.m in Sources */,
962979EF16C3EA3E00E6DCE0 /* ioseagl_ctx.c in Sources */,
96297A0116C4767F00E6DCE0 /* dirent_list.c in Sources */,
96297A0516C4996400E6DCE0 /* browser.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -7,6 +7,7 @@
#import "AppDelegate.h"
#import "dirlist.h"
#import "browser.h"
#define MAX_TOUCH 16
extern struct
@ -27,9 +28,9 @@ extern uint32_t ios_current_touch_count ;
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
self.window.rootViewController = [[dirlist_view alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
self.window.rootViewController = [[browser alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
else
self.window.rootViewController = [[dirlist_view alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
self.window.rootViewController = [[browser alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
[self.window makeKeyAndVisible];
}

14
ios/RetroArch/browser.h Normal file
View File

@ -0,0 +1,14 @@
//
// browser.h
// RetroArch
//
// Created by Jason Fetters on 2/7/13.
// Copyright (c) 2013 RetroArch. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIkit.h>
@interface browser : UINavigationController
@end

21
ios/RetroArch/browser.m Normal file
View File

@ -0,0 +1,21 @@
//
// browser.m
// RetroArch
//
// Created by Jason Fetters on 2/7/13.
// Copyright (c) 2013 RetroArch. All rights reserved.
//
#import "browser.h"
#import "dirlist.h"
@implementation browser
- (void)viewDidLoad
{
[super viewDidLoad];
[self pushViewController:[[[dirlist_view alloc] init] load_path:"/" ] animated:NO];
}
@end

View File

@ -22,7 +22,7 @@ static bool is_dirent_verboten(const struct dirent* entry)
{
if (!entry) return true;
if (strcmp(entry->d_name, ".") == 0) return true;
//if (strcmp(entry->d_name, "..") == 0) return true;
if (strcmp(entry->d_name, "..") == 0) return true;
return false;
}

View File

@ -8,5 +8,5 @@
#import <UIKit/UIKit.h>
@interface dirlist_view : UIViewController <UITableViewDelegate, UITableViewDataSource>
- (id)load_path:(const char*)directory;
@end

View File

@ -12,7 +12,8 @@
@implementation dirlist_view
{
char path[4096];
char* path;
UITableView* table;
struct dirent_list* files;
@ -20,26 +21,43 @@
UIImage* folder_icon;
};
-(void)dealloc
- (id)load_path:(const char*)directory
{
free_dirent_list(files);
files = 0;
files = build_dirent_list(directory);
[table reloadData];
free(path);
path = strdup(directory);
[self setTitle: [[NSString alloc] initWithUTF8String:directory]];
return self;
}
- (void)dealloc
{
free_dirent_list(files);
free(path);
}
- (void)viewDidLoad
{
[super viewDidLoad];
file_icon = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ic_file" ofType:@"png"]];
folder_icon = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ic_dir" ofType:@"png"]];
[super viewDidLoad];
strcpy(path, "/");
files = build_dirent_list(path);
table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 640, 480) style:UITableViewStylePlain];
table.dataSource = self;
table.delegate = self;
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc]
initWithTitle:@"Parent"
style:UIBarButtonItemStyleBordered
target:nil action:nil];
self.view = table;
}
@ -49,38 +67,27 @@
if (!item) return;
char new_path[4096];
strcpy(new_path, path);
strcat(new_path, item->d_name);
if (item->d_type)
{
if (strcmp(item->d_name, "..") == 0)
{
char* last_slash = strrchr(path, '/');
if (last_slash) *last_slash = 0;
path[0] = (path[0] == 0) ? '/' : path[0];
}
else
{
strcat(path, "/");
strcat(path, item->d_name);
}
strcat(new_path, "/");
free_dirent_list(files);
files = build_dirent_list(path);
[table reloadData];
UINavigationController *pvc = (UINavigationController*)self.parentViewController;
[pvc pushViewController:[[[dirlist_view alloc] init] load_path: new_path] animated:YES];
}
else
{
UIWindow *window = [UIApplication sharedApplication].keyWindow;
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
window.rootViewController = [[game_view alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
else
window.rootViewController = [[game_view alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
strcat(path, "/");
strcat(path, item->d_name);
bool is_phone = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone);
window.rootViewController = [[game_view alloc] initWithNibName:
(is_phone ? @"ViewController_iPhone" : @"ViewController_iPad") bundle:nil];
extern void ios_load_game(const char*);
ios_load_game(path);
ios_load_game(new_path);
}
}
@ -99,18 +106,8 @@
if (item)
{
cell.textLabel.text = [[NSString string] initWithUTF8String:item->d_name];
if (item->d_type)
{
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.imageView.image = folder_icon;
}
else
{
cell.accessoryType = UITableViewCellAccessoryNone;
cell.imageView.image = file_icon;
}
cell.accessoryType = (item->d_type) ? UITableViewCellAccessoryDisclosureIndicator : UITableViewCellAccessoryNone;
cell.imageView.image = (item->d_type) ? folder_icon : file_icon;
[cell.imageView sizeToFit];
}