Implement toggle to open the start directory at the last used location

This commit is contained in:
ImJezze 2021-02-07 11:45:16 +01:00
parent a1b4cced5b
commit 270c41b35a
20 changed files with 217 additions and 8 deletions

View File

@ -388,6 +388,9 @@
#define DEFAULT_SHOW_HIDDEN_FILES false
/* Initialise file browser with the last used start directory */
#define DEFAULT_USE_LAST_START_DIRECTORY false
#define DEFAULT_OVERLAY_HIDE_IN_MENU true
/* Automatically disable overlays when a

View File

@ -1717,6 +1717,7 @@ static struct config_bool_setting *populate_settings_bool(
SETTING_BOOL("sort_screenshots_by_content_enable", &settings->bools.sort_screenshots_by_content_enable, true, default_sort_screenshots_by_content_enable, false);
SETTING_BOOL("config_save_on_exit", &settings->bools.config_save_on_exit, true, DEFAULT_CONFIG_SAVE_ON_EXIT, false);
SETTING_BOOL("show_hidden_files", &settings->bools.show_hidden_files, true, DEFAULT_SHOW_HIDDEN_FILES, false);
SETTING_BOOL("use_last_start_directory", &settings->bools.use_last_start_directory, true, DEFAULT_USE_LAST_START_DIRECTORY, false);
SETTING_BOOL("input_autodetect_enable", &settings->bools.input_autodetect_enable, true, input_autodetect_enable, false);
#if defined(HAVE_DINPUT) || defined(HAVE_WINRAWINPUT)
SETTING_BOOL("input_nowinkey_enable", &settings->bools.input_nowinkey_enable, true, false, false);

View File

@ -768,6 +768,7 @@ typedef struct settings
bool sort_screenshots_by_content_enable;
bool config_save_on_exit;
bool show_hidden_files;
bool use_last_start_directory;
bool savefiles_in_content_dir;
bool savestates_in_content_dir;

View File

@ -2704,6 +2704,10 @@ MSG_HASH(
MENU_ENUM_LABEL_SHOW_HIDDEN_FILES,
"show_hidden_files"
)
MSG_HASH(
MENU_ENUM_LABEL_USE_LAST_START_DIRECTORY,
"use_last_start_directory"
)
MSG_HASH(
MENU_ENUM_LABEL_SHUTDOWN,
"shutdown"

View File

@ -3138,6 +3138,14 @@ MSG_HASH(
MENU_ENUM_LABEL_VALUE_FILTER_BY_CURRENT_CORE,
"Filter by Current Core"
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_USE_LAST_START_DIRECTORY,
"Remember Last Used Start Directory"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_USE_LAST_START_DIRECTORY,
"Open the file browser at the last used location when loading content from the Start Directory. Note: Location will be reset to default upon restarting RetroArch."
)
/* Settings > Frame Throttle */

View File

@ -1063,6 +1063,7 @@ static int menu_cbs_init_bind_left_compare_type(menu_file_list_cbs_t *cbs,
case FILE_TYPE_FONT:
case MENU_SETTING_GROUP:
case MENU_SETTINGS_CORE_INFO_NONE:
case MENU_SETTING_ACTION_FAVORITES_DIR:
if (
string_ends_with_size(menu_label, "_tab",
strlen(menu_label), STRLEN_CONST("_tab"))

View File

@ -219,7 +219,6 @@ static int (funcname)(const char *path, const char *label, unsigned type, size_t
return generic_action_ok_displaylist_push(path, _path, label, type, idx, entry_idx, _id); \
}
#define DEFAULT_ACTION_OK_HELP(funcname, _id, _id2) \
static int (funcname)(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) \
{ \
@ -834,6 +833,16 @@ int generic_action_ok_displaylist_push(const char *path,
info_path = new_path;
info_label = label;
dl_type = DISPLAYLIST_GENERIC;
/* If this is the 'Start Directory' content
* list, use last selected directory/file */
if ((type == MENU_SETTING_ACTION_FAVORITES_DIR) &&
settings->bools.use_last_start_directory)
{
info_path = menu_driver_get_last_start_directory();
menu_driver_set_pending_selection(menu_driver_get_last_start_file_name());
}
break;
case ACTION_OK_DL_SCAN_DIR_LIST:
filebrowser_set_type(FILEBROWSER_SCAN_DIR);
@ -1533,6 +1542,7 @@ static int file_load_with_detect_core_wrapper(
return -1;
content_add_to_playlist(def_info.s);
menu_driver_set_last_start_content(def_info.s);
ret = 0;
break;
@ -1917,6 +1927,7 @@ static int default_action_ok_load_content_with_core_from_menu(const char *_path,
(enum rarch_core_type)_type, NULL, NULL))
return -1;
content_add_to_playlist(_path);
menu_driver_set_last_start_content(_path);
return 0;
}
@ -3505,6 +3516,7 @@ static int action_ok_load_core_deferred(const char *path,
NULL, NULL))
return -1;
content_add_to_playlist(path);
menu_driver_set_last_start_content(path);
return 0;
}
@ -4012,6 +4024,7 @@ static int action_ok_file_load_detect_core(const char *path,
NULL, NULL))
return -1;
content_add_to_playlist(menu->detect_content_path);
menu_driver_set_last_start_content(menu->detect_content_path);
return 0;
}
@ -5411,7 +5424,7 @@ static int action_ok_open_picker(const char *path,
ret = generic_action_ok_displaylist_push(path, new_path,
msg_hash_to_str(MENU_ENUM_LABEL_FAVORITES),
type, idx,
MENU_SETTING_ACTION_FAVORITES_DIR, idx,
entry_idx, ACTION_OK_DL_CONTENT_LIST);
free(new_path);
@ -6400,6 +6413,8 @@ static int action_ok_load_archive_detect_core(const char *path,
CORE_TYPE_PLAIN,
NULL, NULL))
ret = -1;
else
menu_driver_set_last_start_content(def_info.s);
}
break;
case 0:

View File

@ -908,6 +908,7 @@ static int menu_cbs_init_bind_right_compare_type(menu_file_list_cbs_t *cbs,
case FILE_TYPE_FONT:
case MENU_SETTING_GROUP:
case MENU_SETTINGS_CORE_INFO_NONE:
case MENU_SETTING_ACTION_FAVORITES_DIR:
if (
string_ends_with_size(menu_label, "_tab",
strlen(menu_label), STRLEN_CONST("_tab"))

View File

@ -653,6 +653,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_playlist_entry_rename,
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_playlist_entry_remove, MENU_ENUM_SUBLABEL_PLAYLIST_ENTRY_REMOVE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_system_directory, MENU_ENUM_SUBLABEL_SYSTEM_DIRECTORY)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_rgui_browser_directory, MENU_ENUM_SUBLABEL_RGUI_BROWSER_DIRECTORY)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_use_last_start_directory, MENU_ENUM_SUBLABEL_USE_LAST_START_DIRECTORY)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_content_dir, MENU_ENUM_SUBLABEL_CONTENT_DIR)
DEFAULT_SUBLABEL_MACRO(action_bind_dynamic_wallpapers_directory, MENU_ENUM_SUBLABEL_DYNAMIC_WALLPAPERS_DIRECTORY)
DEFAULT_SUBLABEL_MACRO(action_bind_thumbnails_directory, MENU_ENUM_SUBLABEL_THUMBNAILS_DIRECTORY)
@ -3480,6 +3481,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_SHOW_HIDDEN_FILES:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_show_hidden_files);
break;
case MENU_ENUM_LABEL_USE_LAST_START_DIRECTORY:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_use_last_start_directory);
break;
case MENU_ENUM_LABEL_INPUT_MENU_ENUM_TOGGLE_GAMEPAD_COMBO:
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_toggle_gamepad_combo);
break;

View File

@ -638,6 +638,7 @@ DEFAULT_FILL_TITLE_MACRO(action_get_title_autoconfig_directory, MENU_ENUM_LABEL
DEFAULT_FILL_TITLE_MACRO(action_get_title_playlist_directory, MENU_ENUM_LABEL_VALUE_PLAYLIST_DIRECTORY)
DEFAULT_FILL_TITLE_MACRO(action_get_title_runtime_log_directory, MENU_ENUM_LABEL_VALUE_RUNTIME_LOG_DIRECTORY)
DEFAULT_FILL_TITLE_MACRO(action_get_title_browser_directory, MENU_ENUM_LABEL_VALUE_RGUI_BROWSER_DIRECTORY)
DEFAULT_FILL_TITLE_MACRO(action_get_title_use_last_start_directory, MENU_ENUM_LABEL_VALUE_USE_LAST_START_DIRECTORY)
DEFAULT_FILL_TITLE_MACRO(action_get_title_content_directory, MENU_ENUM_LABEL_VALUE_CONTENT_DIR)
DEFAULT_FILL_TITLE_MACRO(action_get_title_screenshot_directory, MENU_ENUM_LABEL_VALUE_SCREENSHOT_DIRECTORY)
DEFAULT_FILL_TITLE_MACRO(action_get_title_cursor_directory, MENU_ENUM_LABEL_VALUE_CURSOR_DIRECTORY)
@ -973,6 +974,8 @@ static int menu_cbs_init_bind_title_compare_label(menu_file_list_cbs_t *cbs,
#endif
{MENU_ENUM_LABEL_RGUI_BROWSER_DIRECTORY,
action_get_title_browser_directory},
{MENU_ENUM_LABEL_USE_LAST_START_DIRECTORY,
action_get_title_use_last_start_directory},
{MENU_ENUM_LABEL_PLAYLIST_DIRECTORY,
action_get_title_playlist_directory},
{MENU_ENUM_LABEL_RUNTIME_LOG_DIRECTORY,
@ -1238,6 +1241,9 @@ static int menu_cbs_init_bind_title_compare_label(menu_file_list_cbs_t *cbs,
case MENU_ENUM_LABEL_RGUI_BROWSER_DIRECTORY:
BIND_ACTION_GET_TITLE(cbs, action_get_title_browser_directory);
break;
case MENU_ENUM_LABEL_USE_LAST_START_DIRECTORY:
BIND_ACTION_GET_TITLE(cbs, action_get_title_use_last_start_directory);
break;
case MENU_ENUM_LABEL_PLAYLIST_DIRECTORY:
BIND_ACTION_GET_TITLE(cbs, action_get_title_playlist_directory);
break;

View File

@ -8868,7 +8868,7 @@ static int materialui_list_push(void *data, void *userdata,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_FAVORITES),
msg_hash_to_str(MENU_ENUM_LABEL_FAVORITES),
MENU_ENUM_LABEL_FAVORITES,
MENU_SETTING_ACTION, 0, 0);
MENU_SETTING_ACTION_FAVORITES_DIR, 0, 0);
core_info_get_list(&list);
if (core_info_list_num_info_files(list))

View File

@ -1442,7 +1442,7 @@ static int ozone_list_push(void *data, void *userdata,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_FAVORITES),
msg_hash_to_str(MENU_ENUM_LABEL_FAVORITES),
MENU_ENUM_LABEL_FAVORITES,
MENU_SETTING_ACTION, 0, 0);
MENU_SETTING_ACTION_FAVORITES_DIR, 0, 0);
core_info_get_list(&list);
if (core_info_list_num_info_files(list))

View File

@ -4152,7 +4152,7 @@ static int stripes_list_push(void *data, void *userdata,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_FAVORITES),
msg_hash_to_str(MENU_ENUM_LABEL_FAVORITES),
MENU_ENUM_LABEL_FAVORITES,
MENU_SETTING_ACTION, 0, 0);
MENU_SETTING_ACTION_FAVORITES_DIR, 0, 0);
core_info_get_list(&list);
if (core_info_list_num_info_files(list))

View File

@ -6702,7 +6702,7 @@ static int xmb_list_push(void *data, void *userdata,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_FAVORITES),
msg_hash_to_str(MENU_ENUM_LABEL_FAVORITES),
MENU_ENUM_LABEL_FAVORITES,
MENU_SETTING_ACTION, 0, 0);
MENU_SETTING_ACTION_FAVORITES_DIR, 0, 0);
core_info_get_list(&list);
if (core_info_list_num_info_files(list))

View File

@ -5851,7 +5851,7 @@ unsigned menu_displaylist_build_list(
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_FAVORITES),
msg_hash_to_str(MENU_ENUM_LABEL_FAVORITES),
MENU_ENUM_LABEL_FAVORITES,
MENU_SETTING_ACTION, 0, 0))
MENU_SETTING_ACTION_FAVORITES_DIR, 0, 0))
count++;
#if defined(HAVE_LIBRETRODB)
@ -7589,6 +7589,7 @@ unsigned menu_displaylist_build_list(
{MENU_ENUM_LABEL_USE_BUILTIN_PLAYER, PARSE_ONLY_BOOL},
{MENU_ENUM_LABEL_USE_BUILTIN_IMAGE_VIEWER, PARSE_ONLY_BOOL},
{MENU_ENUM_LABEL_FILTER_BY_CURRENT_CORE, PARSE_ONLY_BOOL},
{MENU_ENUM_LABEL_USE_LAST_START_DIRECTORY, PARSE_ONLY_BOOL},
};
for (i = 0; i < ARRAY_SIZE(build_list); i++)
@ -12970,6 +12971,7 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
else
{
settings_t *settings = config_get_ptr();
const char *pending_selection = menu_driver_get_pending_selection();
bool show_hidden_files = settings->bools.show_hidden_files;
bool multimedia_builtin_mediaplayer_enable = settings->bools.multimedia_builtin_mediaplayer_enable;
bool multimedia_builtin_imageviewer_enable = settings->bools.multimedia_builtin_imageviewer_enable;
@ -12981,6 +12983,22 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type,
multimedia_builtin_imageviewer_enable,
menu_navigation_browser_filter_supported_extensions_enable
);
/* Apply pending selection */
if (!string_is_empty(pending_selection))
{
size_t selection_idx = 0;
file_list_t *selection_buf = menu_entries_get_selection_buf_ptr(0);
if (selection_buf &&
file_list_search(selection_buf, pending_selection, &selection_idx))
{
menu_navigation_set_selection(selection_idx);
menu_driver_navigation_set(true);
}
menu_driver_set_pending_selection(NULL);
}
}
info->need_refresh = true;

View File

@ -114,6 +114,7 @@ enum menu_settings_type
MENU_SETTING_ACTION_RESET,
MENU_SETTING_ACTION_CORE_LOCK,
MENU_SETTING_ACTION_CORE_DELETE,
MENU_SETTING_ACTION_FAVORITES_DIR, /* "Start Directory" */
MENU_SETTING_STRING_OPTIONS,
MENU_SETTING_GROUP,
MENU_SETTING_SUBGROUP,
@ -346,6 +347,14 @@ typedef struct
char pass_dir[PATH_MAX_LENGTH];
} last_shader_selection;
/* Used to cache the last start content
* loaded via the menu file browser */
struct
{
char directory[PATH_MAX_LENGTH];
char file_name[PATH_MAX_LENGTH];
} last_start_content;
char menu_state_msg[8192];
/* Scratchpad variables. These are used for instance
* by the filebrowser when having to store intermediary
@ -525,6 +534,12 @@ const char *menu_driver_get_last_shader_preset_dir(void);
const char *menu_driver_get_last_shader_pass_dir(void);
#endif
const char *menu_driver_get_last_start_directory(void);
const char *menu_driver_get_last_start_file_name(void);
void menu_driver_set_last_start_content(const char *start_content_path);
const char *menu_driver_get_pending_selection();
void menu_driver_set_pending_selection(const char *pending_selection);
menu_handle_t *menu_driver_get_ptr(void);
enum action_iterate_type

View File

@ -15664,6 +15664,21 @@ static bool setting_append_list(
general_read_handler,
SD_FLAG_NONE);
CONFIG_BOOL(
list, list_info,
&settings->bools.use_last_start_directory,
MENU_ENUM_LABEL_USE_LAST_START_DIRECTORY,
MENU_ENUM_LABEL_VALUE_USE_LAST_START_DIRECTORY,
false,
MENU_ENUM_LABEL_VALUE_OFF,
MENU_ENUM_LABEL_VALUE_ON,
&group_info,
&subgroup_info,
parent_group,
general_write_handler,
general_read_handler,
SD_FLAG_NONE);
END_SUB_GROUP(list, list_info, parent_group);
END_GROUP(list, list_info, parent_group);
break;

View File

@ -1859,6 +1859,7 @@ enum msg_hash_enums
MENU_LABEL(CONFIGURATION_LIST),
MENU_LABEL(CONFIRM_ON_EXIT),
MENU_LABEL(SHOW_HIDDEN_FILES),
MENU_LABEL(USE_LAST_START_DIRECTORY),
/* Driver settings */

View File

@ -4532,7 +4532,6 @@ static const char *menu_driver_get_last_shader_dir_int(
return shader_dir;
}
const char *menu_driver_get_last_shader_preset_dir(void)
{
struct rarch_state *p_rarch = &rarch_st;
@ -4567,6 +4566,118 @@ const char *menu_driver_get_last_shader_pass_dir(void)
#endif
const char *menu_driver_get_last_start_directory(void)
{
struct rarch_state *p_rarch = &rarch_st;
menu_handle_t *menu = p_rarch->menu_driver_data;
settings_t *settings = p_rarch->configuration_settings;
bool use_last = settings->bools.use_last_start_directory;
const char *default_directory = settings->paths.directory_menu_content;
/* Return default directory if there is no
* last directory or it's invalid */
if (!menu ||
!use_last ||
string_is_empty(menu->last_start_content.directory) ||
!path_is_directory(menu->last_start_content.directory))
return default_directory;
return menu->last_start_content.directory;
}
const char *menu_driver_get_last_start_file_name(void)
{
struct rarch_state *p_rarch = &rarch_st;
menu_handle_t *menu = p_rarch->menu_driver_data;
settings_t *settings = p_rarch->configuration_settings;
bool use_last = settings->bools.use_last_start_directory;
/* Return NULL if there is no last 'file name' */
if (!menu ||
!use_last ||
string_is_empty(menu->last_start_content.file_name))
return NULL;
return menu->last_start_content.file_name;
}
void menu_driver_set_last_start_content(const char *start_content_path)
{
struct rarch_state *p_rarch = &rarch_st;
menu_handle_t *menu = p_rarch->menu_driver_data;
settings_t *settings = p_rarch->configuration_settings;
bool use_last = settings->bools.use_last_start_directory;
const char *archive_delim = NULL;
const char *file_name = NULL;
char archive_path[PATH_MAX_LENGTH];
if (!menu)
return;
/* Reset existing cache */
menu->last_start_content.directory[0] = '\0';
menu->last_start_content.file_name[0] = '\0';
/* If 'use_last_start_directory' is disabled or
* path is empty, do nothing */
if (!use_last ||
string_is_empty(start_content_path))
return;
/* Cache directory */
fill_pathname_parent_dir(menu->last_start_content.directory,
start_content_path, sizeof(menu->last_start_content.directory));
/* Cache file name */
archive_delim = path_get_archive_delim(start_content_path);
if (archive_delim)
{
/* If path references a file inside an
* archive, must extract the string segment
* before the archive delimiter (i.e. path of
* 'parent' archive file) */
size_t len;
archive_path[0] = '\0';
len = (size_t)(1 + archive_delim - start_content_path);
len = (len < PATH_MAX_LENGTH) ? len : PATH_MAX_LENGTH;
strlcpy(archive_path, start_content_path, len * sizeof(char));
file_name = path_basename(archive_path);
}
else
file_name = path_basename(start_content_path);
if (!string_is_empty(file_name))
strlcpy(menu->last_start_content.file_name, file_name,
sizeof(menu->last_start_content.file_name));
}
const char *menu_driver_get_pending_selection()
{
struct rarch_state *p_rarch = &rarch_st;
struct menu_state *menu_st = &p_rarch->menu_driver_state;
return menu_st->pending_selection;
}
void menu_driver_set_pending_selection(const char *pending_selection)
{
struct rarch_state *p_rarch = &rarch_st;
struct menu_state *menu_st = &p_rarch->menu_driver_state;
char *selection = menu_st->pending_selection;
/* Reset existing cache */
selection[0] = '\0';
/* If path is empty, do nothing */
if (string_is_empty(pending_selection))
return;
strlcpy(selection, pending_selection,
sizeof(menu_st->pending_selection));
}
bool menu_driver_ctl(enum rarch_menu_ctl_state state, void *data)
{
struct rarch_state *p_rarch = &rarch_st;

View File

@ -1591,6 +1591,11 @@ struct menu_state
* representation string */
char datetime_cache[255];
/* When generating a menu list in menu_displaylist_build_list(),
* the entry with a label matching 'pending_selection' will
* be selected automatically */
char pending_selection[PATH_MAX_LENGTH];
/* when enabled, on next iteration the 'Quick Menu' list will
* be pushed onto the stack */
bool pending_quick_menu;