[Xfce4-commits] [xfce/libxfce4ui] 03/04: New function: xfce_titled_dialog_new_with_mixed_buttons

noreply at xfce.org noreply at xfce.org
Tue Jun 7 15:05:01 CEST 2016


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository xfce/libxfce4ui.

commit 902f0a5bc6a3c7c1dab0af5daf1db5514bcff93d
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Tue Jun 7 10:54:37 2016 +0300

    New function: xfce_titled_dialog_new_with_mixed_buttons
    
    Using xfce_titled_dialog_new_with_buttons in Gtk3 results in
    buttons	that cannot have icons except for STOCK	icons. This
    is because it just calls gtk_dialog_add_button to create
    and add	the buttons. With this new function, you specify
    an icon name, STOCK icon, or simply "" for no icon on the
    button followed by the button text and response id for each
    button.
---
 libxfce4ui/libxfce4ui.symbols   |  1 +
 libxfce4ui/xfce-titled-dialog.c | 76 +++++++++++++++++++++++++++++++++++++++
 libxfce4ui/xfce-titled-dialog.h |  7 ++++
 tests/test-ui.c                 | 80 ++++++++++++++++++++++++++++++++++++++---
 4 files changed, 160 insertions(+), 4 deletions(-)

diff --git a/libxfce4ui/libxfce4ui.symbols b/libxfce4ui/libxfce4ui.symbols
index 1a6ea6a..11c0877 100644
--- a/libxfce4ui/libxfce4ui.symbols
+++ b/libxfce4ui/libxfce4ui.symbols
@@ -130,6 +130,7 @@ xfce_sm_client_get_current_directory
 xfce_titled_dialog_get_type G_GNUC_CONST
 xfce_titled_dialog_new G_GNUC_MALLOC
 xfce_titled_dialog_new_with_buttons G_GNUC_MALLOC
+xfce_titled_dialog_new_with_mixed_buttons G_GNUC_MALLOC
 xfce_titled_dialog_get_subtitle
 xfce_titled_dialog_set_subtitle
 #endif
diff --git a/libxfce4ui/xfce-titled-dialog.c b/libxfce4ui/xfce-titled-dialog.c
index 30a3bb9..1abbd45 100644
--- a/libxfce4ui/xfce-titled-dialog.c
+++ b/libxfce4ui/xfce-titled-dialog.c
@@ -31,6 +31,7 @@
 #include <libxfce4ui/xfce-titled-dialog.h>
 #include <libxfce4ui/libxfce4ui-private.h>
 #include <libxfce4ui/libxfce4ui-alias.h>
+#include <libxfce4ui/xfce-gtk-extensions.h>
 
 
 #define XFCE_TITLED_DIALOG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), XFCE_TYPE_TITLED_DIALOG, XfceTitledDialogPrivate))
@@ -317,6 +318,81 @@ xfce_titled_dialog_new_with_buttons (const gchar    *title,
 
 
 /**
+ * xfce_titled_dialog_new_with_mixed_buttons:
+ * @title                  : title of the dialog, or %NULL.
+ * @parent                 : transient parent window of the dialog, or %NULL.
+ * @flags                  : from #GtkDialogFlags.
+ * @first_button_icon_name : icon name to go in first, or "" for no icon.
+ * @first_button_text      : text to go in first, or %NULL.
+ * @...                    : response ID for the first button, then additional buttons, ending with %NULL.
+ *
+ * Creates an #XfceTitledDialog using xfce_gtk_button_new_mixed. This allows
+ * the buttons to use an optional named or stock icon.
+ *
+ * Return value: the newly allocated #XfceTitledDialog.
+ **/
+GtkWidget*
+xfce_titled_dialog_new_with_mixed_buttons (const gchar    *title,
+                                           GtkWindow      *parent,
+                                           GtkDialogFlags  flags,
+                                           const gchar    *first_button_icon_name,
+                                           const gchar    *first_button_text,
+                                           ...)
+{
+  const gchar *icon_name;
+  const gchar *button_text;
+  GtkWidget   *dialog;
+  va_list      args;
+  gint         response_id;
+
+  /* allocate the dialog */
+  dialog = g_object_new (XFCE_TYPE_TITLED_DIALOG,
+                         "destroy-with-parent", ((flags & GTK_DIALOG_DESTROY_WITH_PARENT) != 0),
+                         "modal", ((flags & GTK_DIALOG_MODAL) != 0),
+                         "title", title,
+                         NULL);
+
+  /* set the transient parent (if any) */
+  if (G_LIKELY (parent != NULL))
+    gtk_window_set_transient_for (GTK_WINDOW (dialog), parent);
+
+  /* add all additional buttons */
+  icon_name = first_button_icon_name;
+  button_text = first_button_text;
+  va_start (args, first_button_text);
+
+  while (icon_name != NULL)
+    {
+      GtkWidget *button;
+
+      /* response id comes after button text */
+      response_id = va_arg (args, gint);
+
+      /* build our button and add it */
+      button = xfce_gtk_button_new_mixed (icon_name, button_text);
+      gtk_widget_set_can_default (button, TRUE);
+
+      gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
+      gtk_widget_show (button);
+
+      /* this is to pickup for the next button.
+       * The pattern is icon_name, button text
+       */
+      icon_name = va_arg (args, const gchar *);
+      if (icon_name)
+        {
+          button_text = va_arg (args, const gchar *);
+        }
+    }
+  va_end (args);
+
+  return dialog;
+}
+
+
+
+
+/**
  * xfce_titled_dialog_get_subtitle:
  * @titled_dialog : a #XfceTitledDialog.
  *
diff --git a/libxfce4ui/xfce-titled-dialog.h b/libxfce4ui/xfce-titled-dialog.h
index ddf4ec4..e78f691 100644
--- a/libxfce4ui/xfce-titled-dialog.h
+++ b/libxfce4ui/xfce-titled-dialog.h
@@ -69,6 +69,13 @@ GtkWidget            *xfce_titled_dialog_new_with_buttons (const gchar      *tit
                                                            const gchar      *first_button_text,
                                                            ...) G_GNUC_MALLOC;
 
+GtkWidget            *xfce_titled_dialog_new_with_mixed_buttons (const gchar    *title,
+                                                                 GtkWindow      *parent,
+                                                                 GtkDialogFlags  flags,
+                                                                 const gchar    *first_button_icon_name,
+                                                                 const gchar    *first_button_text,
+                                                                 ...) G_GNUC_MALLOC;
+
 const gchar          *xfce_titled_dialog_get_subtitle     (XfceTitledDialog *titled_dialog);
 void                  xfce_titled_dialog_set_subtitle     (XfceTitledDialog *titled_dialog,
                                                            const gchar      *subtitle);
diff --git a/tests/test-ui.c b/tests/test-ui.c
index f9843fb..4f2e7e9 100644
--- a/tests/test-ui.c
+++ b/tests/test-ui.c
@@ -174,6 +174,15 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 G_GNUC_END_IGNORE_DEPRECATIONS
 }
 
+
+static void
+close_window (GtkDialog *dialog,
+              gint       response_id,
+              gpointer   user_data)
+{
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+}
+
 static void
 show_xfce_titled_dialog_new_with_buttons (GtkButton *button,
                                           gpointer unused)
@@ -183,10 +192,10 @@ show_xfce_titled_dialog_new_with_buttons (GtkButton *button,
 #if GTK_CHECK_VERSION (3, 0, 0)
   GtkWidget *dialog_gtk3;
 
-  dialog_gtk3 = xfce_titled_dialog_new_with_buttons ("Settings Editor", NULL,
+  dialog_gtk3 = xfce_titled_dialog_new_with_buttons ("Settings Editor (Gtk3)", NULL,
                                                 GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                "help-browser", GTK_RESPONSE_HELP,
-                                                "window-close", GTK_RESPONSE_OK,
+                                                "gtk-help", GTK_RESPONSE_HELP,
+                                                "gtk-close", GTK_RESPONSE_OK,
                                                 NULL);
 
   xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (dialog_gtk3),
@@ -194,13 +203,16 @@ show_xfce_titled_dialog_new_with_buttons (GtkButton *button,
 
   gtk_window_set_icon_name (GTK_WINDOW (dialog_gtk3), "preferences-system");
   gtk_window_set_type_hint (GTK_WINDOW (dialog_gtk3), GDK_WINDOW_TYPE_HINT_NORMAL);
+
+  g_signal_connect (dialog_gtk3, "response", G_CALLBACK (close_window), NULL);
+
   gtk_widget_show_all (dialog_gtk3);
 #endif
 
 /* ignore those warnings so it's easy to see what the default Gtk2 version
  * looks like in Gtk3 with the stock icons */
 G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-  dialog_gtk2 = xfce_titled_dialog_new_with_buttons ("Settings Editor", NULL,
+  dialog_gtk2 = xfce_titled_dialog_new_with_buttons ("Settings Editor (Gtk2)", NULL,
                                                      GTK_DIALOG_DESTROY_WITH_PARENT,
                                                      GTK_STOCK_HELP, GTK_RESPONSE_HELP,
                                                      GTK_STOCK_CLOSE, GTK_RESPONSE_OK,
@@ -211,6 +223,60 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 
   gtk_window_set_icon_name (GTK_WINDOW (dialog_gtk2), "preferences-system");
   gtk_window_set_type_hint (GTK_WINDOW (dialog_gtk2), GDK_WINDOW_TYPE_HINT_NORMAL);
+
+  g_signal_connect (dialog_gtk2, "response", G_CALLBACK (close_window), NULL);
+
+  gtk_widget_show_all (dialog_gtk2);
+G_GNUC_END_IGNORE_DEPRECATIONS
+}
+
+static void
+show_xfce_titled_dialog_new_with_mixed_buttons (GtkButton *button,
+                                                gpointer unused)
+{
+  GtkWidget *dialog_gtk2;
+
+#if GTK_CHECK_VERSION (3, 0, 0)
+  GtkWidget *dialog_gtk3;
+
+  dialog_gtk3 = xfce_titled_dialog_new_with_mixed_buttons ("Settings Editor (Gtk3)", NULL,
+                                                           GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                           "help-browser", "Help", GTK_RESPONSE_HELP,
+                                                           "window-close", "Close", GTK_RESPONSE_OK,
+                                                           "weather-snow", "Snow!", GTK_RESPONSE_APPLY,
+                                                           "", "no icon", GTK_RESPONSE_CANCEL,
+                                                           NULL);
+
+  xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (dialog_gtk3),
+                                   _("Customize settings stored by Xfconf"));
+
+  gtk_window_set_icon_name (GTK_WINDOW (dialog_gtk3), "preferences-system");
+  gtk_window_set_type_hint (GTK_WINDOW (dialog_gtk3), GDK_WINDOW_TYPE_HINT_NORMAL);
+
+  g_signal_connect (dialog_gtk3, "response", G_CALLBACK (close_window), NULL);
+
+  gtk_widget_show_all (dialog_gtk3);
+#endif
+
+/* ignore those warnings so it's easy to see what the default Gtk2 version
+ * looks like in Gtk3 with the stock icons */
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+  dialog_gtk2 = xfce_titled_dialog_new_with_mixed_buttons ("Settings Editor (Gtk2)", NULL,
+                                                           GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                           GTK_STOCK_HELP, "Help", GTK_RESPONSE_HELP,
+                                                           GTK_STOCK_CLOSE, "Close", GTK_RESPONSE_OK,
+                                                           "weather-snow", "Snow?", GTK_RESPONSE_APPLY,
+                                                           "", "no icon", GTK_RESPONSE_CANCEL,
+                                                           NULL);
+
+  xfce_titled_dialog_set_subtitle (XFCE_TITLED_DIALOG (dialog_gtk2),
+                                   _("Customize settings stored by Xfconf"));
+
+  gtk_window_set_icon_name (GTK_WINDOW (dialog_gtk2), "preferences-system");
+  gtk_window_set_type_hint (GTK_WINDOW (dialog_gtk2), GDK_WINDOW_TYPE_HINT_NORMAL);
+
+  g_signal_connect (dialog_gtk2, "response", G_CALLBACK (close_window), NULL);
+
   gtk_widget_show_all (dialog_gtk2);
 G_GNUC_END_IGNORE_DEPRECATIONS
 }
@@ -298,6 +364,12 @@ create_main_window (void)
   gtk_container_add (GTK_CONTAINER (box), button);
   gtk_widget_show (button);
   g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_xfce_titled_dialog_new_with_buttons), NULL);
+
+  /* xfce_titled_dialog_new_with_mixed_buttons */
+  button = gtk_button_new_with_label ("show xfce_titled_dialog_new_with_mixed_buttons");
+  gtk_container_add (GTK_CONTAINER (box), button);
+  gtk_widget_show (button);
+  g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (show_xfce_titled_dialog_new_with_mixed_buttons), NULL);
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list