diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-01-20 18:50:33 +0100 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-01-20 18:50:33 +0100 |
commit | eadf455c8c4d74a9b66a47ad97de274fb3d16241 (patch) | |
tree | fd93ff968c83f1aa870c9cf6b97dfa4f7be278b2 /source | |
parent | 74de448ea9fce08d3a9ba7c3f528cdf2f01d1bf8 (diff) |
Let DMenu mode reuse open dialog and not restart it. handy for multi-select.
Diffstat (limited to 'source')
-rw-r--r-- | source/dialogs/dmenu.c | 6 | ||||
-rw-r--r-- | source/rofi.c | 43 |
2 files changed, 24 insertions, 25 deletions
diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index ecb12fa2..37749b67 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -398,9 +398,11 @@ int dmenu_switcher_dialog ( void ) return TRUE; } + MenuState *state = menu ( &dmenu_mode, input, pd->prompt, pd->message, menu_flags ); do { + menu_state_restart ( state ); + menu_state_set_selected_line ( state, pd->selected_line ); retv = FALSE; - MenuState *state = menu ( &dmenu_mode, input, pd->prompt, ( pd->selected_line ), pd->message, menu_flags ); // Enter main loop. while ( !menu_state_get_completed ( state ) ) { @@ -416,7 +418,6 @@ int dmenu_switcher_dialog ( void ) pd->selected_line = menu_state_get_selected_line ( state );; MenuReturn mretv = menu_state_get_return_value ( state ); unsigned int next_pos = menu_state_get_next_position ( state ); - menu_state_free ( state ); // Special behavior. // TODO clean this up! @@ -494,6 +495,7 @@ int dmenu_switcher_dialog ( void ) } } while ( restart ); + menu_state_free ( state ); g_free ( input ); mode_destroy ( &dmenu_mode ); return retv; diff --git a/source/rofi.c b/source/rofi.c index 58396c64..546f6c97 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -235,7 +235,25 @@ static MenuState *menu_state_create ( void ) { return g_malloc0 ( sizeof ( MenuState ) ); } +void menu_state_restart ( MenuState *state ) +{ + state->quit = FALSE; + state->retv = MENU_CANCEL; +} +void menu_state_set_selected_line ( MenuState *state, unsigned int selected_line ) +{ + state->selected_line = selected_line; + // Find the line. + state->selected = 0; + for ( unsigned int i = 0; ( ( state->selected_line ) ) < UINT32_MAX && !state->selected && i < state->filtered_lines; i++ ) { + if ( state->line_map[i] == ( state->selected_line ) ) { + state->selected = i; + break; + } + } + state->update = TRUE; +} void menu_state_free ( MenuState *state ) { // Do this here? @@ -1457,14 +1475,13 @@ static void menu_mainloop_iter ( MenuState *state, XEvent *ev ) MenuState *menu ( Mode *sw, char *input, char *prompt, - unsigned int selected_line, const char *message, MenuFlags menu_flags ) { TICK (); MenuState *state = menu_state_create (); state->sw = sw; - state->selected_line = selected_line; + state->selected_line = UINT32_MAX; state->retv = MENU_CANCEL; state->distance = NULL; state->quit = FALSE; @@ -1656,31 +1673,11 @@ MenuState *menu ( Mode *sw, state->update = TRUE; menu_refilter ( state ); - for ( unsigned int i = 0; ( ( state->selected_line ) ) < UINT32_MAX && !state->selected && i < state->filtered_lines; i++ ) { - if ( state->line_map[i] == ( state->selected_line ) ) { - state->selected = i; - break; - } - } - menu_update ( state ); if ( sncontext != NULL ) { sn_launchee_context_complete ( sncontext ); } return state; -/* - if ( next_pos ) { - if ( ( state->selected + 1 ) < state->num_lines ) { - *( next_pos ) = state->line_map[state->selected + 1]; - } - } - - int retv = state->retv; - menu_state_free ( state ); - - - return retv; - */ } void error_dialog ( const char *msg, int markup ) @@ -2268,7 +2265,7 @@ static int main_loop_signal_handler ( char command, int quiet ) ModeMode switcher_run ( char **input, Mode *sw ) { char *prompt = g_strdup_printf ( "%s:", mode_get_name ( sw ) ); - MenuState * state = menu ( sw, *input, prompt, UINT32_MAX, NULL, MENU_NORMAL ); + MenuState * state = menu ( sw, *input, prompt, NULL, MENU_NORMAL ); g_free ( prompt ); g_return_val_if_fail ( state != NULL, MODE_EXIT ); |