filechooser: Set a row-factory

This way, we can toggle per-row selectability and ensure files are not
selectable in select-folder mode.
This commit is contained in:
Benjamin Otte 2023-03-29 10:39:11 +02:00
parent 880aea513f
commit c760131f6f
2 changed files with 22 additions and 1 deletions

View File

@ -28,6 +28,7 @@
#include "gtkdropdown.h"
#include "gtkcolumnview.h"
#include "gtkcolumnviewcolumn.h"
#include "gtkcolumnviewrow.h"
#include "gtkcssnumbervalueprivate.h"
#include "gtkdroptarget.h"
#include "gtkentry.h"
@ -2023,6 +2024,20 @@ column_view_get_file_type (GtkListItem *item,
return get_type_information (impl, info);
}
static void
column_view_row_bind (GtkListItemFactory *factory,
GtkColumnViewRow *row,
gpointer unused)
{
GFileInfo *info;
gboolean selectable;
info = gtk_column_view_row_get_item (row);
selectable = g_file_info_get_attribute_boolean (info, "filechooser::selectable");
gtk_column_view_row_set_selectable (row, selectable);
}
static char *
file_chooser_get_location (GtkFileChooserWidget *impl,
GFileInfo *info)
@ -6798,8 +6813,8 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, column_view_location_column);
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, column_view_size_column);
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, column_view_time_column);
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, column_view_type_column);
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, filter_combo_hbox);
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, column_view_type_column);
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, filter_combo);
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, extra_align);
gtk_widget_class_bind_template_child (widget_class, GtkFileChooserWidget, extra_and_filters);
@ -6840,6 +6855,7 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class)
gtk_widget_class_bind_template_callback (widget_class, column_view_get_location);
gtk_widget_class_bind_template_callback (widget_class, column_view_get_size);
gtk_widget_class_bind_template_callback (widget_class, column_view_get_tooltip_text);
gtk_widget_class_bind_template_callback (widget_class, column_view_row_bind);
gtk_widget_class_set_css_name (widget_class, I_("filechooser"));

View File

@ -169,6 +169,11 @@
<style>
<class name="complex"/>
</style>
<property name="row-factory">
<object class="GtkSignalListItemFactory">
<signal name="bind" handler="column_view_row_bind" swapped="no"/>
</object>
</property>
<signal name="activate" handler="browse_files_view_row_activated_cb" swapped="no"/>
<signal name="keynav-failed" handler="browse_files_view_keynav_failed_cb"/>
<child>