diff --git a/frontend/menu/file_browser.c b/frontend/menu/file_browser.c index 6d58eda017..bf033f05db 100644 --- a/frontend/menu/file_browser.c +++ b/frontend/menu/file_browser.c @@ -61,7 +61,7 @@ void filebrowser_set_root_and_ext(void *data, const char *ext, const char *root_ strlcpy(filebrowser->current_dir.root_dir, root_dir, sizeof(filebrowser->current_dir.root_dir)); - filebrowser_iterate(filebrowser, FILEBROWSER_ACTION_RESET); + filebrowser_iterate(filebrowser, RGUI_ACTION_START); } #define GET_CURRENT_PATH(browser) (browser->list->elems[browser->current_dir.ptr].data) @@ -74,21 +74,21 @@ bool filebrowser_iterate(void *data, unsigned action) switch(action) { - case FILEBROWSER_ACTION_UP: + case RGUI_ACTION_UP: if (!filebrowser->list->size) break; filebrowser->current_dir.ptr--; if (filebrowser->current_dir.ptr >= filebrowser->list->size) filebrowser->current_dir.ptr = filebrowser->list->size - 1; break; - case FILEBROWSER_ACTION_DOWN: + case RGUI_ACTION_DOWN: if (!filebrowser->list->size) break; filebrowser->current_dir.ptr++; if (filebrowser->current_dir.ptr >= filebrowser->list->size) filebrowser->current_dir.ptr = 0; break; - case FILEBROWSER_ACTION_LEFT: + case RGUI_ACTION_LEFT: if (!filebrowser->list->size) break; if (filebrowser->current_dir.ptr <= 5) @@ -96,13 +96,13 @@ bool filebrowser_iterate(void *data, unsigned action) else filebrowser->current_dir.ptr -= 5; break; - case FILEBROWSER_ACTION_RIGHT: + case RGUI_ACTION_RIGHT: if (!filebrowser->list->size) break; filebrowser->current_dir.ptr = (min(filebrowser->current_dir.ptr + 5, filebrowser->list->size-1)); break; - case FILEBROWSER_ACTION_SCROLL_UP: + case RGUI_ACTION_SCROLL_UP: if (!filebrowser->list->size) break; if (filebrowser->current_dir.ptr <= entries_to_scroll) @@ -110,26 +110,39 @@ bool filebrowser_iterate(void *data, unsigned action) else filebrowser->current_dir.ptr -= entries_to_scroll; break; - case FILEBROWSER_ACTION_SCROLL_DOWN: + case RGUI_ACTION_SCROLL_DOWN: if (!filebrowser->list->size) break; filebrowser->current_dir.ptr = (min(filebrowser->current_dir.ptr + entries_to_scroll, filebrowser->list->size-1)); break; - case FILEBROWSER_ACTION_OK: + case RGUI_ACTION_OK: ret = directory_parse(filebrowser, GET_CURRENT_PATH(filebrowser)); break; - case FILEBROWSER_ACTION_CANCEL: - fill_pathname_parent_dir(filebrowser->current_dir.directory_path, - filebrowser->current_dir.directory_path, - sizeof(filebrowser->current_dir.directory_path)); + case RGUI_ACTION_CANCEL: + { + char tmp_str[PATH_MAX]; + fill_pathname_parent_dir(tmp_str, rgui->browser->current_dir.directory_path, sizeof(tmp_str)); - ret = directory_parse(filebrowser, filebrowser->current_dir.directory_path); + if (tmp_str[0] != '\0') + { + fill_pathname_parent_dir(filebrowser->current_dir.directory_path, + filebrowser->current_dir.directory_path, + sizeof(filebrowser->current_dir.directory_path)); + + ret = directory_parse(filebrowser, filebrowser->current_dir.directory_path); + } + else + ret = false; + } break; - case FILEBROWSER_ACTION_RESET: + case RGUI_ACTION_START: + filebrowser_set_root_and_ext(rgui->browser, NULL, default_paths.filesystem_root_dir); +#ifdef HAVE_RMENU_XUI + filebrowser_fetch_directory_entries(RGUI_ACTION_OK); +#endif ret = directory_parse(filebrowser, filebrowser->current_dir.root_dir); break; - case FILEBROWSER_ACTION_NOOP: default: break; } @@ -152,55 +165,3 @@ bool filebrowser_reset_current_dir(void *data) filebrowser_t *filebrowser = (filebrowser_t*)data; return directory_parse(filebrowser, filebrowser->current_dir.directory_path); } - -void filebrowser_update(void *data, uint64_t action_ori, const char *extensions) -{ - filebrowser_action_t action = FILEBROWSER_ACTION_NOOP; - bool ret = true; - - switch (action_ori) - { - case RGUI_ACTION_DOWN: - action = FILEBROWSER_ACTION_DOWN; - break; - case RGUI_ACTION_UP: - action = FILEBROWSER_ACTION_UP; - break; - case RGUI_ACTION_RIGHT: - action = FILEBROWSER_ACTION_RIGHT; - break; - case RGUI_ACTION_LEFT: - action = FILEBROWSER_ACTION_LEFT; - break; - case RGUI_ACTION_SCROLL_DOWN: - action = FILEBROWSER_ACTION_SCROLL_DOWN; - break; - case RGUI_ACTION_SCROLL_UP: - action = FILEBROWSER_ACTION_SCROLL_UP; - break; - case RGUI_ACTION_CANCEL: - { - char tmp_str[PATH_MAX]; - fill_pathname_parent_dir(tmp_str, rgui->browser->current_dir.directory_path, sizeof(tmp_str)); - - if (tmp_str[0] != '\0') - action = FILEBROWSER_ACTION_CANCEL; - } - break; - case RGUI_ACTION_START: - action = FILEBROWSER_ACTION_RESET; - filebrowser_set_root_and_ext(rgui->browser, NULL, default_paths.filesystem_root_dir); - strlcpy(rgui->browser->current_dir.extensions, extensions, - sizeof(rgui->browser->current_dir.extensions)); -#ifdef HAVE_RMENU_XUI - filebrowser_fetch_directory_entries(1ULL << RETRO_DEVICE_ID_JOYPAD_B); -#endif - break; - } - - if (action != FILEBROWSER_ACTION_NOOP) - ret = filebrowser_iterate(rgui->browser, action); - - if (!ret) - msg_queue_push(g_extern.msg_queue, "ERROR - Failed to open directory.", 1, 180); -} diff --git a/frontend/menu/file_browser.h b/frontend/menu/file_browser.h index f3cf8c9be1..c64e92351c 100644 --- a/frontend/menu/file_browser.h +++ b/frontend/menu/file_browser.h @@ -35,21 +35,6 @@ typedef struct filebrowser_dir_type_t prev_dir; } filebrowser_t; -typedef enum -{ - FILEBROWSER_ACTION_UP, - FILEBROWSER_ACTION_DOWN, - FILEBROWSER_ACTION_LEFT, - FILEBROWSER_ACTION_RIGHT, - FILEBROWSER_ACTION_OK, - FILEBROWSER_ACTION_CANCEL, - FILEBROWSER_ACTION_SCROLL_UP, - FILEBROWSER_ACTION_SCROLL_DOWN, - FILEBROWSER_ACTION_RESET, - FILEBROWSER_ACTION_NOOP -} filebrowser_action_t; - -void filebrowser_update(void *data, uint64_t input, const char *extensions); void filebrowser_set_root_and_ext(void *data, const char *ext, const char *root_dir); bool filebrowser_iterate(void *data, unsigned action); void filebrowser_free(void *data); diff --git a/frontend/menu/menu_common.c b/frontend/menu/menu_common.c index 82f773ea29..8214de86fe 100644 --- a/frontend/menu/menu_common.c +++ b/frontend/menu/menu_common.c @@ -409,7 +409,7 @@ void menu_init(void) strlcpy(rgui->browser->current_dir.root_dir, g_settings.rgui_browser_directory, sizeof(rgui->browser->current_dir.root_dir)); - filebrowser_iterate(rgui->browser, FILEBROWSER_ACTION_RESET); + filebrowser_iterate(rgui->browser, RGUI_ACTION_START); #endif #ifdef HAVE_SHADER_MANAGER diff --git a/frontend/menu/rmenu.c b/frontend/menu/rmenu.c index 345b54ac0e..701a684005 100644 --- a/frontend/menu/rmenu.c +++ b/frontend/menu/rmenu.c @@ -246,7 +246,7 @@ static int select_file(void *data, uint64_t action) case RGUI_ACTION_OK: if (filebrowser_is_current_entry_dir(rgui->browser)) { - if (!filebrowser_iterate(rgui->browser, FILEBROWSER_ACTION_OK)) + if (!filebrowser_iterate(rgui->browser, RGUI_ACTION_OK)) { RARCH_ERR("Failed to open directory.\n"); msg_queue_push(g_extern.msg_queue, "ERROR - Failed to open directory.", 1, 180); @@ -379,7 +379,7 @@ static int select_directory(void *data, uint64_t action) case RGUI_ACTION_OK: #if 1 if (is_dir) - ret = filebrowser_iterate(rgui->browser, FILEBROWSER_ACTION_OK); + ret = filebrowser_iterate(rgui->browser, RGUI_ACTION_OK); #else /* TODO - extra conditional needed here to recognize if user pressed entry */ if (is_dir) @@ -1298,7 +1298,7 @@ static int ingame_menu_history_options(void *data, uint64_t action) else hist_opt_selected -= 5; break; - case FILEBROWSER_ACTION_RIGHT: + case RGUI_ACTION_RIGHT: hist_opt_selected = (min(hist_opt_selected + 5, rom_history_size(rgui->history)-1)); break; case RGUI_ACTION_CANCEL: @@ -1430,7 +1430,7 @@ static int rgui_iterate(void *data, unsigned action) } #endif - filebrowser_update(rgui->browser, action, rgui->browser->current_dir.extensions); + filebrowser_iterate(rgui->browser, action); int ret = -1; diff --git a/frontend/menu/rmenu_xui.cpp b/frontend/menu/rmenu_xui.cpp index 2bbd2e18cd..4c0a836ffe 100644 --- a/frontend/menu/rmenu_xui.cpp +++ b/frontend/menu/rmenu_xui.cpp @@ -229,7 +229,7 @@ static void menu_settings_create_menu_item_label_w(wchar_t *strwbuf, unsigned se void filebrowser_fetch_directory_entries(uint64_t action) { - filebrowser_update(rgui->browser, action, rgui->browser->current_dir.extensions); + filebrowser_iterate(rgui->browser, action); mbstowcs(strw_buffer, rgui->browser->current_dir.directory_path, sizeof(strw_buffer) / sizeof(wchar_t)); XuiTextElementSetText(m_menutitle, strw_buffer); @@ -255,7 +255,7 @@ HRESULT CRetroArchFileBrowser::OnInit(XUIMessageInit * pInitData, BOOL& bHandled filebrowser_set_root_and_ext(rgui->browser, rgui->info.valid_extensions, default_paths.filebrowser_startup_dir); - filebrowser_fetch_directory_entries(FILEBROWSER_ACTION_OK); + filebrowser_fetch_directory_entries(RGUI_ACTION_OK); return 0; } @@ -279,7 +279,7 @@ HRESULT CRetroArchFileBrowser::OnNotifyPress( HXUIOBJ hObjPressed, BOOL& bHandle { fill_pathname_join(path, rgui->browser->current_dir.directory_path, str_buffer, sizeof(path)); filebrowser_set_root_and_ext(rgui->browser, rgui->info.valid_extensions, path); - filebrowser_fetch_directory_entries(FILEBROWSER_ACTION_OK); + filebrowser_fetch_directory_entries(RGUI_ACTION_OK); } } @@ -1022,7 +1022,7 @@ HRESULT CRetroArchShaderBrowser::OnInit(XUIMessageInit * pInitData, BOOL& bHandl GetChildById(L"XuiTxtBottom", &m_menutitlebottom); filebrowser_set_root_and_ext(rgui->browser, "cg", "game:\\media\\shaders"); - filebrowser_fetch_directory_entries(FILEBROWSER_ACTION_OK); + filebrowser_fetch_directory_entries(RGUI_ACTION_OK); return 0; } @@ -1042,7 +1042,7 @@ HRESULT CRetroArchShaderBrowser::OnNotifyPress( HXUIOBJ hObjPressed, BOOL& bHand wcstombs(str_buffer, (const wchar_t *)XuiListGetText(m_menulist, index), sizeof(str_buffer)); fill_pathname_join(path, rgui->browser->current_dir.directory_path, str_buffer, sizeof(path)); filebrowser_set_root_and_ext(rgui->browser, "cg", path); - filebrowser_fetch_directory_entries(FILEBROWSER_ACTION_OK); + filebrowser_fetch_directory_entries(RGUI_ACTION_OK); } } @@ -1058,7 +1058,7 @@ HRESULT CRetroArchCoreBrowser::OnInit(XUIMessageInit * pInitData, BOOL& bHandled GetChildById(L"XuiTxtBottom", &m_menutitlebottom); filebrowser_set_root_and_ext(rgui->browser, "xex|XEX", "game:"); - filebrowser_fetch_directory_entries(FILEBROWSER_ACTION_OK); + filebrowser_fetch_directory_entries(RGUI_ACTION_OK); return 0; } @@ -1085,7 +1085,7 @@ HRESULT CRetroArchCoreBrowser::OnNotifyPress( HXUIOBJ hObjPressed, BOOL& bHandle { fill_pathname_join(path, rgui->browser->current_dir.directory_path, str_buffer, sizeof(path)); filebrowser_set_root_and_ext(rgui->browser, "xex|XEX", path); - filebrowser_fetch_directory_entries(FILEBROWSER_ACTION_OK); + filebrowser_fetch_directory_entries(RGUI_ACTION_OK); } }