1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-11 13:50:48 -05:00

When mode not found, show gui, not only on commandline.

This commit is contained in:
Dave Davenport 2019-03-24 02:30:16 +01:00
parent e17d63f5ae
commit 1a77cae593

View file

@ -366,12 +366,22 @@ static void help_print_disabled_mode ( const char *mode )
} }
static void help_print_mode_not_found ( const char *mode ) static void help_print_mode_not_found ( const char *mode )
{ {
int is_term = isatty ( fileno ( stdout ) ); GString *str = g_string_new ("");
fprintf ( stderr, "Mode %s%s%s is not found.\n", g_string_printf(str, "Mode %s is not found.\nThe following modi are known:\n", mode );
is_term ? color_red : "", mode, is_term ? color_reset : "" ); for ( unsigned int i = 0; i < num_available_modi; i++ ) {
fprintf ( stderr, "The following modi are known:\n" ); gboolean active = FALSE;
print_list_of_modi ( is_term ); for ( unsigned int j = 0; j < num_modi; j++ ) {
printf ( "\n" ); if ( modi[j] == available_modi[i] ) {
active = TRUE;
break;
}
}
g_string_append_printf (str, " * %s%s\n",
active ? "+" : "",
available_modi[i]->name
);
}
rofi_add_error_message ( str );
} }
static void help_print_no_arguments ( void ) static void help_print_no_arguments ( void )
{ {
@ -616,8 +626,6 @@ static gboolean setup_modi ( void )
for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) { for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) {
if ( add_mode ( token ) == -1 ) { if ( add_mode ( token ) == -1 ) {
help_print_mode_not_found ( token ); help_print_mode_not_found ( token );
g_free ( switcher_str );
return TRUE;
} }
} }
// Free string that was modified by strtok_r // Free string that was modified by strtok_r
@ -640,6 +648,25 @@ static gboolean main_loop_signal_handler_int ( G_GNUC_UNUSED gpointer data )
g_main_loop_quit ( main_loop ); g_main_loop_quit ( main_loop );
return G_SOURCE_CONTINUE; return G_SOURCE_CONTINUE;
} }
static void show_error_dialog ()
{
GString *emesg = g_string_new ( "The following errors were detected when starting rofi:\n" );
GList *iter = g_list_first ( list_of_error_msgs );
int index = 0;
for (; iter != NULL && index < 2; iter = g_list_next ( iter ) ) {
GString *msg = (GString *) ( iter->data );
g_string_append ( emesg, "\n\n" );
g_string_append ( emesg, msg->str );
index++;
}
if ( g_list_length ( iter ) > 1 ) {
g_string_append_printf ( emesg, "\nThere are <b>%d</b> more errors.", g_list_length ( iter ) - 1 );
}
rofi_view_error_dialog ( emesg->str, ERROR_MSG_MARKUP );
g_string_free ( emesg, TRUE );
rofi_set_return_code ( EX_DATAERR );
}
static gboolean startup ( G_GNUC_UNUSED gpointer data ) static gboolean startup ( G_GNUC_UNUSED gpointer data )
{ {
@ -662,21 +689,7 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data )
TICK_N ( "Config sanity check" ); TICK_N ( "Config sanity check" );
if ( list_of_error_msgs != NULL ) { if ( list_of_error_msgs != NULL ) {
GString *emesg = g_string_new ( "The following errors were detected when starting rofi:\n" ); show_error_dialog ();
GList *iter = g_list_first ( list_of_error_msgs );
int index = 0;
for (; iter != NULL && index < 2; iter = g_list_next ( iter ) ) {
GString *msg = (GString *) ( iter->data );
g_string_append ( emesg, "\n\n" );
g_string_append ( emesg, msg->str );
index++;
}
if ( g_list_length ( iter ) > 1 ) {
g_string_append_printf ( emesg, "\nThere are <b>%d</b> more errors.", g_list_length ( iter ) - 1 );
}
rofi_view_error_dialog ( emesg->str, ERROR_MSG_MARKUP );
g_string_free ( emesg, TRUE );
rofi_set_return_code ( EX_DATAERR );
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
// Dmenu mode. // Dmenu mode.
@ -715,7 +728,7 @@ static gboolean startup ( G_GNUC_UNUSED gpointer data )
} }
else { else {
help_print_mode_not_found ( sname ); help_print_mode_not_found ( sname );
g_main_loop_quit ( main_loop ); show_error_dialog ();
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
} }
} }