[gtk/matthiasc/for-master: 5/5] columnview: Add column reordering



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

 docs/reference/gtk/gtk4-sections.txt |  1 +
 gtk/gtkcolumnview.c                  | 50 ++++++++++++++++++++++++++++++++++++
 gtk/gtkcolumnview.h                  |  4 +++
 3 files changed, 55 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 8d98f71601..a2fb71fbfc 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -496,6 +496,7 @@ gtk_list_view_get_type
 GtkColumnView
 gtk_column_view_new
 gtk_column_view_append_column
+gtk_column_view_insert_column
 gtk_column_view_remove_column
 gtk_column_view_get_columns
 gtk_column_view_get_model
diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c
index 7ae41f8b1c..e94875ae71 100644
--- a/gtk/gtkcolumnview.c
+++ b/gtk/gtkcolumnview.c
@@ -691,6 +691,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);
@@ -698,6 +699,55 @@ gtk_column_view_remove_column (GtkColumnView       *self,
   g_list_store_remove (self->columns, i);
 }
 
+/**
+ * gtk_column_view_insert_column:
+ * @self: a #GtkColumnView
+ * @position: the position to insert @column at
+ * @column: the #GtkColumnViewColumn to insert
+ *
+ * Inserts a column at the given position in the columns of @self.
+ *
+ * If @column is already a column of @self, it will be repositioned.
+ */
+void
+gtk_column_view_insert_column (GtkColumnView       *self,
+                               guint                position,
+                               GtkColumnViewColumn *column)
+{
+  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) == NULL ||
+                    gtk_column_view_column_get_column_view (column) == self);
+  g_return_if_fail (position <= g_list_model_get_n_items (G_LIST_MODEL (self->columns)));
+
+  g_object_ref (column);
+
+  if (gtk_column_view_column_get_column_view (column) == self)
+    {
+      guint i;
+
+      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);
+
+          g_object_unref (item);
+          if (item == column)
+            {
+              g_list_store_remove (self->columns, i);
+              break;
+            }
+        }
+    }
+  else
+    gtk_column_view_column_set_column_view (column, self);
+
+  g_list_store_insert (self->columns, position, column);
+
+  gtk_column_view_column_queue_resize (column);
+
+  g_object_unref (column);
+}
+
 void
 gtk_column_view_measure_across (GtkColumnView *self,
                                 int           *minimum,
diff --git a/gtk/gtkcolumnview.h b/gtk/gtkcolumnview.h
index 2e1437b8f4..0866b6449c 100644
--- a/gtk/gtkcolumnview.h
+++ b/gtk/gtkcolumnview.h
@@ -61,6 +61,10 @@ 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                   (GtkColumnView          *self,
+                                                                 guint                   position,
+                                                                 GtkColumnViewColumn    *column);
 
 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]