Move menu_list_refresh to menu_displaylist.c

This commit is contained in:
twinaphex 2015-08-18 02:02:56 +02:00
parent 0a35f5e7e9
commit f951f12f9d
3 changed files with 110 additions and 112 deletions

View File

@ -119,6 +119,116 @@ static void print_buf_lines(file_list_t *list, char *buf, int buf_size,
}
#endif
/**
* menu_list_elem_is_dir:
* @list : File list handle.
* @offset : Offset index of element.
*
* Is the current entry at offset @offset a directory?
*
* Returns: true (1) if entry is a directory, otherwise false (0).
**/
static bool menu_list_elem_is_dir(file_list_t *list,
unsigned offset)
{
unsigned type = 0;
menu_list_get_at_offset(list, offset, NULL, NULL, &type, NULL);
return type == MENU_FILE_DIRECTORY;
}
/**
* menu_list_elem_get_first_char:
* @list : File list handle.
* @offset : Offset index of element.
*
* Gets the first character of an element in the
* file list.
*
* Returns: first character of element in file list.
**/
static int menu_list_elem_get_first_char(
file_list_t *list, unsigned offset)
{
int ret;
const char *path = NULL;
menu_list_get_alt_at_offset(list, offset, &path);
ret = tolower(*path);
/* "Normalize" non-alphabetical entries so they
* are lumped together for purposes of jumping. */
if (ret < 'a')
ret = 'a' - 1;
else if (ret > 'z')
ret = 'z' + 1;
return ret;
}
static void menu_list_build_scroll_indices(file_list_t *list)
{
size_t i;
int current;
bool current_is_dir;
menu_navigation_t *nav = menu_navigation_get_ptr();
if (!nav || !list)
return;
nav->scroll.indices.size = 0;
if (!list->size)
return;
nav->scroll.indices.list[nav->scroll.indices.size++] = 0;
current = menu_list_elem_get_first_char(list, 0);
current_is_dir = menu_list_elem_is_dir(list, 0);
for (i = 1; i < list->size; i++)
{
int first = menu_list_elem_get_first_char(list, i);
bool is_dir = menu_list_elem_is_dir(list, i);
if ((current_is_dir && !is_dir) || (first > current))
nav->scroll.indices.list[nav->scroll.indices.size++] = i;
current = first;
current_is_dir = is_dir;
}
nav->scroll.indices.list[nav->scroll.indices.size++] =
list->size - 1;
}
/**
* Before a refresh, we could have deleted a
* file on disk, causing selection_ptr to
* suddendly be out of range.
*
* Ensure it doesn't overflow.
**/
static void menu_list_refresh(file_list_t *list)
{
size_t list_size;
menu_navigation_t *nav = menu_navigation_get_ptr();
menu_list_t *menu_list = menu_list_get_ptr();
if (!nav || !menu_list || !list)
return;
nav->scroll.indices.size = 0;
menu_list_build_scroll_indices(list);
list_size = menu_list_get_size(menu_list);
if ((nav->selection_ptr >= list_size) && list_size)
menu_navigation_set(nav, list_size - 1, true);
else if (!list_size)
menu_navigation_clear(nav, true);
}
static void menu_displaylist_push_perfcounter(
menu_displaylist_info_t *info,
const struct retro_perf_counter **counters,

View File

@ -32,89 +32,6 @@ menu_list_t *menu_list_get_ptr(void)
return entries->menu_list;
}
/**
* menu_list_elem_is_dir:
* @list : File list handle.
* @offset : Offset index of element.
*
* Is the current entry at offset @offset a directory?
*
* Returns: true (1) if entry is a directory, otherwise false (0).
**/
static bool menu_list_elem_is_dir(file_list_t *list,
unsigned offset)
{
unsigned type = 0;
menu_list_get_at_offset(list, offset, NULL, NULL, &type, NULL);
return type == MENU_FILE_DIRECTORY;
}
/**
* menu_list_elem_get_first_char:
* @list : File list handle.
* @offset : Offset index of element.
*
* Gets the first character of an element in the
* file list.
*
* Returns: first character of element in file list.
**/
static int menu_list_elem_get_first_char(
file_list_t *list, unsigned offset)
{
int ret;
const char *path = NULL;
menu_list_get_alt_at_offset(list, offset, &path);
ret = tolower(*path);
/* "Normalize" non-alphabetical entries so they
* are lumped together for purposes of jumping. */
if (ret < 'a')
ret = 'a' - 1;
else if (ret > 'z')
ret = 'z' + 1;
return ret;
}
static void menu_list_build_scroll_indices(file_list_t *list)
{
size_t i;
int current;
bool current_is_dir;
menu_navigation_t *nav = menu_navigation_get_ptr();
if (!nav || !list)
return;
nav->scroll.indices.size = 0;
if (!list->size)
return;
nav->scroll.indices.list[nav->scroll.indices.size++] = 0;
current = menu_list_elem_get_first_char(list, 0);
current_is_dir = menu_list_elem_is_dir(list, 0);
for (i = 1; i < list->size; i++)
{
int first = menu_list_elem_get_first_char(list, i);
bool is_dir = menu_list_elem_is_dir(list, i);
if ((current_is_dir && !is_dir) || (first > current))
nav->scroll.indices.list[nav->scroll.indices.size++] = i;
current = first;
current_is_dir = is_dir;
}
nav->scroll.indices.list[nav->scroll.indices.size++] =
list->size - 1;
}
size_t menu_list_get_size(menu_list_t *list)
{
if (!list)
@ -122,33 +39,6 @@ size_t menu_list_get_size(menu_list_t *list)
return file_list_get_size(list->selection_buf);
}
/**
* Before a refresh, we could have deleted a
* file on disk, causing selection_ptr to
* suddendly be out of range.
*
* Ensure it doesn't overflow.
**/
void menu_list_refresh(file_list_t *list)
{
size_t list_size;
menu_navigation_t *nav = menu_navigation_get_ptr();
menu_list_t *menu_list = menu_list_get_ptr();
if (!nav || !menu_list || !list)
return;
nav->scroll.indices.size = 0;
menu_list_build_scroll_indices(list);
list_size = menu_list_get_size(menu_list);
if ((nav->selection_ptr >= list_size) && list_size)
menu_navigation_set(nav, list_size - 1, true);
else if (!list_size)
menu_navigation_clear(nav, true);
}
static void menu_list_free_list(file_list_t *list)
{
unsigned i;

View File

@ -120,8 +120,6 @@ void menu_list_get_alt_at_offset(const file_list_t *list, size_t idx,
void menu_list_set_alt_at_offset(file_list_t *list, size_t idx,
const char *alt);
void menu_list_refresh(file_list_t *list);
#ifdef __cplusplus
}
#endif