[gtk/columnview-menu: 1/4] columnviewcolumn: Add a menu property



commit f27bd061fbfd0b69bd1110e1c380b017057519a3
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.

 docs/reference/gtk/gtk4-sections.txt |  3 ++
 gtk/gtkcolumnviewcolumn.c            | 65 ++++++++++++++++++++++++++++++++++++
 gtk/gtkcolumnviewcolumn.h            |  6 ++++
 3 files changed, 74 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index a2fb71fbfc..05011437d4 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -533,6 +533,9 @@ gtk_column_view_column_set_sorter
 gtk_column_view_column_get_sorter
 gtk_column_view_column_set_visible
 gtk_column_view_column_get_visible
+gtk_column_view_column_set_header_menu
+gtk_column_view_column_get_header_menu
+
 <SUBSECTION Standard>
 GTK_COLUMN_VIEW_COLUMN
 GTK_COLUMN_VIEW_COLUMN_CLASS
diff --git a/gtk/gtkcolumnviewcolumn.c b/gtk/gtkcolumnviewcolumn.c
index 5b61633d7a..d01cf0344e 100644
--- a/gtk/gtkcolumnviewcolumn.c
+++ b/gtk/gtkcolumnviewcolumn.c
@@ -63,6 +63,8 @@ struct _GtkColumnViewColumn
 
   gboolean visible;
 
+  GMenuModel *menu;
+
   /* This list isn't sorted - this is just caching for performance */
   GtkColumnViewCell *first_cell; /* no reference, just caching */
 };
@@ -80,6 +82,7 @@ enum
   PROP_TITLE,
   PROP_SORTER,
   PROP_VISIBLE,
+  PROP_HEADER_MENU,
 
   N_PROPS
 };
@@ -99,6 +102,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);
 }
@@ -133,6 +137,10 @@ gtk_column_view_column_get_property (GObject    *object,
       g_value_set_boolean (value, self->visible);
       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;
@@ -165,6 +173,10 @@ gtk_column_view_column_set_property (GObject      *object,
       gtk_column_view_column_set_visible (self, g_value_get_boolean (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;
@@ -240,6 +252,18 @@ gtk_column_view_column_class_init (GtkColumnViewColumnClass *klass)
                           TRUE,
                           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);
 }
 
@@ -723,3 +747,44 @@ gtk_column_view_column_get_visible (GtkColumnViewColumn *self)
 
   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;
+}
diff --git a/gtk/gtkcolumnviewcolumn.h b/gtk/gtkcolumnviewcolumn.h
index f0005809be..dbe27c48f6 100644
--- a/gtk/gtkcolumnviewcolumn.h
+++ b/gtk/gtkcolumnviewcolumn.h
@@ -78,6 +78,12 @@ void                    gtk_column_view_column_set_visible              (GtkColu
 GDK_AVAILABLE_IN_ALL
 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
 
 #endif  /* __GTK_COLUMN_VIEW_COLUMN_H__ */


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