Commit a7bcb8a4 authored by Matthias Clasen's avatar Matthias Clasen

Add a way to set the heading of GtkAppChooserDialog

The application can probably set a better string than the default
we construct, like 'Select an application for "software" files'.
parent ec750bed
......@@ -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
......
......@@ -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
......
......@@ -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;
}
......@@ -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__ */
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment