diff options
author | Matthias Clasen <mclasen@redhat.com> | 2022-10-20 13:37:26 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2022-10-20 13:57:33 -0400 |
commit | 9ed1505073406db8e0635dffd25fbf245cfe1596 (patch) | |
tree | 42b2024943fb5ed70213ca3574edeae9be6e73d6 | |
parent | e040d3663eb17f8400e667ef9d1fa045c8656f9c (diff) | |
download | gtk+-9ed1505073406db8e0635dffd25fbf245cfe1596.tar.gz |
columnviewtitle: Clean up interactions
Separate the apis we use for updating title,
menu and sort indicator.
-rw-r--r-- | gtk/gtkcolumnviewcolumn.c | 8 | ||||
-rw-r--r-- | gtk/gtkcolumnviewtitle.c | 43 | ||||
-rw-r--r-- | gtk/gtkcolumnviewtitleprivate.h | 7 |
3 files changed, 37 insertions, 21 deletions
diff --git a/gtk/gtkcolumnviewcolumn.c b/gtk/gtkcolumnviewcolumn.c index 9ff589e5d8..715248f1c8 100644 --- a/gtk/gtkcolumnviewcolumn.c +++ b/gtk/gtkcolumnviewcolumn.c @@ -706,7 +706,7 @@ gtk_column_view_column_set_title (GtkColumnViewColumn *self, self->title = g_strdup (title); if (self->header) - gtk_column_view_title_update (GTK_COLUMN_VIEW_TITLE (self->header)); + gtk_column_view_title_set_title (GTK_COLUMN_VIEW_TITLE (self->header), title); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TITLE]); } @@ -765,7 +765,7 @@ gtk_column_view_column_set_sorter (GtkColumnViewColumn *self, gtk_column_view_column_remove_from_sorter (self); if (self->header) - gtk_column_view_title_update (GTK_COLUMN_VIEW_TITLE (self->header)); + gtk_column_view_title_update_sort (GTK_COLUMN_VIEW_TITLE (self->header)); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SORTER]); } @@ -790,7 +790,7 @@ void gtk_column_view_column_notify_sort (GtkColumnViewColumn *self) { if (self->header) - gtk_column_view_title_update (GTK_COLUMN_VIEW_TITLE (self->header)); + gtk_column_view_title_update_sort (GTK_COLUMN_VIEW_TITLE (self->header)); } /** @@ -862,7 +862,7 @@ gtk_column_view_column_set_header_menu (GtkColumnViewColumn *self, return; if (self->header) - gtk_column_view_title_update (GTK_COLUMN_VIEW_TITLE (self->header)); + gtk_column_view_title_set_menu (GTK_COLUMN_VIEW_TITLE (self->header), menu); g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_HEADER_MENU]); } diff --git a/gtk/gtkcolumnviewtitle.c b/gtk/gtkcolumnviewtitle.c index cb75bc1d74..f2a3cae45f 100644 --- a/gtk/gtkcolumnviewtitle.c +++ b/gtk/gtkcolumnviewtitle.c @@ -283,45 +283,56 @@ gtk_column_view_title_new (GtkColumnViewColumn *column) title = g_object_new (GTK_TYPE_COLUMN_VIEW_TITLE, NULL); title->column = g_object_ref (column); - gtk_column_view_title_update (title); + gtk_column_view_title_update_sort (title); + gtk_column_view_title_set_title (title, gtk_column_view_column_get_title (column)); + gtk_column_view_title_set_menu (title, gtk_column_view_column_get_header_menu (column)); return GTK_WIDGET (title); } void -gtk_column_view_title_update (GtkColumnViewTitle *self) +gtk_column_view_title_set_title (GtkColumnViewTitle *self, + const char *title) { - GtkSorter *sorter; - GtkColumnView *view; - GtkColumnViewSorter *view_sorter; - gboolean inverted; - GtkColumnViewColumn *active; - - gtk_label_set_label (GTK_LABEL (self->title), gtk_column_view_column_get_title (self->column)); + gtk_label_set_label (GTK_LABEL (self->title), title); +} - sorter = gtk_column_view_column_get_sorter (self->column); +void +gtk_column_view_title_set_menu (GtkColumnViewTitle *self, + GMenuModel *model) +{ + g_clear_pointer (&self->popup_menu, gtk_widget_unparent); +} - if (sorter) +void +gtk_column_view_title_update_sort (GtkColumnViewTitle *self) +{ + if (gtk_column_view_column_get_sorter (self->column)) { + GtkColumnView *view; + GtkColumnViewSorter *view_sorter; + GtkColumnViewColumn *primary; + GtkSortType sort_order; + view = gtk_column_view_column_get_column_view (self->column); view_sorter = GTK_COLUMN_VIEW_SORTER (gtk_column_view_get_sorter (view)); - active = gtk_column_view_sorter_get_sort_column (view_sorter, &inverted); + primary = gtk_column_view_sorter_get_primary_sort_column (view_sorter); + sort_order = gtk_column_view_sorter_get_primary_sort_order (view_sorter); gtk_widget_show (self->sort); gtk_widget_remove_css_class (self->sort, "ascending"); gtk_widget_remove_css_class (self->sort, "descending"); gtk_widget_remove_css_class (self->sort, "unsorted"); - if (self->column != active) + + if (self->column != primary) gtk_widget_add_css_class (self->sort, "unsorted"); - else if (inverted) + else if (sort_order == GTK_SORT_DESCENDING) gtk_widget_add_css_class (self->sort, "descending"); else gtk_widget_add_css_class (self->sort, "ascending"); } else gtk_widget_hide (self->sort); - - g_clear_pointer (&self->popup_menu, gtk_widget_unparent); } GtkColumnViewColumn * diff --git a/gtk/gtkcolumnviewtitleprivate.h b/gtk/gtkcolumnviewtitleprivate.h index 84bc6a4050..dae569f55a 100644 --- a/gtk/gtkcolumnviewtitleprivate.h +++ b/gtk/gtkcolumnviewtitleprivate.h @@ -38,7 +38,12 @@ GType gtk_column_view_title_get_type (void) G_GNUC_CO GtkWidget * gtk_column_view_title_new (GtkColumnViewColumn *column); -void gtk_column_view_title_update (GtkColumnViewTitle *self); +void gtk_column_view_title_set_title (GtkColumnViewTitle *self, + const char *title); +void gtk_column_view_title_set_menu (GtkColumnViewTitle *self, + GMenuModel *model); + +void gtk_column_view_title_update_sort (GtkColumnViewTitle *self); GtkColumnViewColumn * gtk_column_view_title_get_column (GtkColumnViewTitle *self); |