[master 2/5] Allow markup and links in the info bar.

dashea installerbot-noreply at redhat.com
Wed Mar 4 15:41:17 UTC 2015


From: David Shea <dshea at redhat.com>

This changes the behavior of
anaconda_base_window_set_{error,info_warning}, in that the message
parameter is now treated as markup. Encourage the use of links in the
message in order to add something activatable to the tab order. The
actual link URI will be ignored.

Change the info-bar-clicked event to activate on button-pressed instead
of button-released, which keeps us from both a button event and a link
event if someone clicks on a link.
---
 widgets/src/BaseWindow.c | 41 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/widgets/src/BaseWindow.c b/widgets/src/BaseWindow.c
index 4fc1cb3..b82c7d2 100644
--- a/widgets/src/BaseWindow.c
+++ b/widgets/src/BaseWindow.c
@@ -131,6 +131,7 @@ static void anaconda_base_window_get_property(GObject *object, guint prop_id, GV
 static void anaconda_base_window_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
 static void anaconda_base_window_buildable_init(GtkBuildableIface *iface);
 static void format_beta_label(AnacondaBaseWindow *window, const char *markup);
+static gboolean anaconda_base_window_info_activate_link(GtkLabel *label, gchar *uri, gpointer user_data);
 
 static gboolean anaconda_base_window_info_bar_clicked(GtkWidget *widget, GdkEvent *event, AnacondaBaseWindow *win);
 static void anaconda_base_window_help_button_clicked(GtkButton *button, AnacondaBaseWindow *win);
@@ -189,6 +190,11 @@ static void anaconda_base_window_class_init(AnacondaBaseWindowClass *klass) {
      * (pressed and released).  This allows, for instance, popping up a dialog with
      * more detailed information.
      *
+     * Activatable info bars are encouraged to include a link in the message for the
+     * purpose of keyboard navigation.  Clicking the link will emit the
+     * info-bar-clicked signal. See anaconda_base_window_set_error() for more
+     * information.
+     *
      * Since: 1.0
      */
     window_signals[SIGNAL_INFO_BAR_CLICKED] = g_signal_new("info-bar-clicked",
@@ -570,8 +576,15 @@ static void anaconda_base_window_set_info_bar(AnacondaBaseWindow *win, GtkMessag
     label = gtk_label_new(_(msg));
     gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
     gtk_label_set_line_wrap_mode(GTK_LABEL(label), PANGO_WRAP_WORD);
+    gtk_label_set_use_markup(GTK_LABEL(label), TRUE);
     gtk_widget_show(label);
 
+    /* Connect the activate-link signal to ignore actual link clicks. The part
+     * of the click we care about will be handled by the event box
+     */
+    g_signal_connect(label, "activate-link",
+            G_CALLBACK(anaconda_base_window_info_activate_link), win);
+
     win->priv->info_bar = gtk_info_bar_new();
     gtk_widget_set_no_show_all(win->priv->info_bar, TRUE);
 
@@ -585,8 +598,8 @@ static void anaconda_base_window_set_info_bar(AnacondaBaseWindow *win, GtkMessag
      * custom signal for the whole window.  It will be disconnected when the info
      * bar is hidden.
      */
-    gtk_widget_add_events(GTK_WIDGET(win->priv->event_box), GDK_BUTTON_RELEASE_MASK);
-    g_signal_connect(win->priv->event_box, "button-release-event",
+    gtk_widget_add_events(GTK_WIDGET(win->priv->event_box), GDK_BUTTON_PRESS_MASK);
+    g_signal_connect(win->priv->event_box, "button-press-event",
                      G_CALLBACK(anaconda_base_window_info_bar_clicked), win);
 
     content_area = gtk_info_bar_get_content_area(GTK_INFO_BAR(win->priv->info_bar));
@@ -603,6 +616,12 @@ static void anaconda_base_window_set_info_bar(AnacondaBaseWindow *win, GtkMessag
     win->priv->info_shown = TRUE;
 }
 
+static gboolean anaconda_base_window_info_activate_link(GtkLabel *label, gchar *uri, gpointer win) {
+    /* Ignore the actual URI and emit info-bar-clicked on the window */
+    g_signal_emit(win, window_signals[SIGNAL_INFO_BAR_CLICKED], 0);
+    return TRUE;
+}
+
 /**
  * anaconda_base_window_set_error:
  * @win: a #AnacondaBaseWindow
@@ -612,6 +631,12 @@ static void anaconda_base_window_set_info_bar(AnacondaBaseWindow *win, GtkMessag
  * message.  Only one message may be shown at a time.  In order to show
  * a second message, anaconda_base_window_clear_info() must first be called.
  *
+ * The message will be interpreted as Pango markup. Clickable messages are
+ * encouraged to include a clickable link using the #GtkLabel syntax in order
+ * to make the info bar accessible via the keyboard. The link URI will be
+ * ignored, and all link clicks will emit the
+ * #AnacondaBaseWindow::info-bar-clicked signal on @win.
+ *
  * Since: 1.0
  */
 void anaconda_base_window_set_error(AnacondaBaseWindow *win, const char *msg) {
@@ -627,6 +652,12 @@ void anaconda_base_window_set_error(AnacondaBaseWindow *win, const char *msg) {
  * message.  Only one message may be shown at a time.  In order to show
  * a second message, anaconda_base_window_clear_info() must first be called.
  *
+ * The message will be interpreted as Pango markup. Clickable messages are
+ * encouraged to include a clickable link using the #GtkLabel syntax in order
+ * to make the info bar accessible via the keyboard. The link URI will be
+ * ignored, and all link clicks will emit the
+ * #AnacondaBaseWindow::info-bar-clicked signal on @win.
+ *
  * Since: 1.0
  */
 void anaconda_base_window_set_info(AnacondaBaseWindow *win, const char *msg) {
@@ -642,6 +673,12 @@ void anaconda_base_window_set_info(AnacondaBaseWindow *win, const char *msg) {
  * message.  Only one message may be shown at a time.  In order to show
  * a second message, anaconda_base_window_clear_info() must first be called.
  *
+ * The message will be interpreted as Pango markup. Clickable messages are
+ * encouraged to include a clickable link using the #GtkLabel syntax in order
+ * to make the info bar accessible via the keyboard. The link URI will be
+ * ignored, and all link clicks will emit the
+ * #AnacondaBaseWindow::info-bar-clicked signal on @win.
+ *
  * Since: 1.0
  */
 void anaconda_base_window_set_warning(AnacondaBaseWindow *win, const char *msg) {


-- 
To view this commit on github, visit https://github.com/rhinstaller/anaconda/commit/e66ccae33054876bfc996d995d8be799a30b1021


More information about the anaconda-patches mailing list