From b4cebd605e7c5ffe97310932451cc4d3e35af6b5 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 17 Oct 2014 20:55:41 +0200 Subject: [PATCH] Refactor menu_entries_pop_stack --- frontend/menu/menu_entries.c | 19 ------------------- frontend/menu/menu_entries.h | 2 -- frontend/menu/menu_entries_cbs.c | 6 +++--- frontend/menu/menu_list.c | 20 ++++++++++++++++++++ frontend/menu/menu_list.h | 3 +++ 5 files changed, 26 insertions(+), 24 deletions(-) diff --git a/frontend/menu/menu_entries.c b/frontend/menu/menu_entries.c index 33197a7e1b..5f644d169d 100644 --- a/frontend/menu/menu_entries.c +++ b/frontend/menu/menu_entries.c @@ -426,25 +426,6 @@ void menu_flush_stack_type(file_list_t *list, } } -void menu_entries_pop_stack(file_list_t *list, - const char *needle) -{ - const char *path = NULL; - const char *label = NULL; - unsigned type = 0; - - if (!driver.menu || !list) - return; - - driver.menu->need_refresh = true; - file_list_get_last(list, &path, &label, &type); - while (strcmp(needle, label) == 0) - { - menu_list_pop(list, &driver.menu->selection_ptr); - file_list_get_last(list, &path, &label, &type); - } -} - void menu_flush_stack_label(file_list_t *list, const char *needle) { diff --git a/frontend/menu/menu_entries.h b/frontend/menu/menu_entries.h index 3a36efde9a..4f305d18fc 100644 --- a/frontend/menu/menu_entries.h +++ b/frontend/menu/menu_entries.h @@ -36,8 +36,6 @@ int menu_entries_parse_list(file_list_t *list, file_list_t *menu_list, int menu_entries_deferred_push(file_list_t *list, file_list_t *menu_list); -void menu_entries_pop_stack(file_list_t *list, const char *needle); - void menu_flush_stack_type(file_list_t *list, unsigned final_type); void menu_flush_stack_label(file_list_t *list, const char *needle); diff --git a/frontend/menu/menu_entries_cbs.c b/frontend/menu/menu_entries_cbs.c index 52ca23dafe..f0ed853e16 100644 --- a/frontend/menu/menu_entries_cbs.c +++ b/frontend/menu/menu_entries_cbs.c @@ -256,7 +256,7 @@ static int action_ok_path_use_directory(const char *path, if (setting->type == ST_DIR) { menu_action_setting_set_current_string(setting, menu_path); - menu_entries_pop_stack(driver.menu->menu_stack, setting->name); + menu_list_pop_stack_by_needle(driver.menu->menu_stack, setting->name); } return 0; @@ -448,7 +448,7 @@ static int action_ok_file_load(const char *path, if (setting && setting->type == ST_PATH) { menu_action_setting_set_current_string_path(setting, menu_path, path); - menu_entries_pop_stack(driver.menu->menu_stack, setting->name); + menu_list_pop_stack_by_needle(driver.menu->menu_stack, setting->name); } else { @@ -489,7 +489,7 @@ static int action_ok_set_path(const char *path, return -1; menu_action_setting_set_current_string_path(setting, menu_path, path); - menu_entries_pop_stack(driver.menu->menu_stack, setting->name); + menu_list_pop_stack_by_needle(driver.menu->menu_stack, setting->name); return 0; } diff --git a/frontend/menu/menu_list.c b/frontend/menu/menu_list.c index 335d723b3e..20470dbf92 100644 --- a/frontend/menu/menu_list.c +++ b/frontend/menu/menu_list.c @@ -15,6 +15,7 @@ #include "../../driver.h" #include "menu_list.h" +#include void menu_list_free(file_list_t *list) { @@ -49,6 +50,25 @@ void menu_list_pop_stack(file_list_t *list) } } +void menu_list_pop_stack_by_needle(file_list_t *list, + const char *needle) +{ + const char *path = NULL; + const char *label = NULL; + unsigned type = 0; + + if (!driver.menu || !list) + return; + + driver.menu->need_refresh = true; + file_list_get_last(list, &path, &label, &type); + while (strcmp(needle, label) == 0) + { + menu_list_pop(list, &driver.menu->selection_ptr); + file_list_get_last(list, &path, &label, &type); + } +} + void menu_list_pop(file_list_t *list, size_t *directory_ptr) { if (!driver.menu_ctx) diff --git a/frontend/menu/menu_list.h b/frontend/menu/menu_list.h index 568409c75a..f540a1984b 100644 --- a/frontend/menu/menu_list.h +++ b/frontend/menu/menu_list.h @@ -29,6 +29,9 @@ void menu_list_pop(file_list_t *list, size_t *directory_ptr); void menu_list_pop_stack(file_list_t *list); +void menu_list_pop_stack_by_needle(file_list_t *list, + const char *needle); + void menu_list_clear(file_list_t *list); void menu_list_push(file_list_t *list,