diff options
author | Dave Davenport <qball@gmpclient.org> | 2017-03-01 09:57:54 +0100 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2017-03-01 09:57:54 +0100 |
commit | 45c70cbecf980769ec5cda10e1186bf3d7dcb580 (patch) | |
tree | 6f226bd82cc54a4aad62a75048e8329510eb28b6 /source | |
parent | 8aac855fe045bc3e388dc888b01ed3438522f0f8 (diff) |
Allow modes to set message box, instead of view creation argument.
Diffstat (limited to 'source')
-rw-r--r-- | source/dialogs/dmenu.c | 11 | ||||
-rw-r--r-- | source/mode.c | 7 | ||||
-rw-r--r-- | source/rofi.c | 2 | ||||
-rw-r--r-- | source/view.c | 24 |
4 files changed, 37 insertions, 7 deletions
diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 6417e322..ea0880a2 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -470,6 +470,14 @@ static int dmenu_token_match ( const Mode *sw, GRegex **tokens, unsigned int ind DmenuModePrivateData *rmpd = (DmenuModePrivateData *) mode_get_private_data ( sw ); return helper_token_match ( tokens, rmpd->cmd_list[index] ); } +static char *dmenu_get_message ( const Mode *sw ) +{ + DmenuModePrivateData *pd = (DmenuModePrivateData *) mode_get_private_data ( sw ); + if ( pd->message ){ + return g_strdup ( pd->message ); + } + return NULL; +} #include "mode-private.h" /** dmenu Mode object. */ @@ -485,6 +493,7 @@ Mode dmenu_mode = ._get_display_value = get_display_data, ._get_completion = NULL, ._preprocess_input = NULL, + ._get_message = dmenu_get_message, .private_data = NULL, .free = NULL, .display_name = "dmenu:" @@ -697,7 +706,7 @@ int dmenu_switcher_dialog ( void ) return TRUE; } find_arg_str ( "-p", &( dmenu_mode.display_name ) ); - RofiViewState *state = rofi_view_create ( &dmenu_mode, input, pd->message, menu_flags, dmenu_finalize ); + RofiViewState *state = rofi_view_create ( &dmenu_mode, input, menu_flags, dmenu_finalize ); // @TODO we should do this better. if ( async ) { rofi_view_set_overlay ( state, "Loading.. " ); diff --git a/source/mode.c b/source/mode.c index 48cf9477..53daf88c 100644 --- a/source/mode.c +++ b/source/mode.c @@ -124,4 +124,11 @@ char * mode_preprocess_input ( Mode *mode, const char *input ) } return g_strdup ( input ); } +char *mode_get_message ( const Mode *mode ) +{ + if ( mode->_get_message ) { + return mode->_get_message ( mode ); + } + return NULL; +} /*@}*/ diff --git a/source/rofi.c b/source/rofi.c index 901b3eb0..c933a742 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -196,7 +196,7 @@ static void run_switcher ( ModeMode mode ) return; } curr_switcher = mode; - RofiViewState * state = rofi_view_create ( modi[mode], config.filter, NULL, MENU_PROMPT_COLON, process_result ); + RofiViewState * state = rofi_view_create ( modi[mode], config.filter, MENU_PROMPT_COLON, process_result ); if ( state ) { rofi_view_set_active ( state ); } diff --git a/source/view.c b/source/view.c index 7fd03485..9d92ae57 100644 --- a/source/view.c +++ b/source/view.c @@ -374,6 +374,22 @@ static void rofi_view_window_update_size ( RofiViewState * state ) widget_resize ( WIDGET ( state->main_window ), state->width, state->height ); } + +static void rofi_view_reload_message_bar ( RofiViewState *state ) +{ + if ( state->mesg_box == NULL ){ + return ; + } + char *msg = mode_get_message ( state->sw ); + if ( msg ) { + textbox_text ( state->mesg_tb, msg ); + widget_enable ( WIDGET (state->mesg_box ) ); + g_free ( msg ); + } else { + widget_disable ( WIDGET (state->mesg_box ) ); + } +} + static gboolean rofi_view_reload_idle ( G_GNUC_UNUSED gpointer data ) { if ( current_active_menu ) { @@ -1002,6 +1018,7 @@ static void _rofi_view_reload_row ( RofiViewState *state ) state->line_map = g_malloc0_n ( state->num_lines, sizeof ( unsigned int ) ); state->distance = g_malloc0_n ( state->num_lines, sizeof ( int ) ); listview_set_max_lines ( state->list_view, state->num_lines ); + rofi_view_reload_message_bar ( state ); } static void rofi_view_refilter ( RofiViewState *state ) @@ -1524,7 +1541,6 @@ static void rofi_view_listview_mouse_activated_cb ( listview *lv, xcb_button_pre RofiViewState *rofi_view_create ( Mode *sw, const char *input, - const char *message, MenuFlags menu_flags, void ( *finalize )( RofiViewState * ) ) { @@ -1593,11 +1609,9 @@ RofiViewState *rofi_view_create ( Mode *sw, textbox_text ( state->case_indicator, get_matching_state () ); state->mesg_box = container_create ( "window.mainbox.message.box" ); - state->mesg_tb = textbox_create ( "window.mainbox.message.textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, message ); + state->mesg_tb = textbox_create ( "window.mainbox.message.textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, NORMAL, NULL ); container_add ( state->mesg_box, WIDGET ( state->mesg_tb ) ); - if ( message == NULL ) { - widget_disable ( WIDGET( state->mesg_box ) ); - } + rofi_view_reload_message_bar ( state ); box_add ( state->main_box, WIDGET ( state->mesg_box ), FALSE, end ? 8 : 2 ); state->overlay = textbox_create ( "window.overlay", TB_AUTOWIDTH | TB_AUTOHEIGHT, URGENT, "blaat" ); |