diff --git a/source/modes/filebrowser.c b/source/modes/filebrowser.c index 0e9b271c4..8c83a8819 100644 --- a/source/modes/filebrowser.c +++ b/source/modes/filebrowser.c @@ -428,6 +428,12 @@ static ModeMode file_browser_mode_result(Mode *sw, int mretv, char **input, FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *)mode_get_private_data(sw); + /* bitwise-and allows for multiple MENU_ values to be stored in one + value, and then decoded out into seperate values within the relevant + mode file + e.g. mretv == MENU_CUSTOM_INPUT means selecting a directory, + mretv == MENU_CUSTOM_INPUT | MENU_CUSTOM_ACTION results in + going up to parent directory thanks to special_command bool */ gboolean special_command = ((mretv & MENU_CUSTOM_ACTION) == MENU_CUSTOM_ACTION); if (mretv & MENU_NEXT) { @@ -473,22 +479,36 @@ static ModeMode file_browser_mode_result(Mode *sw, int mretv, char **input, } } retv = RELOAD_DIALOG; - } else if ((mretv & MENU_CUSTOM_INPUT) && *input) { - char *p = rofi_expand_path(*input); - char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL); - g_free(p); - if (g_file_test(dir, G_FILE_TEST_EXISTS)) { - if (g_file_test(dir, G_FILE_TEST_IS_DIR)) { + } else if ((mretv & MENU_CUSTOM_INPUT)) { + // go up to parent directory + if (special_command) { + GFile *new = g_file_get_parent(pd->current_dir); + if (new) { g_object_unref(pd->current_dir); - pd->current_dir = g_file_new_for_path(dir); - g_free(dir); + pd->current_dir = new; free_list(pd); get_file_browser(sw); - return RESET_DIALOG; } + return RESET_DIALOG; + } + // else, if text field has valid pathname, select it + if (*input) { + char *p = rofi_expand_path(*input); + char *dir = g_filename_from_utf8(p, -1, NULL, NULL, NULL); + g_free(p); + if (g_file_test(dir, G_FILE_TEST_EXISTS)) { + if (g_file_test(dir, G_FILE_TEST_IS_DIR)) { + g_object_unref(pd->current_dir); + pd->current_dir = g_file_new_for_path(dir); + g_free(dir); + free_list(pd); + get_file_browser(sw); + return RESET_DIALOG; + } + } + g_free(dir); + retv = RELOAD_DIALOG; } - g_free(dir); - retv = RELOAD_DIALOG; } else if ((mretv & MENU_ENTRY_DELETE) == MENU_ENTRY_DELETE) { retv = RELOAD_DIALOG; } diff --git a/source/view.c b/source/view.c index ae707190e..d94658046 100644 --- a/source/view.c +++ b/source/view.c @@ -1510,7 +1510,6 @@ static void rofi_view_trigger_global_action(KeyBindingAction action) { // Nothing entered and nothing selected. state->retv = MENU_CUSTOM_INPUT; } - state->quit = TRUE; break; }