tui: handle Esc correctly from toplevel windows

The main "connect" and "edit" windows set the "escape-exits" flag, but
that just closed the form without exiting the app, leaving the user
trapped. Fix this by emitting a signal when the form quits, and
catching that. (And now we don't need to watch the "clicked" signal on
the quit buttons, since they have the "exit-on-activate" flag set.)
This commit is contained in:
Dan Winship 2014-02-06 12:32:00 +01:00
parent 12a2d64063
commit 5d581b0d08
4 changed files with 37 additions and 7 deletions

View file

@ -72,6 +72,14 @@ enum {
LAST_PROP
};
enum {
QUIT,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static void nmt_newt_form_redraw (NmtNewtForm *form);
/**
@ -400,7 +408,6 @@ nmt_newt_form_quit (NmtNewtForm *form)
nmt_newt_form_destroy (form);
form_stack = g_slist_remove (form_stack, form);
g_object_unref (form);
if (form_stack)
nmt_newt_form_iterate (form_stack->data);
@ -408,6 +415,9 @@ nmt_newt_form_quit (NmtNewtForm *form)
g_source_destroy (keypress_source);
g_clear_pointer (&keypress_source, g_source_unref);
}
g_signal_emit (form, signals[QUIT], 0);
g_object_unref (form);
}
/**
@ -556,6 +566,22 @@ nmt_newt_form_class_init (NmtNewtFormClass *form_class)
form_class->show = nmt_newt_form_real_show;
/* signals */
/**
* NmtNewtForm::quit:
* @form: the #NmtNewtForm
*
* Emitted when the form quits.
*/
signals[QUIT] =
g_signal_new ("quit",
G_OBJECT_CLASS_TYPE (object_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NmtNewtFormClass, quit),
NULL, NULL, NULL,
G_TYPE_NONE, 0);
/**
* NmtNewtForm:title:
*

View file

@ -38,6 +38,10 @@ struct _NmtNewtForm {
typedef struct {
NmtNewtContainerClass parent;
/* signals */
void (*quit) (NmtNewtForm *form);
/* methods */
void (*show) (NmtNewtForm *form);
} NmtNewtFormClass;

View file

@ -237,8 +237,8 @@ listbox_active_changed (GObject *object,
}
static void
quit_clicked (NmtNewtButton *button,
gpointer user_data)
form_quit (NmtNewtForm *form,
gpointer user_data)
{
nmtui_quit ();
}
@ -257,6 +257,7 @@ nmt_connect_connection_list (void)
"height", screen_height - 4,
"escape-exits", TRUE,
NULL);
g_signal_connect (form, "quit", G_CALLBACK (form_quit), NULL);
grid = nmt_newt_grid_new ();
@ -278,7 +279,6 @@ nmt_connect_connection_list (void)
quit = nmt_newt_button_box_add_end (NMT_NEWT_BUTTON_BOX (bbox), _("Quit"));
nmt_newt_widget_set_exit_on_activate (quit, TRUE);
g_signal_connect (quit, "clicked", G_CALLBACK (quit_clicked), NULL);
nmt_newt_form_set_content (form, grid);
nmt_newt_form_show (form);

View file

@ -78,8 +78,8 @@ edit_connection_list_filter (NmtEditConnectionList *list,
}
static void
quit_clicked (NmtNewtButton *button,
gpointer user_data)
form_quit (NmtNewtForm *form,
gpointer user_data)
{
nmtui_quit ();
}
@ -98,10 +98,10 @@ nmt_edit_main_connection_list (void)
"height", screen_height - 4,
"escape-exits", TRUE,
NULL);
g_signal_connect (form, "quit", G_CALLBACK (form_quit), NULL);
quit = nmt_newt_button_new (_("Quit"));
nmt_newt_widget_set_exit_on_activate (quit, TRUE);
g_signal_connect (quit, "clicked", G_CALLBACK (quit_clicked), NULL);
list = g_object_new (NMT_TYPE_EDIT_CONNECTION_LIST,
"extra-widget", quit,