[gtk/prop-list: 1/3] column view title: Add sort indicators
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/prop-list: 1/3] column view title: Add sort indicators
- Date: Tue, 3 Dec 2019 20:12:16 +0000 (UTC)
commit 42ce1b752276a0126704860d9ec858189c8aa98a
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Dec 3 02:26:33 2019 -0500
column view title: Add sort indicators
And make the titles clickable to change sort.
gtk/gtkcolumnview.c | 8 +++++
gtk/gtkcolumnviewcolumn.c | 7 ++++
gtk/gtkcolumnviewcolumnprivate.h | 1 +
gtk/gtkcolumnviewtitle.c | 75 +++++++++++++++++++++++++++++++++++++---
4 files changed, 87 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
index 0f48c2e183..2995b236bc 100644
--- a/gtk/gtkcolumnview.c
+++ b/gtk/gtkcolumnview.c
@@ -739,6 +739,8 @@ void
gtk_column_view_set_sorter (GtkColumnView *self,
GtkSorter *sorter)
{
+ int i;
+
g_return_if_fail (GTK_IS_COLUMN_VIEW (self));
g_return_if_fail (sorter == NULL || GTK_IS_SORTER (sorter));
@@ -748,6 +750,12 @@ gtk_column_view_set_sorter (GtkColumnView *self,
if (self->sort_model)
gtk_sort_list_model_set_sorter (self->sort_model, self->sorter);
+ for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (self->columns)); i++)
+ {
+ GtkColumnViewColumn *column = g_list_model_get_item (G_LIST_MODEL (self->columns), i);
+ gtk_column_view_column_active_sorter_changed (column);
+ }
+
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SORTER]);
}
diff --git a/gtk/gtkcolumnviewcolumn.c b/gtk/gtkcolumnviewcolumn.c
index ac27cb1c00..7cfbb1a5ce 100644
--- a/gtk/gtkcolumnviewcolumn.c
+++ b/gtk/gtkcolumnviewcolumn.c
@@ -593,3 +593,10 @@ gtk_column_view_column_get_sorter (GtkColumnViewColumn *self)
return self->sorter;
}
+
+void
+gtk_column_view_column_active_sorter_changed (GtkColumnViewColumn *self)
+{
+ if (self->header)
+ gtk_column_view_title_update (GTK_COLUMN_VIEW_TITLE (self->header));
+}
diff --git a/gtk/gtkcolumnviewcolumnprivate.h b/gtk/gtkcolumnviewcolumnprivate.h
index d7e06a5b0f..3df2958c07 100644
--- a/gtk/gtkcolumnviewcolumnprivate.h
+++ b/gtk/gtkcolumnviewcolumnprivate.h
@@ -43,5 +43,6 @@ void gtk_column_view_column_allocate (GtkColu
void gtk_column_view_column_get_allocation (GtkColumnViewColumn *self,
int *offset,
int *size);
+void gtk_column_view_column_active_sorter_changed (GtkColumnViewColumn *self);
#endif /* __GTK_COLUMN_VIEW_COLUMN_PRIVATE_H__ */
diff --git a/gtk/gtkcolumnviewtitle.c b/gtk/gtkcolumnviewtitle.c
index 7170018eb4..69063f9be0 100644
--- a/gtk/gtkcolumnviewtitle.c
+++ b/gtk/gtkcolumnviewtitle.c
@@ -25,6 +25,9 @@
#include "gtkintl.h"
#include "gtklabel.h"
#include "gtkwidgetprivate.h"
+#include "gtkbox.h"
+#include "gtkimage.h"
+#include "gtkgestureclick.h"
struct _GtkColumnViewTitle
{
@@ -32,7 +35,9 @@ struct _GtkColumnViewTitle
GtkColumnViewColumn *column;
+ GtkWidget *box;
GtkWidget *title;
+ GtkWidget *sort;
};
struct _GtkColumnViewTitleClass
@@ -74,7 +79,7 @@ gtk_column_view_title_dispose (GObject *object)
{
GtkColumnViewTitle *self = GTK_COLUMN_VIEW_TITLE (object);
- g_clear_pointer(&self->title, gtk_widget_unparent);
+ g_clear_pointer (&self->box, gtk_widget_unparent);
g_clear_object (&self->column);
@@ -104,15 +109,56 @@ gtk_column_view_title_resize_func (GtkWidget *widget)
gtk_column_view_column_queue_resize (self->column);
}
+static void
+click_pressed_cb (GtkGestureClick *gesture,
+ guint n_press,
+ gdouble x,
+ gdouble y,
+ GtkWidget *widget)
+{
+ GtkColumnViewTitle *self = GTK_COLUMN_VIEW_TITLE (widget);
+ GtkSorter *sorter;
+ GtkSorter *active_sorter;
+
+ sorter = gtk_column_view_column_get_sorter (self->column);
+ active_sorter = gtk_column_view_get_sorter (gtk_column_view_column_get_column_view (self->column));
+
+ if (sorter)
+ {
+ if (sorter == active_sorter)
+ {
+ gtk_sorter_set_sort_direction (sorter, 1 - gtk_sorter_get_sort_direction (sorter));
+ }
+ else
+ {
+ gtk_sorter_set_sort_direction (sorter, GTK_SORT_ASCENDING);
+ gtk_column_view_set_sorter (gtk_column_view_column_get_column_view (self->column), sorter);
+ }
+ }
+
+ gtk_column_view_title_update (self);
+}
+
static void
gtk_column_view_title_init (GtkColumnViewTitle *self)
{
GtkWidget *widget = GTK_WIDGET (self);
+ GtkGesture *gesture;
widget->priv->resize_func = gtk_column_view_title_resize_func;
+ self->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ gtk_widget_set_parent (self->box, widget);
+
self->title = gtk_label_new (NULL);
- gtk_widget_set_parent (self->title, widget);
+ gtk_container_add (GTK_CONTAINER (self->box), self->title);
+
+ self->sort = gtk_image_new ();
+ gtk_container_add (GTK_CONTAINER (self->box), self->sort);
+
+ gesture = gtk_gesture_click_new ();
+ g_signal_connect (gesture, "pressed", G_CALLBACK (click_pressed_cb), self);
+ gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture));
}
GtkWidget *
@@ -120,8 +166,7 @@ gtk_column_view_title_new (GtkColumnViewColumn *column)
{
GtkColumnViewTitle *title;
- title = g_object_new (GTK_TYPE_COLUMN_VIEW_TITLE,
- NULL);
+ title = g_object_new (GTK_TYPE_COLUMN_VIEW_TITLE, NULL);
title->column = g_object_ref (column);
gtk_column_view_title_update (title);
@@ -132,7 +177,29 @@ gtk_column_view_title_new (GtkColumnViewColumn *column)
void
gtk_column_view_title_update (GtkColumnViewTitle *self)
{
+ GtkSorter *sorter;
+ GtkSorter *active_sorter;
+
gtk_label_set_label (GTK_LABEL (self->title), gtk_column_view_column_get_title (self->column));
+
+ sorter = gtk_column_view_column_get_sorter (self->column);
+ active_sorter = gtk_column_view_get_sorter (gtk_column_view_column_get_column_view (self->column));
+
+ if (sorter)
+ {
+ gtk_widget_show (self->sort);
+ if (sorter == active_sorter)
+ {
+ if (gtk_sorter_get_sort_direction (sorter) == GTK_SORT_ASCENDING)
+ gtk_image_set_from_icon_name (GTK_IMAGE (self->sort), "pan-down-symbolic");
+ else
+ gtk_image_set_from_icon_name (GTK_IMAGE (self->sort), "pan-up-symbolic");
+ }
+ else
+ gtk_image_clear (GTK_IMAGE (self->sort));
+ }
+ else
+ gtk_widget_hide (self->sort);
}
GtkColumnViewColumn *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]