[gtk/prop-list: 61/75] columnviewcolumn: Add a menu property



commit ea19482edc393b6f6e18e23de984ab637a8a7cc4
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Dec 21 22:20:42 2019 -0500

    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.

 gtk/gtkcolumnviewcolumn.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkcolumnviewcolumn.h |  5 ++++
 2 files changed, 70 insertions(+)
---
diff --git a/gtk/gtkcolumnviewcolumn.c b/gtk/gtkcolumnviewcolumn.c
index c18688d051..363cfb0a2a 100644
--- a/gtk/gtkcolumnviewcolumn.c
+++ b/gtk/gtkcolumnviewcolumn.c
@@ -68,6 +68,8 @@ struct _GtkColumnViewColumn
   guint resizable   : 1;
   guint reorderable : 1;
 
+  GMenuModel *menu;
+
   /* This list isn't sorted - this is just caching for performance */
   GtkColumnViewCell *first_cell; /* no reference, just caching */
 };
@@ -88,6 +90,7 @@ enum
   PROP_RESIZABLE,
   PROP_REORDERABLE,
   PROP_FIXED_WIDTH,
+  PROP_HEADER_MENU,
 
   N_PROPS
 };
@@ -107,6 +110,7 @@ gtk_column_view_column_dispose (GObject *object)
   g_clear_object (&self->factory);
   g_clear_object (&self->sorter);
   g_clear_pointer (&self->title, g_free);
+  g_clear_object (&self->menu);
 
   G_OBJECT_CLASS (gtk_column_view_column_parent_class)->dispose (object);
 }
@@ -153,6 +157,10 @@ gtk_column_view_column_get_property (GObject    *object,
       g_value_set_int (value, self->fixed_width);
       break;
 
+    case PROP_HEADER_MENU:
+      g_value_set_object (value, self->menu);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -197,6 +205,10 @@ gtk_column_view_column_set_property (GObject      *object,
       gtk_column_view_column_set_fixed_width (self, g_value_get_int (value));
       break;
 
+    case PROP_HEADER_MENU:
+      gtk_column_view_column_set_header_menu (self, g_value_get_object (value));
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
       break;
@@ -304,6 +316,18 @@ gtk_column_view_column_class_init (GtkColumnViewColumnClass *klass)
                       -1, G_MAXINT, -1,
                       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);
 }
 
@@ -962,3 +986,44 @@ gtk_column_view_column_get_header_allocation (GtkColumnViewColumn *self,
   if (size)
     *size = self->allocation_size;
 }
+
+/**
+ * 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;
+}
diff --git a/gtk/gtkcolumnviewcolumn.h b/gtk/gtkcolumnviewcolumn.h
index 5163cc587b..f2704c43d0 100644
--- a/gtk/gtkcolumnviewcolumn.h
+++ b/gtk/gtkcolumnviewcolumn.h
@@ -96,6 +96,11 @@ void                    gtk_column_view_column_set_reorderable          (GtkColu
 GDK_AVAILABLE_IN_ALL
 gboolean                gtk_column_view_column_get_reorderable          (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
 
 #endif  /* __GTK_COLUMN_VIEW_COLUMN_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]