diff --git a/apple/iOS/menu.m b/apple/iOS/menu.m index 80fee20a4d..e00b70284a 100644 --- a/apple/iOS/menu.m +++ b/apple/iOS/menu.m @@ -84,6 +84,17 @@ static void RunActionSheet(const char* title, const struct string_list* items, U [[self itemForIndexPath:indexPath] wasSelectedOnTableView:tableView ofController:self]; } +- (void)willReloadData +{ + +} + +- (void)reloadData +{ + [self willReloadData]; + [[self tableView] reloadData]; +} + @end /*********************************************/ @@ -505,33 +516,49 @@ static void RunActionSheet(const char* title, const struct string_list* items, U /*********************************************/ @implementation RAHistoryMenu +- (void)dealloc +{ + if (_history) + rom_history_free(_history); +} + - (id)initWithHistoryPath:(NSString *)historyPath { if ((self = [super initWithStyle:UITableViewStylePlain])) { - RAHistoryMenu* __weak weakSelf = self; - _history = rom_history_init(historyPath.UTF8String, 100); - - NSMutableArray* section = [NSMutableArray arrayWithObject:@""]; - [self.sections addObject:section]; - - for (int i = 0; _history && i != rom_history_size(_history); i ++) - { - RAMenuItemBasic* item = [RAMenuItemBasic itemWithDescription:BOXSTRING(path_basename(apple_rom_history_get_path(weakSelf.history, i))) - action:^{ apple_run_core(BOXSTRING(apple_rom_history_get_core_path(weakSelf.history, i)), - apple_rom_history_get_path(weakSelf.history, i)); } - detail:^{ return BOXSTRING(apple_rom_history_get_core_name(weakSelf.history, i)); }]; - [section addObject:item]; - } + [self reloadData]; + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Clear History" + style:UIBarButtonItemStyleBordered target:self action:@selector(clearHistory)]; } return self; } -- (void)dealloc +- (void)clearHistory { - rom_history_free(self.history); + if (_history) + rom_history_clear(_history); + [self reloadData]; +} + +- (void)willReloadData +{ + printf("DOING\n"); + + RAHistoryMenu* __weak weakSelf = self; + NSMutableArray* section = [NSMutableArray arrayWithObject:@""]; + + for (int i = 0; _history && i != rom_history_size(_history); i ++) + { + RAMenuItemBasic* item = [RAMenuItemBasic itemWithDescription:BOXSTRING(path_basename(apple_rom_history_get_path(weakSelf.history, i))) + action:^{ apple_run_core(BOXSTRING(apple_rom_history_get_core_path(weakSelf.history, i)), + apple_rom_history_get_path(weakSelf.history, i)); } + detail:^{ return BOXSTRING(apple_rom_history_get_core_name(weakSelf.history, i)); }]; + [section addObject:item]; + } + + self.sections = [NSMutableArray arrayWithObject:section]; } @end diff --git a/frontend/menu/history.c b/frontend/menu/history.c index 19a924104b..b4d05c6aa9 100644 --- a/frontend/menu/history.c +++ b/frontend/menu/history.c @@ -134,6 +134,14 @@ void rom_history_free(rom_history_t *hist) free(hist); } +void rom_history_clear(rom_history_t *hist) +{ + size_t i; + for (i = 0; i < hist->cap; i++) + rom_history_free_entry(&hist->entries[i]); + hist->size = 0; +} + size_t rom_history_size(rom_history_t *hist) { return hist->size; diff --git a/frontend/menu/history.h b/frontend/menu/history.h index b0c6ea7a70..1dc772dd0e 100644 --- a/frontend/menu/history.h +++ b/frontend/menu/history.h @@ -27,6 +27,8 @@ typedef struct rom_history rom_history_t; rom_history_t *rom_history_init(const char *path, size_t size); void rom_history_free(rom_history_t *hist); +void rom_history_clear(rom_history_t *hist); + size_t rom_history_size(rom_history_t *hist); void rom_history_get_index(rom_history_t *hist,