]> Pileus Git - ~andy/gtk/commitdiff
Add a way to set the heading of GtkAppChooserDialog
authorMatthias Clasen <mclasen@redhat.com>
Fri, 21 Jan 2011 01:55:59 +0000 (20:55 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Fri, 21 Jan 2011 01:57:47 +0000 (20:57 -0500)
The application can probably set a better string than the default
we construct, like 'Select an application for "software" files'.

docs/reference/gtk/gtk3-sections.txt
gtk/gtk.symbols
gtk/gtkappchooserdialog.c
gtk/gtkappchooserdialog.h
tests/testappchooser.c

index 83d63b3c53c2762c8fa0fd4115df8b97e63583cf..585b044c67fd2ae3360c437893fdb97f368a2f49 100644 (file)
@@ -6982,6 +6982,8 @@ GtkAppChooserDialog
 gtk_app_chooser_dialog_new
 gtk_app_chooser_dialog_new_for_content_type
 gtk_app_chooser_dialog_get_widget
+gtk_app_chooser_dialog_set_heading
+gtk_app_chooser_dialog_get_heading
 
 <SUBSECTION Standard>
 GtkAppChooserDialogClass
index ebc3a39777aa36e236c44c2496b2b97b880a487a..ada6a645593a4a066ff15813c70e41fa0f6f14d6 100644 (file)
@@ -193,6 +193,8 @@ gtk_app_chooser_dialog_new
 gtk_app_chooser_dialog_new_for_content_type
 gtk_app_chooser_dialog_get_type G_GNUC_CONST
 gtk_app_chooser_dialog_get_widget
+gtk_app_chooser_dialog_get_heading
+gtk_app_chooser_dialog_set_heading
 gtk_app_chooser_widget_new
 gtk_app_chooser_widget_get_show_all
 gtk_app_chooser_widget_get_default_text
index 1814a6436765f8a8da16b1aae77ee27968c18d59..a722d472061867401e64a61b6128c6789f567087 100644 (file)
@@ -62,6 +62,7 @@
 struct _GtkAppChooserDialogPrivate {
   char *content_type;
   GFile *gfile;
+  char *heading;
 
   GtkWidget *label;
   GtkWidget *button;
@@ -80,6 +81,7 @@ struct _GtkAppChooserDialogPrivate {
 enum {
   PROP_GFILE = 1,
   PROP_CONTENT_TYPE,
+  PROP_HEADING,
   N_PROPERTIES
 };
 
@@ -348,10 +350,13 @@ set_dialog_properties (GtkAppChooserDialog *self)
 
   font_desc = pango_font_description_new ();
   pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
-  gtk_widget_modify_font (self->priv->label, font_desc);
+  gtk_widget_override_font (self->priv->label, font_desc);
   pango_font_description_free (font_desc);
 
-  gtk_label_set_markup (GTK_LABEL (self->priv->label), label);
+  if (self->priv->heading != NULL)
+    gtk_label_set_markup (GTK_LABEL (self->priv->label), self->priv->heading);
+  else
+    gtk_label_set_markup (GTK_LABEL (self->priv->label), label);
 
   default_text = g_strdup_printf ("<big><b>%s</b></big>\n%s",
                                   string,
@@ -621,6 +626,9 @@ gtk_app_chooser_dialog_set_property (GObject      *object,
       if (self->priv->content_type == NULL)
         self->priv->content_type = g_value_dup_string (value);
       break;
+    case PROP_HEADING:
+      gtk_app_chooser_dialog_set_heading (self, g_value_get_string (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -644,6 +652,9 @@ gtk_app_chooser_dialog_get_property (GObject    *object,
     case PROP_CONTENT_TYPE:
       g_value_set_string (value, self->priv->content_type);
       break;
+    case PROP_HEADING:
+      g_value_set_string (value, self->priv->heading);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -687,6 +698,20 @@ gtk_app_chooser_dialog_class_init (GtkAppChooserDialogClass *klass)
                                G_PARAM_STATIC_STRINGS);
   g_object_class_install_property (gobject_class, PROP_GFILE, pspec);
 
+  /**
+   * GtkAppChooserDialog:heading:
+   *
+   * The text to show at the top of the dialog.
+   * The string may contain Pango markup.
+   */
+  pspec = g_param_spec_string ("heading",
+                               P_("Heading"),
+                               P_("The text to show at the top of the dialog"),
+                               NULL,
+                               G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
+  g_object_class_install_property (gobject_class, PROP_HEADING, pspec);
+
+
   g_type_class_add_private (klass, sizeof (GtkAppChooserDialogPrivate));
 }
 
@@ -797,3 +822,43 @@ gtk_app_chooser_dialog_get_widget (GtkAppChooserDialog *self)
 
   return self->priv->app_chooser_widget;
 }
+
+/**
+ * gtk_app_chooser_dialog_set_heading:
+ * @self: a #GtkAppChooserDialog
+ * @heading: a string containing Pango markup
+ *
+ * Sets the text to display at the top of the dialog.
+ * If the heading is not set, the dialog displays a default text.
+ */
+void
+gtk_app_chooser_dialog_set_heading (GtkAppChooserDialog *self,
+                                    const gchar         *heading)
+{
+  g_return_if_fail (GTK_IS_APP_CHOOSER_DIALOG (self));
+
+  g_free (self->priv->heading);
+  self->priv->heading = g_strdup (heading);
+
+  if (self->priv->label && self->priv->heading)
+    gtk_label_set_markup (GTK_LABEL (self->priv->label), self->priv->heading);
+
+  g_object_notify (G_OBJECT (self), "heading");
+}
+
+/**
+ * gtk_app_chooser_dialog_get_heading:
+ * @self: a #GtkAppChooserDialog
+ *
+ * Returns the text to display at the top of the dialog.
+ *
+ * Returns: the text to display at the top of the dialog, or %NULL, in which
+ *     case a default text is displayed
+ */
+const gchar *
+gtk_app_chooser_dialog_get_heading (GtkAppChooserDialog *self)
+{
+  g_return_val_if_fail (GTK_IS_APP_CHOOSER_DIALOG (self), NULL);
+
+  return self->priv->heading;
+}
index bcb3dd97d44518354647512cebc1d61cda75492b..30f092e65287978e800289f584d811d2f5065139 100644 (file)
@@ -59,15 +59,18 @@ struct _GtkAppChooserDialogClass {
   gpointer padding[16];
 };
 
-GType       gtk_app_chooser_dialog_get_type             (void) G_GNUC_CONST;
+GType         gtk_app_chooser_dialog_get_type             (void) G_GNUC_CONST;
 
-GtkWidget * gtk_app_chooser_dialog_new                  (GtkWindow      *parent,
-                                                         GtkDialogFlags  flags,
-                                                         GFile          *file);
-GtkWidget * gtk_app_chooser_dialog_new_for_content_type (GtkWindow      *parent,
-                                                         GtkDialogFlags  flags,
-                                                         const gchar    *content_type);
+GtkWidget *   gtk_app_chooser_dialog_new                  (GtkWindow           *parent,
+                                                           GtkDialogFlags       flags,
+                                                           GFile               *file);
+GtkWidget *   gtk_app_chooser_dialog_new_for_content_type (GtkWindow           *parent,
+                                                           GtkDialogFlags       flags,
+                                                           const gchar         *content_type);
 
-GtkWidget * gtk_app_chooser_dialog_get_widget           (GtkAppChooserDialog *self);
+GtkWidget *   gtk_app_chooser_dialog_get_widget           (GtkAppChooserDialog *self);
+void          gtk_app_chooser_dialog_set_heading          (GtkAppChooserDialog *self,
+                                                           const gchar         *heading);
+const gchar * gtk_app_chooser_dialog_get_heading          (GtkAppChooserDialog *self);
 
 #endif /* __GTK_APP_CHOOSER_DIALOG_H__ */
index a50f1b4e4cfcd45d71e2bb98c0f58b73de358793..6bf121a68577ce340ed8844abf8f1e8077c5bc15 100644 (file)
@@ -98,6 +98,8 @@ prepare_dialog (void)
                                                             0, content_type);
     }
 
+  gtk_app_chooser_dialog_set_heading (GTK_APP_CHOOSER_DIALOG (dialog), "Select one already, you <i>fool</i>");
+
   g_signal_connect (dialog, "response",
                     G_CALLBACK (dialog_response), NULL);