Allow GtkAppChooser classes to be instantiated with content-type=NULL.
Mostly for corner cases such as Glade that treats objects generically and needs to have an object that doesnt crash out of g_object_new().
This commit is contained in:
parent
0e608f1b1f
commit
c844a24ae6
@ -248,7 +248,7 @@ gtk_app_chooser_button_ensure_dialog_item (GtkAppChooserButton *self,
|
|||||||
{
|
{
|
||||||
GtkTreeIter iter, iter2;
|
GtkTreeIter iter, iter2;
|
||||||
|
|
||||||
if (!self->priv->show_dialog_item)
|
if (!self->priv->show_dialog_item || !self->priv->content_type)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (prev_iter == NULL)
|
if (prev_iter == NULL)
|
||||||
@ -275,6 +275,7 @@ gtk_app_chooser_button_populate (GtkAppChooserButton *self)
|
|||||||
gboolean cycled_recommended;
|
gboolean cycled_recommended;
|
||||||
|
|
||||||
#ifndef G_OS_WIN32
|
#ifndef G_OS_WIN32
|
||||||
|
if (self->priv->content_type)
|
||||||
recommended_apps = g_app_info_get_recommended_for_type (self->priv->content_type);
|
recommended_apps = g_app_info_get_recommended_for_type (self->priv->content_type);
|
||||||
#endif
|
#endif
|
||||||
cycled_recommended = FALSE;
|
cycled_recommended = FALSE;
|
||||||
@ -325,14 +326,6 @@ gtk_app_chooser_button_build_ui (GtkAppChooserButton *self)
|
|||||||
GtkCellRenderer *cell;
|
GtkCellRenderer *cell;
|
||||||
GtkCellArea *area;
|
GtkCellArea *area;
|
||||||
|
|
||||||
self->priv->store = gtk_list_store_new (NUM_COLUMNS,
|
|
||||||
G_TYPE_APP_INFO,
|
|
||||||
G_TYPE_STRING, /* name */
|
|
||||||
G_TYPE_STRING, /* label */
|
|
||||||
G_TYPE_ICON,
|
|
||||||
G_TYPE_BOOLEAN, /* separator */
|
|
||||||
G_TYPE_BOOLEAN); /* custom */
|
|
||||||
|
|
||||||
gtk_combo_box_set_model (GTK_COMBO_BOX (self),
|
gtk_combo_box_set_model (GTK_COMBO_BOX (self),
|
||||||
GTK_TREE_MODEL (self->priv->store));
|
GTK_TREE_MODEL (self->priv->store));
|
||||||
|
|
||||||
@ -457,8 +450,6 @@ gtk_app_chooser_button_constructed (GObject *obj)
|
|||||||
if (G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->constructed != NULL)
|
if (G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->constructed != NULL)
|
||||||
G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->constructed (obj);
|
G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->constructed (obj);
|
||||||
|
|
||||||
g_assert (self->priv->content_type != NULL);
|
|
||||||
|
|
||||||
gtk_app_chooser_button_build_ui (self);
|
gtk_app_chooser_button_build_ui (self);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -521,6 +512,8 @@ gtk_app_chooser_button_finalize (GObject *obj)
|
|||||||
g_free (self->priv->content_type);
|
g_free (self->priv->content_type);
|
||||||
g_free (self->priv->heading);
|
g_free (self->priv->heading);
|
||||||
|
|
||||||
|
g_object_unref (self->priv->store);
|
||||||
|
|
||||||
G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->finalize (obj);
|
G_OBJECT_CLASS (gtk_app_chooser_button_parent_class)->finalize (obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -605,6 +598,14 @@ gtk_app_chooser_button_init (GtkAppChooserButton *self)
|
|||||||
self->priv->custom_item_names =
|
self->priv->custom_item_names =
|
||||||
g_hash_table_new_full (g_str_hash, g_str_equal,
|
g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
g_free, NULL);
|
g_free, NULL);
|
||||||
|
|
||||||
|
self->priv->store = gtk_list_store_new (NUM_COLUMNS,
|
||||||
|
G_TYPE_APP_INFO,
|
||||||
|
G_TYPE_STRING, /* name */
|
||||||
|
G_TYPE_STRING, /* label */
|
||||||
|
G_TYPE_ICON,
|
||||||
|
G_TYPE_BOOLEAN, /* separator */
|
||||||
|
G_TYPE_BOOLEAN); /* custom */
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -170,6 +170,10 @@ app_chooser_online_get_default_ready_cb (GObject *source,
|
|||||||
g_signal_connect (self->priv->online_button, "clicked",
|
g_signal_connect (self->priv->online_button, "clicked",
|
||||||
G_CALLBACK (online_button_clicked_cb), self);
|
G_CALLBACK (online_button_clicked_cb), self);
|
||||||
|
|
||||||
|
|
||||||
|
if (!self->priv->content_type)
|
||||||
|
gtk_widget_set_sensitive (self->priv->online_button, FALSE);
|
||||||
|
|
||||||
gtk_widget_show (self->priv->online_button);
|
gtk_widget_show (self->priv->online_button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -247,6 +251,7 @@ add_or_find_application (GtkAppChooserDialog *self)
|
|||||||
app = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self));
|
app = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self));
|
||||||
|
|
||||||
/* we don't care about reporting errors here */
|
/* we don't care about reporting errors here */
|
||||||
|
if (self->priv->content_type)
|
||||||
g_app_info_set_as_last_used_for_type (app,
|
g_app_info_set_as_last_used_for_type (app,
|
||||||
self->priv->content_type,
|
self->priv->content_type,
|
||||||
NULL);
|
NULL);
|
||||||
@ -313,12 +318,14 @@ set_dialog_properties (GtkAppChooserDialog *self)
|
|||||||
gchar *description;
|
gchar *description;
|
||||||
gchar *default_text;
|
gchar *default_text;
|
||||||
gchar *string;
|
gchar *string;
|
||||||
|
gboolean unknown;
|
||||||
PangoFontDescription *font_desc;
|
PangoFontDescription *font_desc;
|
||||||
|
|
||||||
name = NULL;
|
name = NULL;
|
||||||
extension = NULL;
|
extension = NULL;
|
||||||
label = NULL;
|
label = NULL;
|
||||||
description = NULL;
|
description = NULL;
|
||||||
|
unknown = TRUE;
|
||||||
|
|
||||||
if (self->priv->gfile != NULL)
|
if (self->priv->gfile != NULL)
|
||||||
{
|
{
|
||||||
@ -326,7 +333,12 @@ set_dialog_properties (GtkAppChooserDialog *self)
|
|||||||
extension = get_extension (name);
|
extension = get_extension (name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (self->priv->content_type)
|
||||||
|
{
|
||||||
description = g_content_type_get_description (self->priv->content_type);
|
description = g_content_type_get_description (self->priv->content_type);
|
||||||
|
unknown = g_content_type_is_unknown (self->priv->content_type);
|
||||||
|
}
|
||||||
|
|
||||||
gtk_window_set_title (GTK_WINDOW (self), "");
|
gtk_window_set_title (GTK_WINDOW (self), "");
|
||||||
|
|
||||||
if (name != NULL)
|
if (name != NULL)
|
||||||
@ -340,11 +352,9 @@ set_dialog_properties (GtkAppChooserDialog *self)
|
|||||||
{
|
{
|
||||||
/* Translators: %s is a file type description */
|
/* Translators: %s is a file type description */
|
||||||
label = g_strdup_printf (_("Select an application for \"%s\" files"),
|
label = g_strdup_printf (_("Select an application for \"%s\" files"),
|
||||||
g_content_type_is_unknown (self->priv->content_type) ?
|
unknown ? self->priv->content_type : description);
|
||||||
self->priv->content_type : description);
|
|
||||||
string = g_strdup_printf (_("No applications available to open \"%s\" files"),
|
string = g_strdup_printf (_("No applications available to open \"%s\" files"),
|
||||||
g_content_type_is_unknown (self->priv->content_type) ?
|
unknown ? self->priv->content_type : description);
|
||||||
self->priv->content_type : description);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
font_desc = pango_font_description_new ();
|
font_desc = pango_font_description_new ();
|
||||||
@ -575,9 +585,6 @@ gtk_app_chooser_dialog_constructed (GObject *object)
|
|||||||
{
|
{
|
||||||
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
GtkAppChooserDialog *self = GTK_APP_CHOOSER_DIALOG (object);
|
||||||
|
|
||||||
g_assert (self->priv->content_type != NULL ||
|
|
||||||
self->priv->gfile != NULL);
|
|
||||||
|
|
||||||
if (G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->constructed != NULL)
|
if (G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->constructed != NULL)
|
||||||
G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->constructed (object);
|
G_OBJECT_CLASS (gtk_app_chooser_dialog_parent_class)->constructed (object);
|
||||||
|
|
||||||
|
@ -630,13 +630,15 @@ gtk_app_chooser_add_default (GtkAppChooserWidget *self,
|
|||||||
static void
|
static void
|
||||||
add_no_applications_label (GtkAppChooserWidget *self)
|
add_no_applications_label (GtkAppChooserWidget *self)
|
||||||
{
|
{
|
||||||
gchar *text = NULL, *desc;
|
gchar *text = NULL, *desc = NULL;
|
||||||
const gchar *string;
|
const gchar *string;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
|
|
||||||
if (self->priv->default_text == NULL)
|
if (self->priv->default_text == NULL)
|
||||||
{
|
{
|
||||||
|
if (self->priv->content_type)
|
||||||
desc = g_content_type_get_description (self->priv->content_type);
|
desc = g_content_type_get_description (self->priv->content_type);
|
||||||
|
|
||||||
string = text = g_strdup_printf (_("No applications available to open \"%s\""),
|
string = text = g_strdup_printf (_("No applications available to open \"%s\""),
|
||||||
desc);
|
desc);
|
||||||
g_free (desc);
|
g_free (desc);
|
||||||
@ -706,7 +708,7 @@ gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self)
|
|||||||
if (self->priv->show_all)
|
if (self->priv->show_all)
|
||||||
show_headings = FALSE;
|
show_headings = FALSE;
|
||||||
|
|
||||||
if (self->priv->show_default)
|
if (self->priv->show_default && self->priv->content_type)
|
||||||
{
|
{
|
||||||
default_app = g_app_info_get_default_for_type (self->priv->content_type, FALSE);
|
default_app = g_app_info_get_default_for_type (self->priv->content_type, FALSE);
|
||||||
|
|
||||||
@ -719,8 +721,9 @@ gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifndef G_OS_WIN32
|
#ifndef G_OS_WIN32
|
||||||
if (self->priv->show_recommended || self->priv->show_all)
|
if ((self->priv->content_type && self->priv->show_recommended) || self->priv->show_all)
|
||||||
{
|
{
|
||||||
|
if (self->priv->content_type)
|
||||||
recommended_apps = g_app_info_get_recommended_for_type (self->priv->content_type);
|
recommended_apps = g_app_info_get_recommended_for_type (self->priv->content_type);
|
||||||
|
|
||||||
apps_added |= gtk_app_chooser_widget_add_section (self, _("Recommended Applications"),
|
apps_added |= gtk_app_chooser_widget_add_section (self, _("Recommended Applications"),
|
||||||
@ -733,8 +736,9 @@ gtk_app_chooser_widget_real_add_items (GtkAppChooserWidget *self)
|
|||||||
g_list_copy (recommended_apps));
|
g_list_copy (recommended_apps));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self->priv->show_fallback || self->priv->show_all)
|
if ((self->priv->content_type && self->priv->show_fallback) || self->priv->show_all)
|
||||||
{
|
{
|
||||||
|
if (self->priv->content_type)
|
||||||
fallback_apps = g_app_info_get_fallback_for_type (self->priv->content_type);
|
fallback_apps = g_app_info_get_fallback_for_type (self->priv->content_type);
|
||||||
|
|
||||||
apps_added |= gtk_app_chooser_widget_add_section (self, _("Related Applications"),
|
apps_added |= gtk_app_chooser_widget_add_section (self, _("Related Applications"),
|
||||||
@ -953,8 +957,6 @@ gtk_app_chooser_widget_constructed (GObject *object)
|
|||||||
{
|
{
|
||||||
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
|
GtkAppChooserWidget *self = GTK_APP_CHOOSER_WIDGET (object);
|
||||||
|
|
||||||
g_assert (self->priv->content_type != NULL);
|
|
||||||
|
|
||||||
if (G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->constructed != NULL)
|
if (G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->constructed != NULL)
|
||||||
G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->constructed (object);
|
G_OBJECT_CLASS (gtk_app_chooser_widget_parent_class)->constructed (object);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user