[gtk/prop-list] columnview: Add column reordering



commit ff4caecff033ec4326508e578c67b19aabf9b560
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Dec 18 02:19:48 2019 -0500

    columnview: Add column reordering
    
    Add an API to allow reordering columns.

 gtk/gtkcolumnview.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkcolumnview.h |  8 +++++++
 2 files changed, 70 insertions(+)
---
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
index 745af7dc08..155003437c 100644
--- a/gtk/gtkcolumnview.c
+++ b/gtk/gtkcolumnview.c
@@ -724,6 +724,7 @@ gtk_column_view_remove_column (GtkColumnView       *self,
       g_object_unref (item);
       if (item == column)
         break;
+
     }
 
   gtk_column_view_sorter_remove_column (GTK_COLUMN_VIEW_SORTER (self->sorter), column);
@@ -731,6 +732,67 @@ gtk_column_view_remove_column (GtkColumnView       *self,
   g_list_store_remove (self->columns, i);
 }
 
+static void
+gtk_column_view_insert_column (GtkColumnView       *self,
+                               GtkColumnViewColumn *column,
+                               GtkColumnViewColumn *sibling,
+                               gboolean             after)
+{
+  int i, c, s;
+
+  g_return_if_fail (GTK_IS_COLUMN_VIEW (self));
+  g_return_if_fail (GTK_IS_COLUMN_VIEW_COLUMN (column));
+  g_return_if_fail (gtk_column_view_column_get_column_view (column) == self ||
+                    gtk_column_view_column_get_column_view (column) == NULL);
+  g_return_if_fail (gtk_column_view_column_get_column_view (sibling) == self);
+
+  s = c = -1;
+  for (i = 0; i < g_list_model_get_n_items (G_LIST_MODEL (self->columns)); i++)
+    {
+      GtkColumnViewColumn *item = g_list_model_get_item (G_LIST_MODEL (self->columns), i);
+
+      if (item == sibling)
+        s = i;
+      if (item == column)
+        c = i;
+
+      g_object_unref (item);
+    }
+
+  if (after)
+    s++;
+
+  gtk_column_view_column_set_column_view (column, self);
+
+  g_object_ref (column);
+  if (c != -1)
+    {
+      g_list_store_remove (self->columns, c);
+      if (s > c)
+        s--;
+    }
+  g_list_store_insert (self->columns, s, column);
+  g_object_unref (column);
+
+  gtk_column_view_column_queue_resize (column);
+}
+
+void
+gtk_column_view_insert_column_before (GtkColumnView       *self,
+                                      GtkColumnViewColumn *column,
+                                      GtkColumnViewColumn *sibling)
+{
+  gtk_column_view_insert_column (self, column, sibling, FALSE);
+}
+
+void
+gtk_column_view_insert_column_after (GtkColumnView       *self,
+                                     GtkColumnViewColumn *column,
+                                     GtkColumnViewColumn *sibling)
+{
+  gtk_column_view_insert_column (self, column, sibling, TRUE);
+}
+
 void
 gtk_column_view_measure_across (GtkColumnView *self,
                                 int           *minimum,
diff --git a/gtk/gtkcolumnview.h b/gtk/gtkcolumnview.h
index fd0e99a4d3..b63f9ee676 100644
--- a/gtk/gtkcolumnview.h
+++ b/gtk/gtkcolumnview.h
@@ -61,6 +61,14 @@ void            gtk_column_view_append_column                   (GtkColumnView
 GDK_AVAILABLE_IN_ALL
 void            gtk_column_view_remove_column                   (GtkColumnView          *self,
                                                                  GtkColumnViewColumn    *column);
+GDK_AVAILABLE_IN_ALL
+void            gtk_column_view_insert_column_before            (GtkColumnView          *self,
+                                                                 GtkColumnViewColumn    *column,
+                                                                 GtkColumnViewColumn    *sibling);
+GDK_AVAILABLE_IN_ALL
+void            gtk_column_view_insert_column_after             (GtkColumnView          *self,
+                                                                 GtkColumnViewColumn    *column,
+                                                                 GtkColumnViewColumn    *sibling);
 
 GDK_AVAILABLE_IN_ALL
 GListModel *    gtk_column_view_get_model                       (GtkColumnView          *self);


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