static void list_add_connection (NmtEditConnectionList *list, gpointer form) { nmt_add_connection (); nmt_newt_form_set_focus (form, NMT_NEWT_WIDGET (list)); }
static void list_remove_connection (NmtEditConnectionList *list, NMRemoteConnection *connection, gpointer form) { nmt_remove_connection (connection); nmt_newt_form_set_focus (form, NMT_NEWT_WIDGET (list)); }
/* A "normal" newt program would call newtFormRun() to run newt's main loop * and process events. But we want to let GLib's main loop control the program * (eg, so libnm can process D-Bus notifications). So we call this function * to run a single iteration of newt's main loop (or rather, to run newt's * main loop for 1ms) whenever there are events for newt to process (redrawing * or keypresses). */ static void nmt_newt_form_iterate (NmtNewtForm *form) { NmtNewtFormPrivate *priv = NMT_NEWT_FORM_GET_PRIVATE (form); NmtNewtWidget *focus; struct newtExitStruct es; if (priv->dirty) { nmt_newt_form_destroy (form); nmt_newt_form_build (form); } newtFormSetTimer (priv->form, 1); newtFormRun (priv->form, &es); if ( es.reason == NEWT_EXIT_HOTKEY || es.reason == NEWT_EXIT_ERROR) { /* The user hit Esc or there was an error. */ g_clear_object (&priv->focus); nmt_newt_form_quit (form); return; } if (es.reason == NEWT_EXIT_COMPONENT) { /* The user hit Return/Space on a component; update the form focus * to point that that component, and activate it. */ focus = nmt_newt_widget_find_component (priv->content, es.u.co); if (focus) { nmt_newt_form_set_focus (form, focus); nmt_newt_widget_activated (focus); } } else { /* The 1ms timer ran out. Update focus but don't do anything else. */ focus = nmt_newt_widget_find_component (priv->content, newtFormGetCurrent (priv->form)); if (focus) nmt_newt_form_set_focus (form, focus); } }
static void ensure_widgets (NmtWidgetList *list) { NmtWidgetListPrivate *priv = NMT_WIDGET_LIST_GET_PRIVATE (list); NmtNewtWidget *widget, *button, *focus; gboolean was_empty; NmtNewtForm *form; int i; was_empty = priv->widgets->len == 0; if (priv->length < priv->widgets->len) { /* remove excess widgets */ for (i = priv->length; i < priv->widgets->len; i++) { nmt_newt_container_remove (NMT_NEWT_CONTAINER (list), priv->widgets->pdata[i]); nmt_newt_container_remove (NMT_NEWT_CONTAINER (list), priv->remove_buttons->pdata[i]); } g_ptr_array_set_size (priv->widgets, priv->length); g_ptr_array_set_size (priv->remove_buttons, priv->length); } else if (priv->length > priv->widgets->len) { /* add new widgets */ for (i = priv->widgets->len; i < priv->length; i++) { widget = NMT_WIDGET_LIST_GET_CLASS (list)->create_widget (list, i); nmt_newt_grid_add (NMT_NEWT_GRID (list), widget, 0, i); g_ptr_array_add (priv->widgets, widget); button = nmt_newt_button_new (_("Remove")); g_signal_connect (button, "clicked", G_CALLBACK (remove_clicked), list); nmt_newt_grid_add (NMT_NEWT_GRID (list), button, 1, i); nmt_newt_widget_set_padding (button, 1, 0, 0, 0); g_ptr_array_add (priv->remove_buttons, button); } } else return; if (priv->widgets->len == 0 && priv->empty_widget) { nmt_newt_widget_set_visible (priv->empty_widget, TRUE); nmt_newt_grid_move (NMT_NEWT_GRID (list), priv->add_button, 0, 1); } else { if (was_empty && priv->empty_widget) nmt_newt_widget_set_visible (priv->empty_widget, FALSE); nmt_newt_grid_move (NMT_NEWT_GRID (list), priv->add_button, 0, priv->length); } form = nmt_newt_widget_get_form (NMT_NEWT_WIDGET (list)); if (form) { if (priv->widgets->len) { if (was_empty) focus = priv->widgets->pdata[0]; else focus = priv->widgets->pdata[priv->widgets->len - 1]; } else focus = priv->add_button; nmt_newt_form_set_focus (form, focus); } g_clear_object (&priv->add_sensitivity); if (priv->widgets->len) { widget = priv->widgets->pdata[priv->widgets->len - 1]; priv->add_sensitivity = g_object_bind_property (widget, "valid", priv->add_button, "sensitive", G_BINDING_SYNC_CREATE); g_object_add_weak_pointer (G_OBJECT (priv->add_sensitivity), (gpointer *)&priv->add_sensitivity); } }