From bf5a89de022098b16d3ae8a567e6719c83d0bd24 Mon Sep 17 00:00:00 2001 From: ana-rchy Date: Thu, 26 May 2022 22:57:19 +0100 Subject: [PATCH 1/5] a --- include/keyb.h | 1 + source/keyb.c | 4 ++++ source/modes/filebrowser.c | 2 +- source/view.c | 7 +++++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/keyb.h b/include/keyb.h index ad34e5e5a..959a6c39b 100644 --- a/include/keyb.h +++ b/include/keyb.h @@ -109,6 +109,7 @@ typedef enum { ROW_LAST, ROW_SELECT, CANCEL, + PARENT_DIRECTORY, CUSTOM_1, CUSTOM_2, CUSTOM_3, diff --git a/source/keyb.c b/source/keyb.c index 34878ee0f..2deef35d0 100644 --- a/source/keyb.c +++ b/source/keyb.c @@ -204,6 +204,10 @@ ActionBindingEntry rofi_bindings[] = { .name = "kb-cancel", .binding = "Escape,Control+g,Control+bracketleft", .comment = "Quit rofi"}, + {.id = PARENT_DIRECTORY, + .name = "parent-directory-keybind", + .binding = "Control+Shift+z", + .comment = "Go to parent directory"}, {.id = CUSTOM_1, .name = "kb-custom-1", .binding = "Alt+1", diff --git a/source/modes/filebrowser.c b/source/modes/filebrowser.c index 0e9b271c4..b1e174d05 100644 --- a/source/modes/filebrowser.c +++ b/source/modes/filebrowser.c @@ -423,7 +423,7 @@ static unsigned int file_browser_mode_get_num_entries(const Mode *sw) { } static ModeMode file_browser_mode_result(Mode *sw, int mretv, char **input, - unsigned int selected_line) { + unsigned int selected_line, gboolean parent_bind) { ModeMode retv = MODE_EXIT; FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *)mode_get_private_data(sw); diff --git a/source/view.c b/source/view.c index ae707190e..865cdbf9d 100644 --- a/source/view.c +++ b/source/view.c @@ -1514,6 +1514,13 @@ static void rofi_view_trigger_global_action(KeyBindingAction action) { state->quit = TRUE; break; } + case PARENT_DIRECTORY: { + rofi_view_refilter_force(state); + state->selected_line = 1; + state->retv = MENU_OK; + state->quit = TRUE; + break; + } } } From d060ce25f1531ed322a4bd52cb450b1c252f8c5e Mon Sep 17 00:00:00 2001 From: ana-rchy Date: Thu, 26 May 2022 23:05:41 +0100 Subject: [PATCH 2/5] Added keybinding to go to parent directory [not working because skill issue] --- source/modes/filebrowser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/modes/filebrowser.c b/source/modes/filebrowser.c index b1e174d05..0e9b271c4 100644 --- a/source/modes/filebrowser.c +++ b/source/modes/filebrowser.c @@ -423,7 +423,7 @@ static unsigned int file_browser_mode_get_num_entries(const Mode *sw) { } static ModeMode file_browser_mode_result(Mode *sw, int mretv, char **input, - unsigned int selected_line, gboolean parent_bind) { + unsigned int selected_line) { ModeMode retv = MODE_EXIT; FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *)mode_get_private_data(sw); From 7d85115830a6d34a5c37622f402050828df9a622 Mon Sep 17 00:00:00 2001 From: ana-rchy Date: Sat, 28 May 2022 22:03:22 +0100 Subject: [PATCH 3/5] Added keybind to go to parent directory --- include/keyb.h | 1 - source/keyb.c | 4 ---- source/modes/filebrowser.c | 34 +++++++++++++++++++++++----------- source/view.c | 8 -------- 4 files changed, 23 insertions(+), 24 deletions(-) diff --git a/include/keyb.h b/include/keyb.h index 959a6c39b..ad34e5e5a 100644 --- a/include/keyb.h +++ b/include/keyb.h @@ -109,7 +109,6 @@ typedef enum { ROW_LAST, ROW_SELECT, CANCEL, - PARENT_DIRECTORY, CUSTOM_1, CUSTOM_2, CUSTOM_3, diff --git a/source/keyb.c b/source/keyb.c index 2deef35d0..34878ee0f 100644 --- a/source/keyb.c +++ b/source/keyb.c @@ -204,10 +204,6 @@ ActionBindingEntry rofi_bindings[] = { .name = "kb-cancel", .binding = "Escape,Control+g,Control+bracketleft", .comment = "Quit rofi"}, - {.id = PARENT_DIRECTORY, - .name = "parent-directory-keybind", - .binding = "Control+Shift+z", - .comment = "Go to parent directory"}, {.id = CUSTOM_1, .name = "kb-custom-1", .binding = "Alt+1", diff --git a/source/modes/filebrowser.c b/source/modes/filebrowser.c index 0e9b271c4..61237ec4a 100644 --- a/source/modes/filebrowser.c +++ b/source/modes/filebrowser.c @@ -473,22 +473,34 @@ 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) { + 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; + } + 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 865cdbf9d..d94658046 100644 --- a/source/view.c +++ b/source/view.c @@ -1510,14 +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; - } - case PARENT_DIRECTORY: { - rofi_view_refilter_force(state); - state->selected_line = 1; - state->retv = MENU_OK; state->quit = TRUE; break; } From f6521d5a1e0fe791e271fdb5e220cdc7b2f8206f Mon Sep 17 00:00:00 2001 From: ana-rchy Date: Sat, 28 May 2022 22:15:15 +0100 Subject: [PATCH 4/5] Added keybind to go to parent directory, added comments to clarify code --- source/modes/filebrowser.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/modes/filebrowser.c b/source/modes/filebrowser.c index 61237ec4a..24a6948da 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) { @@ -474,6 +480,7 @@ static ModeMode file_browser_mode_result(Mode *sw, int mretv, char **input, } retv = RELOAD_DIALOG; } 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) { @@ -484,6 +491,7 @@ static ModeMode file_browser_mode_result(Mode *sw, int mretv, char **input, } 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); From 3b2b169c1a3b47aee3eb5b9ac99dcafc0b6f013b Mon Sep 17 00:00:00 2001 From: ana-rchy Date: Sat, 28 May 2022 22:17:59 +0100 Subject: [PATCH 5/5] Added comments to clarify code --- source/modes/filebrowser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/modes/filebrowser.c b/source/modes/filebrowser.c index 24a6948da..8c83a8819 100644 --- a/source/modes/filebrowser.c +++ b/source/modes/filebrowser.c @@ -479,7 +479,7 @@ static ModeMode file_browser_mode_result(Mode *sw, int mretv, char **input, } } retv = RELOAD_DIALOG; - } else if (mretv & MENU_CUSTOM_INPUT) { + } else if ((mretv & MENU_CUSTOM_INPUT)) { // go up to parent directory if (special_command) { GFile *new = g_file_get_parent(pd->current_dir);