Move menu_common_list_{insert|delete} to menu_driver.c

This commit is contained in:
twinaphex 2015-05-19 23:28:32 +02:00
parent 2bcc2d08d7
commit c27211d60a
3 changed files with 49 additions and 51 deletions

View File

@ -18,6 +18,7 @@
#include <string/string_list.h>
#include "menu_driver.h"
#include "menu.h"
#include "menu_entries_cbs.h"
#include "menu_displaylist.h"
#include "../driver.h"
#include "../general.h"
@ -181,12 +182,36 @@ const menu_ctx_driver_t *menu_ctx_driver_get_ptr(void)
return driver->menu_ctx;
}
static void menu_driver_list_delete_common(file_list_t *list, size_t idx,
size_t list_size)
{
menu_file_list_cbs_t *cbs = NULL;
if (!list)
return;
cbs = (menu_file_list_cbs_t*)list->list[idx].actiondata;
if (cbs)
{
cbs->action_start = NULL;
cbs->action_ok = NULL;
cbs->action_cancel = NULL;
cbs->action_left = NULL;
cbs->action_right = NULL;
cbs->action_deferred_push = NULL;
free(list->list[idx].actiondata);
}
list->list[idx].actiondata = NULL;
}
void menu_driver_list_delete(file_list_t *list, size_t i, size_t list_size)
{
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
if (driver->list_delete)
driver->list_delete(list, i, list_size);
menu_driver_list_delete_common(list, i, list_size);
}
void menu_driver_list_clear(file_list_t *list)
@ -213,13 +238,34 @@ void menu_driver_list_set_selection(file_list_t *list)
driver->list_set_selection(list);
}
static void menu_driver_list_insert_common(file_list_t *list,
const char *path, const char *label,
unsigned type, size_t idx)
{
if (!list)
return;
list->list[idx].actiondata = (menu_file_list_cbs_t*)
calloc(1, sizeof(menu_file_list_cbs_t));
if (!list->list[idx].actiondata)
{
RARCH_ERR("Action data could not be allocated.\n");
return;
}
menu_entries_cbs_init(list, path, label, type, idx);
}
void menu_driver_list_insert(file_list_t *list, const char *path,
const char *label, size_t list_size)
const char *label, unsigned type, size_t list_size)
{
const menu_ctx_driver_t *driver = menu_ctx_driver_get_ptr();
if (driver->list_insert)
driver->list_insert(list, path, label, list_size);
menu_driver_list_insert_common(list, path, label, type, list_size);
}
void menu_driver_list_cache(bool state, unsigned action)

View File

@ -337,7 +337,7 @@ void menu_driver_list_cache(bool state, unsigned action);
void menu_driver_list_delete(file_list_t *list, size_t i, size_t list_size);
void menu_driver_list_insert(file_list_t *list, const char *path,
const char *label, size_t list_size);
const char *label, unsigned type, size_t list_size);
void menu_driver_list_clear(file_list_t *list);

View File

@ -21,7 +21,6 @@
#include "../driver.h"
#include "menu.h"
#include "menu_list.h"
#include "menu_entries_cbs.h"
#include "menu_navigation.h"
menu_list_t *menu_list_get_ptr(void)
@ -143,29 +142,6 @@ void menu_list_refresh(file_list_t *list)
menu_navigation_clear(nav, true);
}
static void menu_common_list_delete(file_list_t *list, size_t idx,
size_t list_size)
{
menu_file_list_cbs_t *cbs = NULL;
if (!list)
return;
cbs = (menu_file_list_cbs_t*)list->list[idx].actiondata;
if (cbs)
{
cbs->action_start = NULL;
cbs->action_ok = NULL;
cbs->action_cancel = NULL;
cbs->action_left = NULL;
cbs->action_right = NULL;
cbs->action_deferred_push = NULL;
free(list->list[idx].actiondata);
}
list->list[idx].actiondata = NULL;
}
static void menu_list_destroy(file_list_t *list)
{
unsigned i;
@ -178,10 +154,7 @@ static void menu_list_destroy(file_list_t *list)
goto end;
for (i = 0; i < list->size; i++)
{
menu_driver_list_delete(list, i, list->size);
menu_common_list_delete(list, i, list->size);
}
end:
if (list)
@ -343,7 +316,6 @@ void menu_list_pop(file_list_t *list, size_t *directory_ptr)
size_t list_size = list->size - 1;
menu_driver_list_delete(list, list_size, list_size);
menu_common_list_delete(list, list_size, list_size);
}
end:
@ -368,25 +340,6 @@ end:
file_list_clear(list);
}
static void menu_common_list_insert(file_list_t *list,
const char *path, const char *label,
unsigned type, size_t idx)
{
if (!list)
return;
list->list[idx].actiondata = (menu_file_list_cbs_t*)
calloc(1, sizeof(menu_file_list_cbs_t));
if (!list->list[idx].actiondata)
{
RARCH_ERR("Action data could not be allocated.\n");
return;
}
menu_entries_cbs_init(list, path, label, type, idx);
}
void menu_list_push(file_list_t *list,
const char *path, const char *label,
unsigned type, size_t directory_ptr)
@ -395,8 +348,7 @@ void menu_list_push(file_list_t *list,
return;
file_list_push(list, path, label, type, directory_ptr);
menu_driver_list_insert(list, path, label, list->size - 1);
menu_common_list_insert(list, path, label, type, list->size - 1);
menu_driver_list_insert(list, path, label, type, list->size - 1);
}
void menu_list_set_alt_at_offset(file_list_t *list, size_t idx,