diff options
author | Dan Winship <danw@gnome.org> | 2014-01-21 11:10:34 -0500 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2014-04-09 10:58:14 -0400 |
commit | c62f115fcf1543f1401d2e784937f656671798e7 (patch) | |
tree | 287442d1d18a704717d8903cc1de562879d5bc97 | |
parent | 3e75dfdec726920218d3fe8a1ebcdc6c8dd92505 (diff) | |
download | NetworkManager-c62f115fcf1543f1401d2e784937f656671798e7.tar.gz |
tui: add NmtNewtWidget:help-text, display in NmtNewtForm
If a widget defines the :help-text property, display it in the form's
help line when that widget is focused.
NOTE: requires un-upstreamed newt changes!
-rw-r--r-- | tui/newt/nmt-newt-form.c | 30 | ||||
-rw-r--r-- | tui/newt/nmt-newt-form.h | 4 | ||||
-rw-r--r-- | tui/newt/nmt-newt-utils.c | 3 | ||||
-rw-r--r-- | tui/newt/nmt-newt-widget.c | 57 | ||||
-rw-r--r-- | tui/newt/nmt-newt-widget.h | 3 |
5 files changed, 97 insertions, 0 deletions
diff --git a/tui/newt/nmt-newt-form.c b/tui/newt/nmt-newt-form.c index 305a599481..645606858a 100644 --- a/tui/newt/nmt-newt-form.c +++ b/tui/newt/nmt-newt-form.c @@ -53,6 +53,7 @@ typedef struct { gboolean dirty, escape_exits; NmtNewtWidget *focus; + char *help_line; #ifdef HAVE_NEWTFORMGETSCROLLPOSITION int scroll_position = 0; #endif @@ -191,6 +192,30 @@ nmt_newt_form_set_content (NmtNewtForm *form, } static void +nmt_newt_form_reset_help_line (NmtNewtForm *form) +{ + NmtNewtFormPrivate *priv = NMT_NEWT_FORM_GET_PRIVATE (form); + const char *help_text; + + newtPopHelpLine (); + if (priv->focus) { + help_text = nmt_newt_widget_get_help_text (priv->focus); + if (help_text) + newtPushHelpLine (help_text); + } +} + +static void +focus_help_text_changed (GObject *object, + GParamSpec *pspec, + gpointer user_data) +{ + NmtNewtForm *form = user_data; + + nmt_newt_form_reset_help_line (form); +} + +static void nmt_newt_form_focus_changed (NmtNewtForm *form, NmtNewtWidget *focus, newtComponent co) @@ -199,6 +224,7 @@ nmt_newt_form_focus_changed (NmtNewtForm *form, if (priv->focus != focus) { if (priv->focus) { + g_signal_handlers_disconnect_by_func (priv->focus, G_CALLBACK (focus_help_text_changed), form); nmt_newt_widget_focus_out (priv->focus); g_object_unref (priv->focus); } @@ -208,9 +234,13 @@ nmt_newt_form_focus_changed (NmtNewtForm *form, if (priv->focus) { g_object_ref (priv->focus); nmt_newt_widget_focus_in (priv->focus); + g_signal_connect (priv->focus, "notify::help-text", + G_CALLBACK (focus_help_text_changed), form); } } + nmt_newt_form_reset_help_line (form); + if (priv->form && priv->focus) { if (!co) co = nmt_newt_widget_get_focus_component (priv->focus); diff --git a/tui/newt/nmt-newt-form.h b/tui/newt/nmt-newt-form.h index be95eb68ad..a959ef30d5 100644 --- a/tui/newt/nmt-newt-form.h +++ b/tui/newt/nmt-newt-form.h @@ -61,6 +61,10 @@ void nmt_newt_form_quit (NmtNewtForm *form); void nmt_newt_form_set_focus (NmtNewtForm *form, NmtNewtWidget *widget); +void nmt_newt_form_set_help_line (NmtNewtForm *form, + NmtNewtWidget *widget, + const char *help_line); + G_END_DECLS #endif /* NMT_NEWT_FORM_H */ diff --git a/tui/newt/nmt-newt-utils.c b/tui/newt/nmt-newt-utils.c index 9a960d0e33..22d3f2e963 100644 --- a/tui/newt/nmt-newt-utils.c +++ b/tui/newt/nmt-newt-utils.c @@ -403,4 +403,7 @@ nmt_newt_get_screen_size (int *screen_width, int *screen_height) { newtGetScreenSize (screen_width, screen_height); + + /* Allow room for the help line at the bottom */ + *screen_height -= 2; } diff --git a/tui/newt/nmt-newt-widget.c b/tui/newt/nmt-newt-widget.c index 6251c21b93..057d9abd20 100644 --- a/tui/newt/nmt-newt-widget.c +++ b/tui/newt/nmt-newt-widget.c @@ -47,6 +47,7 @@ typedef struct { NmtNewtWidget *parent; gboolean visible, realized, valid; gboolean exit_on_activate; + char *help_text; int pad_left, pad_top, pad_right, pad_bottom; } NmtNewtWidgetPrivate; @@ -57,6 +58,7 @@ enum { PROP_PARENT, PROP_VISIBLE, PROP_VALID, + PROP_HELP_TEXT, PROP_EXIT_ON_ACTIVATE, LAST_PROP @@ -87,6 +89,7 @@ nmt_newt_widget_finalize (GObject *object) nmt_newt_widget_unrealize (NMT_NEWT_WIDGET (object)); g_clear_object (&priv->parent); + g_free (priv->help_text); G_OBJECT_CLASS (nmt_newt_widget_parent_class)->finalize (object); } @@ -526,6 +529,46 @@ nmt_newt_widget_set_valid (NmtNewtWidget *widget, } /** + * nmt_newt_widget_get_help_text: + * @widget: an #NmtNewtWidget + * + * Gets @widget's #NmtNewtWidget:help-text, indicating text to display + * in its form's status line (or %NULL to not display anything). + * + * Returns: @widget's #NmtNewtWidget:help-text. + */ +const char * +nmt_newt_widget_get_help_text (NmtNewtWidget *widget) +{ + NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget); + + return priv->help_text; +} + +/** + * nmt_newt_widget_set_help_text: + * @widget: an #NmtNewtWidget + * @help_text: help text to display when @widget is focused + * + * Sets @widget's #NmtNewtWidget:help-text, indicating text to display + * in its form's status line when the widget is focused. + */ +void +nmt_newt_widget_set_help_text (NmtNewtWidget *widget, + const char *help_text) +{ + NmtNewtWidgetPrivate *priv = NMT_NEWT_WIDGET_GET_PRIVATE (widget); + + if (!g_strcmp0 (priv->help_text, help_text)) + return; + + g_free (priv->help_text); + priv->help_text = g_strdup (help_text); + + g_object_notify (G_OBJECT (widget), "help-text"); +} + +/** * nmt_newt_widget_needs_rebuilds: * @widget: an #NmtNewtWidget * @@ -584,6 +627,9 @@ nmt_newt_widget_get_property (GObject *object, case PROP_VALID: g_value_set_boolean (value, priv->valid); break; + case PROP_HELP_TEXT: + g_value_set_string (value, priv->help_text); + break; case PROP_EXIT_ON_ACTIVATE: g_value_set_boolean (value, priv->exit_on_activate); break; @@ -678,6 +724,17 @@ nmt_newt_widget_class_init (NmtNewtWidgetClass *widget_class) G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); /** + * NmtNewtWidget:help-text: + * + * Text to display in the widget's form's status line when the + * widget is focused. + */ + g_object_class_install_property (object_class, PROP_HELP_TEXT, + g_param_spec_string ("help-text", "", "", + NULL, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + /** * NmtNewtWidget:exit-on-activate: * * If %TRUE, the widget will call nmt_newt_form_quit() on its form diff --git a/tui/newt/nmt-newt-widget.h b/tui/newt/nmt-newt-widget.h index 137ed6381d..b5cde6c89b 100644 --- a/tui/newt/nmt-newt-widget.h +++ b/tui/newt/nmt-newt-widget.h @@ -110,6 +110,7 @@ void nmt_newt_widget_set_exit_on_activate (NmtNewtWidget *widget, gboolean exit_on_activate); gboolean nmt_newt_widget_get_valid (NmtNewtWidget *widget); +const char * nmt_newt_widget_get_help_text (NmtNewtWidget *widget); NmtNewtWidget *nmt_newt_widget_find_component (NmtNewtWidget *widget, newtComponent co); @@ -118,6 +119,8 @@ NmtNewtWidget *nmt_newt_widget_find_component (NmtNewtWidget *widget, void nmt_newt_widget_needs_rebuild (NmtNewtWidget *widget); void nmt_newt_widget_set_valid (NmtNewtWidget *widget, gboolean valid); +void nmt_newt_widget_set_help_text (NmtNewtWidget *widget, + const char *help_text); G_END_DECLS |