diff options
author | Corey Berla <corey@berla.me> | 2022-12-21 09:52:16 -0800 |
---|---|---|
committer | Corey Berla <corey@berla.me> | 2023-04-17 10:10:25 -0700 |
commit | bbea6aff0ea6b718d068882e49377a8ac5776905 (patch) | |
tree | b935c0b5a54ba7194b39bae3e648d5a2c5341276 | |
parent | 7ef1452d4cb5a4eb5bc73da8efd95f501ae69c3a (diff) | |
download | nautilus-wip/corey/more-list-vieww.tar.gz |
list-view: Keep track of column order when dragging headerswip/corey/more-list-vieww
Now that we are keeping all of the columns in the correct
order we can use the column views model to save the
column order.
-rw-r--r-- | src/nautilus-list-view.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c index 6c9a752ee..2872f6833 100644 --- a/src/nautilus-list-view.c +++ b/src/nautilus-list-view.c @@ -63,6 +63,10 @@ static const char *default_columns_for_trash[] = "name", "size", "trashed_on", NULL }; +static char ** get_column_order (NautilusListView *self); +static GStrv get_columns_from_view (NautilusListView *self, + gboolean visible_only); + static guint get_icon_size_for_zoom_level (NautilusListZoomLevel zoom_level) { @@ -106,6 +110,35 @@ real_get_view_ui (NautilusListBase *list_base_view) } static void +columns_items_changed (GListModel *self, + guint position, + guint removed, + guint added, + gpointer user_data) +{ + NautilusFile *file; + NautilusListView *view = user_data; + g_auto (GStrv) column_order = get_column_order (view); + g_auto (GStrv) new_column_order = get_columns_from_view (view, FALSE); + g_auto (GStrv) new_visible_order = NULL; + + if (g_strv_equal ((const gchar * const *) column_order, (const gchar * const *) new_column_order)) + { + return; + } + + file = nautilus_files_view_get_directory_as_file (NAUTILUS_FILES_VIEW (view)); + new_visible_order = get_columns_from_view (view, TRUE); + + nautilus_file_set_metadata_list (file, + NAUTILUS_METADATA_KEY_LIST_VIEW_COLUMN_ORDER, + new_column_order); + nautilus_file_set_metadata_list (file, + NAUTILUS_METADATA_KEY_LIST_VIEW_VISIBLE_COLUMNS, + new_visible_order); +} + +static void apply_columns_settings (NautilusListView *self, char **column_order, char **visible_columns) @@ -195,10 +228,16 @@ apply_columns_settings (NautilusListView *self, continue; } + g_signal_handlers_block_by_func (gtk_column_view_get_columns (self->view_ui), + G_CALLBACK (columns_items_changed), self); + gtk_column_view_insert_column (self->view_ui, column_i, view_column); visible = g_hash_table_contains (visible_columns_hash, lowercase); gtk_column_view_column_set_visible (view_column, visible); + + g_signal_handlers_unblock_by_func (gtk_column_view_get_columns (self->view_ui), + G_CALLBACK (columns_items_changed), self); } } @@ -1438,6 +1477,9 @@ setup_view_columns (NautilusListView *self) section = g_menu_new (); g_menu_append (section, _("More Columns"), "view.visible-columns"); g_menu_append_section (menu, NULL, G_MENU_MODEL (section)); + + g_signal_connect (gtk_column_view_get_columns (self->view_ui), + "items-changed", G_CALLBACK (columns_items_changed), self); } static void @@ -1542,6 +1584,9 @@ nautilus_list_view_dispose (GObject *object) g_clear_pointer (&self->factory_to_column_map, g_hash_table_destroy); g_signal_handlers_disconnect_by_func (gtk_column_view_get_sorter (self->view_ui), on_sorter_changed, self); + g_signal_handlers_disconnect_by_func (gtk_column_view_get_columns (self->view_ui), + columns_items_changed, + self); G_OBJECT_CLASS (nautilus_list_view_parent_class)->dispose (object); } |