mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-29 08:00:18 +01:00
tui: return to initial menu after sub-forms exit
When the user runs nmtui and selects an operation (edit, connect or set-hostname) from the initial menu, the expectation is that once the operation terminates the initial menu is shown again, so that the user can perform multiple operations (like creating a connection and activating it) without quitting. https://bugzilla.gnome.org/show_bug.cgi?id=763836
This commit is contained in:
parent
b88ce6d044
commit
b2fb80928e
7 changed files with 33 additions and 30 deletions
|
|
@ -378,7 +378,7 @@ listbox_active_changed (GObject *object,
|
||||||
}
|
}
|
||||||
|
|
||||||
static NmtNewtForm *
|
static NmtNewtForm *
|
||||||
nmt_connect_connection_list (void)
|
nmt_connect_connection_list (gboolean is_top)
|
||||||
{
|
{
|
||||||
int screen_width, screen_height;
|
int screen_width, screen_height;
|
||||||
NmtNewtForm *form;
|
NmtNewtForm *form;
|
||||||
|
|
@ -410,7 +410,7 @@ nmt_connect_connection_list (void)
|
||||||
listbox_active_changed (G_OBJECT (list), NULL, activate);
|
listbox_active_changed (G_OBJECT (list), NULL, activate);
|
||||||
g_signal_connect (activate, "clicked", G_CALLBACK (activate_clicked), list);
|
g_signal_connect (activate, "clicked", G_CALLBACK (activate_clicked), list);
|
||||||
|
|
||||||
quit = nmt_newt_button_box_add_end (NMT_NEWT_BUTTON_BOX (bbox), _("Quit"));
|
quit = nmt_newt_button_box_add_end (NMT_NEWT_BUTTON_BOX (bbox), is_top ? _("Quit") : _("Back"));
|
||||||
nmt_newt_widget_set_exit_on_activate (quit, TRUE);
|
nmt_newt_widget_set_exit_on_activate (quit, TRUE);
|
||||||
|
|
||||||
nmt_newt_form_set_content (form, grid);
|
nmt_newt_form_set_content (form, grid);
|
||||||
|
|
@ -444,10 +444,10 @@ nmt_connect_connection (const char *identifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
NmtNewtForm *
|
NmtNewtForm *
|
||||||
nmtui_connect (int argc, char **argv)
|
nmtui_connect (gboolean is_top, int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc == 2)
|
if (argc == 2)
|
||||||
return nmt_connect_connection (argv[1]);
|
return nmt_connect_connection (argv[1]);
|
||||||
else
|
else
|
||||||
return nmt_connect_connection_list ();
|
return nmt_connect_connection_list (is_top);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
NmtNewtForm *nmtui_connect (int argc, char **argv);
|
NmtNewtForm *nmtui_connect (gboolean is_top, int argc, char **argv);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ edit_connection_list_filter (NmtEditConnectionList *list,
|
||||||
}
|
}
|
||||||
|
|
||||||
static NmtNewtForm *
|
static NmtNewtForm *
|
||||||
nmt_edit_main_connection_list (void)
|
nmt_edit_main_connection_list (gboolean is_top)
|
||||||
{
|
{
|
||||||
int screen_width, screen_height;
|
int screen_width, screen_height;
|
||||||
NmtNewtForm *form;
|
NmtNewtForm *form;
|
||||||
|
|
@ -117,7 +117,7 @@ nmt_edit_main_connection_list (void)
|
||||||
"escape-exits", TRUE,
|
"escape-exits", TRUE,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
quit = nmt_newt_button_new (_("Quit"));
|
quit = nmt_newt_button_new (is_top ? _("Quit") : _("Back"));
|
||||||
nmt_newt_widget_set_exit_on_activate (quit, TRUE);
|
nmt_newt_widget_set_exit_on_activate (quit, TRUE);
|
||||||
|
|
||||||
list = g_object_new (NMT_TYPE_EDIT_CONNECTION_LIST,
|
list = g_object_new (NMT_TYPE_EDIT_CONNECTION_LIST,
|
||||||
|
|
@ -555,7 +555,7 @@ nmt_remove_connection (NMRemoteConnection *connection)
|
||||||
}
|
}
|
||||||
|
|
||||||
NmtNewtForm *
|
NmtNewtForm *
|
||||||
nmtui_edit (int argc, char **argv)
|
nmtui_edit (gboolean is_top, int argc, char **argv)
|
||||||
{
|
{
|
||||||
NMConnection *conn = NULL;
|
NMConnection *conn = NULL;
|
||||||
|
|
||||||
|
|
@ -572,5 +572,5 @@ nmtui_edit (int argc, char **argv)
|
||||||
|
|
||||||
return nmt_editor_new (conn);
|
return nmt_editor_new (conn);
|
||||||
} else
|
} else
|
||||||
return nmt_edit_main_connection_list ();
|
return nmt_edit_main_connection_list (is_top);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ G_BEGIN_DECLS
|
||||||
typedef gboolean (*NmtAddConnectionTypeFilter) (GType connection_type,
|
typedef gboolean (*NmtAddConnectionTypeFilter) (GType connection_type,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
NmtNewtForm *nmtui_edit (int argc, char **argv);
|
NmtNewtForm *nmtui_edit (gboolean is_top, int argc, char **argv);
|
||||||
|
|
||||||
void nmt_add_connection (void);
|
void nmt_add_connection (void);
|
||||||
void nmt_add_connection_full (const char *primary_text,
|
void nmt_add_connection_full (const char *primary_text,
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ hostname_set (GObject *object,
|
||||||
}
|
}
|
||||||
|
|
||||||
NmtNewtForm *
|
NmtNewtForm *
|
||||||
nmtui_hostname (int argc, char **argv)
|
nmtui_hostname (gboolean is_top, int argc, char **argv)
|
||||||
{
|
{
|
||||||
const char *hostname;
|
const char *hostname;
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
NmtNewtForm *nmtui_hostname (int argc, char **argv);
|
NmtNewtForm *nmtui_hostname (gboolean is_top, int argc, char **argv);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
NMClient *nm_client;
|
NMClient *nm_client;
|
||||||
static GMainLoop *loop;
|
static GMainLoop *loop;
|
||||||
|
|
||||||
typedef NmtNewtForm * (*NmtuiSubprogram) (int argc, char **argv);
|
typedef NmtNewtForm * (*NmtuiSubprogram) (gboolean is_top, int argc, char **argv);
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
const char *name, *shortcut, *arg;
|
const char *name, *shortcut, *arg;
|
||||||
|
|
@ -63,20 +63,29 @@ static const struct {
|
||||||
static const int num_subprograms = G_N_ELEMENTS (subprograms);
|
static const int num_subprograms = G_N_ELEMENTS (subprograms);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
quit_func (int argc, char **argv)
|
main_list_activated (NmtNewtWidget *widget, NmtNewtListbox *listbox)
|
||||||
{
|
{
|
||||||
nmtui_quit ();
|
NmtNewtForm *form;
|
||||||
|
NmtuiSubprogram sub;
|
||||||
|
|
||||||
|
sub = nmt_newt_listbox_get_active_key (listbox);
|
||||||
|
if (sub) {
|
||||||
|
form = sub (FALSE, 0, NULL);
|
||||||
|
if (form) {
|
||||||
|
nmt_newt_form_show (form);
|
||||||
|
g_object_unref (form);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static NmtNewtForm *
|
static NmtNewtForm *
|
||||||
nmtui_main (int argc, char **argv)
|
nmtui_main (gboolean is_top, int argc, char **argv)
|
||||||
{
|
{
|
||||||
NmtNewtForm *form;
|
NmtNewtForm *form;
|
||||||
NmtNewtWidget *widget, *ok;
|
NmtNewtWidget *widget, *ok;
|
||||||
NmtNewtGrid *grid;
|
NmtNewtGrid *grid;
|
||||||
NmtNewtListbox *listbox;
|
NmtNewtListbox *listbox;
|
||||||
NmtNewtButtonBox *bbox;
|
NmtNewtButtonBox *bbox;
|
||||||
NmtuiSubprogram subprogram = NULL;
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
form = g_object_new (NMT_TYPE_NEWT_FORM,
|
form = g_object_new (NMT_TYPE_NEWT_FORM,
|
||||||
|
|
@ -97,32 +106,26 @@ nmtui_main (int argc, char **argv)
|
||||||
NULL);
|
NULL);
|
||||||
nmt_newt_grid_add (grid, widget, 0, 1);
|
nmt_newt_grid_add (grid, widget, 0, 1);
|
||||||
nmt_newt_widget_set_padding (widget, 0, 1, 0, 1);
|
nmt_newt_widget_set_padding (widget, 0, 1, 0, 1);
|
||||||
nmt_newt_widget_set_exit_on_activate (widget, TRUE);
|
|
||||||
listbox = NMT_NEWT_LISTBOX (widget);
|
listbox = NMT_NEWT_LISTBOX (widget);
|
||||||
|
g_signal_connect (widget, "activated",
|
||||||
|
G_CALLBACK (main_list_activated), listbox);
|
||||||
|
|
||||||
for (i = 0; i < num_subprograms; i++) {
|
for (i = 0; i < num_subprograms; i++) {
|
||||||
nmt_newt_listbox_append (listbox, _(subprograms[i].display_name),
|
nmt_newt_listbox_append (listbox, _(subprograms[i].display_name),
|
||||||
subprograms[i].func);
|
subprograms[i].func);
|
||||||
}
|
}
|
||||||
nmt_newt_listbox_append (listbox, "", NULL);
|
nmt_newt_listbox_append (listbox, "", NULL);
|
||||||
nmt_newt_listbox_append (listbox, _("Quit"), quit_func);
|
nmt_newt_listbox_append (listbox, _("Quit"), nmtui_quit);
|
||||||
|
|
||||||
widget = nmt_newt_button_box_new (NMT_NEWT_BUTTON_BOX_HORIZONTAL);
|
widget = nmt_newt_button_box_new (NMT_NEWT_BUTTON_BOX_HORIZONTAL);
|
||||||
nmt_newt_grid_add (grid, widget, 0, 2);
|
nmt_newt_grid_add (grid, widget, 0, 2);
|
||||||
bbox = NMT_NEWT_BUTTON_BOX (widget);
|
bbox = NMT_NEWT_BUTTON_BOX (widget);
|
||||||
|
|
||||||
ok = nmt_newt_button_box_add_end (bbox, _("OK"));
|
ok = nmt_newt_button_box_add_end (bbox, _("OK"));
|
||||||
nmt_newt_widget_set_exit_on_activate (ok, TRUE);
|
g_signal_connect (ok, "activated",
|
||||||
|
G_CALLBACK (main_list_activated), listbox);
|
||||||
|
|
||||||
widget = nmt_newt_form_run_sync (form);
|
return form;
|
||||||
if (widget)
|
|
||||||
subprogram = nmt_newt_listbox_get_active_key (listbox);
|
|
||||||
g_object_unref (form);
|
|
||||||
|
|
||||||
if (subprogram)
|
|
||||||
return subprogram (argc, argv);
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -179,7 +182,7 @@ idle_run_subprogram (gpointer user_data)
|
||||||
NmtuiStartupData *data = user_data;
|
NmtuiStartupData *data = user_data;
|
||||||
NmtNewtForm *form;
|
NmtNewtForm *form;
|
||||||
|
|
||||||
form = data->subprogram (data->argc, data->argv);
|
form = data->subprogram (TRUE, data->argc, data->argv);
|
||||||
if (form) {
|
if (form) {
|
||||||
g_signal_connect (form, "quit", G_CALLBACK (toplevel_form_quit), NULL);
|
g_signal_connect (form, "quit", G_CALLBACK (toplevel_form_quit), NULL);
|
||||||
nmt_newt_form_show (form);
|
nmt_newt_form_show (form);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue