columnviewcolumn: Add a menu property

Add a ::header-menu property that will be used
to create a context menu for the header of the
column.
This commit is contained in:
Matthias Clasen 2019-12-21 22:20:42 -05:00
parent 572386e4ce
commit f27bd061fb
3 changed files with 74 additions and 0 deletions

View File

@ -533,6 +533,9 @@ gtk_column_view_column_set_sorter
gtk_column_view_column_get_sorter gtk_column_view_column_get_sorter
gtk_column_view_column_set_visible gtk_column_view_column_set_visible
gtk_column_view_column_get_visible gtk_column_view_column_get_visible
gtk_column_view_column_set_header_menu
gtk_column_view_column_get_header_menu
<SUBSECTION Standard> <SUBSECTION Standard>
GTK_COLUMN_VIEW_COLUMN GTK_COLUMN_VIEW_COLUMN
GTK_COLUMN_VIEW_COLUMN_CLASS GTK_COLUMN_VIEW_COLUMN_CLASS

View File

@ -63,6 +63,8 @@ struct _GtkColumnViewColumn
gboolean visible; gboolean visible;
GMenuModel *menu;
/* This list isn't sorted - this is just caching for performance */ /* This list isn't sorted - this is just caching for performance */
GtkColumnViewCell *first_cell; /* no reference, just caching */ GtkColumnViewCell *first_cell; /* no reference, just caching */
}; };
@ -80,6 +82,7 @@ enum
PROP_TITLE, PROP_TITLE,
PROP_SORTER, PROP_SORTER,
PROP_VISIBLE, PROP_VISIBLE,
PROP_HEADER_MENU,
N_PROPS N_PROPS
}; };
@ -99,6 +102,7 @@ gtk_column_view_column_dispose (GObject *object)
g_clear_object (&self->factory); g_clear_object (&self->factory);
g_clear_object (&self->sorter); g_clear_object (&self->sorter);
g_clear_pointer (&self->title, g_free); g_clear_pointer (&self->title, g_free);
g_clear_object (&self->menu);
G_OBJECT_CLASS (gtk_column_view_column_parent_class)->dispose (object); G_OBJECT_CLASS (gtk_column_view_column_parent_class)->dispose (object);
} }
@ -133,6 +137,10 @@ gtk_column_view_column_get_property (GObject *object,
g_value_set_boolean (value, self->visible); g_value_set_boolean (value, self->visible);
break; break;
case PROP_HEADER_MENU:
g_value_set_object (value, self->menu);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -165,6 +173,10 @@ gtk_column_view_column_set_property (GObject *object,
gtk_column_view_column_set_visible (self, g_value_get_boolean (value)); gtk_column_view_column_set_visible (self, g_value_get_boolean (value));
break; break;
case PROP_HEADER_MENU:
gtk_column_view_column_set_header_menu (self, g_value_get_object (value));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
@ -240,6 +252,18 @@ gtk_column_view_column_class_init (GtkColumnViewColumnClass *klass)
TRUE, TRUE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GtkColumnViewColumn:header-menu:
*
* Menu model used to create the context menu for the column header.
*/
properties[PROP_HEADER_MENU] =
g_param_spec_object ("header-menu",
P_("Header menu"),
P_("Menu to use on the title of this column"),
G_TYPE_MENU_MODEL,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (gobject_class, N_PROPS, properties); g_object_class_install_properties (gobject_class, N_PROPS, properties);
} }
@ -723,3 +747,44 @@ gtk_column_view_column_get_visible (GtkColumnViewColumn *self)
return self->visible; return self->visible;
} }
/**
* gtk_column_view_column_set_header_menu:
* @self: a #GtkColumnViewColumn
* @menu: (allow-none): a #GMenuModel, or %NULL
*
* Sets the menu model that is used to create the context menu
* for the column header.
*/
void
gtk_column_view_column_set_header_menu (GtkColumnViewColumn *self,
GMenuModel *menu)
{
g_return_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self));
g_return_if_fail (menu == NULL || G_IS_MENU_MODEL (menu));
if (!g_set_object (&self->menu, menu))
return;
if (self->header)
gtk_column_view_title_update (GTK_COLUMN_VIEW_TITLE (self->header));
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_HEADER_MENU]);
}
/**
* gtk_column_view_column_get_header_menu:
* @self: a #GtkColumnViewColumn
*
* Gets the menu model that is used to create the context menu
* for the column header.
*
* Returns: the #GMenuModel, or %NULL
*/
GMenuModel *
gtk_column_view_column_get_header_menu (GtkColumnViewColumn *self)
{
g_return_val_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self), NULL);
return self->menu;
}

View File

@ -78,6 +78,12 @@ void gtk_column_view_column_set_visible (GtkColu
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gboolean gtk_column_view_column_get_visible (GtkColumnViewColumn *self); gboolean gtk_column_view_column_get_visible (GtkColumnViewColumn *self);
GDK_AVAILABLE_IN_ALL
void gtk_column_view_column_set_header_menu (GtkColumnViewColumn *self,
GMenuModel *menu);
GDK_AVAILABLE_IN_ALL
GMenuModel * gtk_column_view_column_get_header_menu (GtkColumnViewColumn *self);
G_END_DECLS G_END_DECLS
#endif /* __GTK_COLUMN_VIEW_COLUMN_H__ */ #endif /* __GTK_COLUMN_VIEW_COLUMN_H__ */