From 5a29565fc88e350019a8159ae054a4c36b407983 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Fri, 6 Jan 2023 11:54:43 +0100 Subject: [PATCH] [filebrowser] Add option to return 1 on cancel. Fixes: #1732 --- doc/rofi.1 | 14 ++++++++++++++ doc/rofi.1.markdown | 8 ++++++++ source/modes/filebrowser.c | 13 +++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/doc/rofi.1 b/doc/rofi.1 index d99e8f26..bf050441 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -1155,12 +1155,26 @@ configuration { directories-first: true; /** Show hidden files. */ show-hidden: false; + /** return 1 on cancel. */ + cancel-returns-1: true; } } .fi .RE +.PP +These options can also be passed on the commandline, for example: + +.PP +.RS + +.nf +rofi -filebrowser-cancel-returns-1 true -show filebrowser + +.fi +.RE + .PP The \fB\fCshow-hidden\fR can also be triggered with the \fB\fCkb-delete-entry\fR keybinding. diff --git a/doc/rofi.1.markdown b/doc/rofi.1.markdown index dc1bde35..50838919 100644 --- a/doc/rofi.1.markdown +++ b/doc/rofi.1.markdown @@ -710,10 +710,18 @@ configuration { directories-first: true; /** Show hidden files. */ show-hidden: false; + /** return 1 on cancel. */ + cancel-returns-1: true; } } ``` +These options can also be passed on the commandline, for example: + +```bash +rofi -filebrowser-cancel-returns-1 true -show filebrowser +``` + The `show-hidden` can also be triggered with the `kb-delete-entry` keybinding. ### Other diff --git a/source/modes/filebrowser.c b/source/modes/filebrowser.c index df3c8c12..9095fc71 100644 --- a/source/modes/filebrowser.c +++ b/source/modes/filebrowser.c @@ -374,12 +374,12 @@ static void file_browser_mode_init_config(Mode *sw) { if (p != NULL && p->type == P_BOOLEAN) { file_browser_config.directories_first = p->value.b; } - + p = rofi_theme_find_property(wid, P_BOOLEAN, "show-hidden", TRUE); if (p != NULL && p->type == P_BOOLEAN) { file_browser_config.show_hidden = p->value.b; } - + if (found_error) { rofi_view_error_dialog(msg, FALSE); @@ -450,6 +450,15 @@ static ModeMode file_browser_mode_result(Mode *sw, int mretv, char **input, FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *)mode_get_private_data(sw); + if ((mretv & MENU_CANCEL) == MENU_CANCEL) { + ThemeWidget *wid = rofi_config_find_widget(sw->name, NULL, TRUE); + Property *p = + rofi_theme_find_property(wid, P_BOOLEAN, "cancel-returns-1", TRUE); + if (p && p->type == P_BOOLEAN && p->value.b == TRUE) { + rofi_set_return_code(1); + } + return MODE_EXIT; + } gboolean special_command = ((mretv & MENU_CUSTOM_ACTION) == MENU_CUSTOM_ACTION); if (mretv & MENU_NEXT) {