mirror of
https://github.com/davatorium/rofi.git
synced 2025-02-03 15:34:54 -05:00
Let DMenu mode reuse open dialog and not restart it. handy for multi-select.
This commit is contained in:
parent
74de448ea9
commit
eadf455c8c
3 changed files with 26 additions and 26 deletions
|
@ -52,7 +52,6 @@ typedef enum
|
||||||
*/
|
*/
|
||||||
MenuState *menu ( Mode *sw,
|
MenuState *menu ( Mode *sw,
|
||||||
char *input, char *prompt,
|
char *input, char *prompt,
|
||||||
unsigned int selected_line,
|
|
||||||
const char *message, MenuFlags flags )
|
const char *message, MenuFlags flags )
|
||||||
__attribute__ ( ( nonnull ( 1, 2, 3 ) ) );
|
__attribute__ ( ( nonnull ( 1, 2, 3 ) ) );
|
||||||
|
|
||||||
|
@ -92,5 +91,7 @@ void menu_state_itterrate ( MenuState *state, XEvent *event );
|
||||||
unsigned int menu_state_get_completed ( const MenuState *state );
|
unsigned int menu_state_get_completed ( const MenuState *state );
|
||||||
const char * menu_state_get_user_input ( const MenuState *state );
|
const char * menu_state_get_user_input ( const MenuState *state );
|
||||||
void menu_state_free ( MenuState *state );
|
void menu_state_free ( MenuState *state );
|
||||||
|
void menu_state_restart ( MenuState *state );
|
||||||
|
void menu_state_set_selected_line ( MenuState *state, unsigned int selected_line );
|
||||||
/*@}*/
|
/*@}*/
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -398,9 +398,11 @@ int dmenu_switcher_dialog ( void )
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MenuState *state = menu ( &dmenu_mode, input, pd->prompt, pd->message, menu_flags );
|
||||||
do {
|
do {
|
||||||
|
menu_state_restart ( state );
|
||||||
|
menu_state_set_selected_line ( state, pd->selected_line );
|
||||||
retv = FALSE;
|
retv = FALSE;
|
||||||
MenuState *state = menu ( &dmenu_mode, input, pd->prompt, ( pd->selected_line ), pd->message, menu_flags );
|
|
||||||
|
|
||||||
// Enter main loop.
|
// Enter main loop.
|
||||||
while ( !menu_state_get_completed ( state ) ) {
|
while ( !menu_state_get_completed ( state ) ) {
|
||||||
|
@ -416,7 +418,6 @@ int dmenu_switcher_dialog ( void )
|
||||||
pd->selected_line = menu_state_get_selected_line ( state );;
|
pd->selected_line = menu_state_get_selected_line ( state );;
|
||||||
MenuReturn mretv = menu_state_get_return_value ( state );
|
MenuReturn mretv = menu_state_get_return_value ( state );
|
||||||
unsigned int next_pos = menu_state_get_next_position ( state );
|
unsigned int next_pos = menu_state_get_next_position ( state );
|
||||||
menu_state_free ( state );
|
|
||||||
|
|
||||||
// Special behavior.
|
// Special behavior.
|
||||||
// TODO clean this up!
|
// TODO clean this up!
|
||||||
|
@ -494,6 +495,7 @@ int dmenu_switcher_dialog ( void )
|
||||||
}
|
}
|
||||||
} while ( restart );
|
} while ( restart );
|
||||||
|
|
||||||
|
menu_state_free ( state );
|
||||||
g_free ( input );
|
g_free ( input );
|
||||||
mode_destroy ( &dmenu_mode );
|
mode_destroy ( &dmenu_mode );
|
||||||
return retv;
|
return retv;
|
||||||
|
|
|
@ -235,7 +235,25 @@ static MenuState *menu_state_create ( void )
|
||||||
{
|
{
|
||||||
return g_malloc0 ( sizeof ( MenuState ) );
|
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 )
|
void menu_state_free ( MenuState *state )
|
||||||
{
|
{
|
||||||
// Do this here?
|
// Do this here?
|
||||||
|
@ -1457,14 +1475,13 @@ static void menu_mainloop_iter ( MenuState *state, XEvent *ev )
|
||||||
MenuState *menu ( Mode *sw,
|
MenuState *menu ( Mode *sw,
|
||||||
char *input,
|
char *input,
|
||||||
char *prompt,
|
char *prompt,
|
||||||
unsigned int selected_line,
|
|
||||||
const char *message,
|
const char *message,
|
||||||
MenuFlags menu_flags )
|
MenuFlags menu_flags )
|
||||||
{
|
{
|
||||||
TICK ();
|
TICK ();
|
||||||
MenuState *state = menu_state_create ();
|
MenuState *state = menu_state_create ();
|
||||||
state->sw = sw;
|
state->sw = sw;
|
||||||
state->selected_line = selected_line;
|
state->selected_line = UINT32_MAX;
|
||||||
state->retv = MENU_CANCEL;
|
state->retv = MENU_CANCEL;
|
||||||
state->distance = NULL;
|
state->distance = NULL;
|
||||||
state->quit = FALSE;
|
state->quit = FALSE;
|
||||||
|
@ -1656,31 +1673,11 @@ MenuState *menu ( Mode *sw,
|
||||||
state->update = TRUE;
|
state->update = TRUE;
|
||||||
menu_refilter ( state );
|
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 );
|
menu_update ( state );
|
||||||
if ( sncontext != NULL ) {
|
if ( sncontext != NULL ) {
|
||||||
sn_launchee_context_complete ( sncontext );
|
sn_launchee_context_complete ( sncontext );
|
||||||
}
|
}
|
||||||
return state;
|
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 )
|
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 )
|
ModeMode switcher_run ( char **input, Mode *sw )
|
||||||
{
|
{
|
||||||
char *prompt = g_strdup_printf ( "%s:", mode_get_name ( 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_free ( prompt );
|
||||||
g_return_val_if_fail ( state != NULL, MODE_EXIT );
|
g_return_val_if_fail ( state != NULL, MODE_EXIT );
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue