[gtk/prop-list: 6/8] column view column: Add a sorter property
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/prop-list: 6/8] column view column: Add a sorter property
- Date: Tue, 3 Dec 2019 17:59:05 +0000 (UTC)
commit 04d63c84237151c0115a515eede9eb999af68ae9
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Dec 3 02:26:02 2019 -0500
column view column: Add a sorter property
This will be used to implement sort by header click.
gtk/gtkcolumnviewcolumn.c | 41 +++++++++++++++++++++++++++++++++++++++++
gtk/gtkcolumnviewcolumn.h | 7 +++++++
2 files changed, 48 insertions(+)
---
diff --git a/gtk/gtkcolumnviewcolumn.c b/gtk/gtkcolumnviewcolumn.c
index 0898c54548..ac27cb1c00 100644
--- a/gtk/gtkcolumnviewcolumn.c
+++ b/gtk/gtkcolumnviewcolumn.c
@@ -32,6 +32,7 @@
#include "gtksizegroup.h"
#include "gtkstylecontext.h"
#include "gtkwidgetprivate.h"
+#include "gtksorter.h"
/**
* SECTION:gtkcolumnviewcolumn
@@ -48,6 +49,7 @@ struct _GtkColumnViewColumn
GtkListItemFactory *factory;
char *title;
+ GtkSorter *sorter;
/* data for the view */
GtkColumnView *view;
@@ -73,6 +75,7 @@ enum
PROP_COLUMN_VIEW,
PROP_FACTORY,
PROP_TITLE,
+ PROP_SORTER,
N_PROPS
};
@@ -117,6 +120,10 @@ gtk_column_view_column_get_property (GObject *object,
g_value_set_string (value, self->title);
break;
+ case PROP_SORTER:
+ g_value_set_object (value, self->sorter);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -141,6 +148,10 @@ gtk_column_view_column_set_property (GObject *object,
gtk_column_view_column_set_title (self, g_value_get_string (value));
break;
+ case PROP_SORTER:
+ gtk_column_view_column_set_sorter (self, g_value_get_object (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -192,6 +203,13 @@ gtk_column_view_column_class_init (GtkColumnViewColumnClass *klass)
NULL,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+ properties[PROP_SORTER] =
+ g_param_spec_object ("sorter",
+ P_("Sorter"),
+ P_("Sorter for sorting list items"),
+ GTK_TYPE_SORTER,
+ G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+
g_object_class_install_properties (gobject_class, N_PROPS, properties);
}
@@ -552,3 +570,26 @@ gtk_column_view_column_get_title (GtkColumnViewColumn *self)
return self->title;
}
+void
+gtk_column_view_column_set_sorter (GtkColumnViewColumn *self,
+ GtkSorter *sorter)
+{
+ g_return_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self));
+ g_return_if_fail (sorter == NULL || GTK_IS_SORTER (sorter));
+
+ if (!g_set_object (&self->sorter, sorter))
+ 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_SORTER]);
+}
+
+GtkSorter *
+gtk_column_view_column_get_sorter (GtkColumnViewColumn *self)
+{
+ g_return_val_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (self), NULL);
+
+ return self->sorter;
+}
diff --git a/gtk/gtkcolumnviewcolumn.h b/gtk/gtkcolumnviewcolumn.h
index 612cdb1854..f74cedaa08 100644
--- a/gtk/gtkcolumnviewcolumn.h
+++ b/gtk/gtkcolumnviewcolumn.h
@@ -25,6 +25,7 @@
#endif
#include <gtk/gtkcolumnview.h>
+#include <gtk/gtksorter.h>
G_BEGIN_DECLS
@@ -65,6 +66,12 @@ void gtk_column_view_column_set_title (GtkColu
GDK_AVAILABLE_IN_ALL
const char * gtk_column_view_column_get_title (GtkColumnViewColumn *self);
+GDK_AVAILABLE_IN_ALL
+void gtk_column_view_column_set_sorter (GtkColumnViewColumn *self,
+ GtkSorter *sorter);
+GDK_AVAILABLE_IN_ALL
+GtkSorter * gtk_column_view_column_get_sorter (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]