diff options
author | Matthias Clasen <mclasen@redhat.com> | 2023-04-11 05:32:38 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2023-04-11 05:32:38 +0000 |
commit | db48cd64674ca6a7a4b777f97d6ab46ef2a52c5a (patch) | |
tree | 9ae42640d8f37c233efa9994196282d975767570 | |
parent | ba43a126b9b863457fa16dd8b9264d18f810d795 (diff) | |
parent | 2a70093a309481cf633086a5e8f0c8bc6d2c89f0 (diff) | |
download | gtk+-db48cd64674ca6a7a4b777f97d6ab46ef2a52c5a.tar.gz |
Merge branch 'wip/corey/file-chooser-widget' into 'main'
More fixes to filechooserwidget
See merge request GNOME/gtk!5815
-rw-r--r-- | gtk/gtkfilechoosercell.c | 68 | ||||
-rw-r--r-- | gtk/gtkfilechoosercellprivate.h | 2 | ||||
-rw-r--r-- | gtk/gtkfilechooserwidget.c | 67 | ||||
-rw-r--r-- | gtk/gtkfilechooserwidgetprivate.h | 9 | ||||
-rw-r--r-- | gtk/ui/gtkfilechooserwidget.ui | 33 |
5 files changed, 107 insertions, 72 deletions
diff --git a/gtk/gtkfilechoosercell.c b/gtk/gtkfilechoosercell.c index 3787b7f8b4..3098d7a2e9 100644 --- a/gtk/gtkfilechoosercell.c +++ b/gtk/gtkfilechoosercell.c @@ -23,22 +23,25 @@ #include "gtkprivate.h" #include "gtkbinlayout.h" +#include "gtkcolumnviewcell.h" #include "gtkdragsource.h" #include "gtkgestureclick.h" #include "gtkgesturelongpress.h" #include "gtkicontheme.h" -#include "gtklistitem.h" +#include "gtklabel.h" #include "gtkselectionmodel.h" #include "gtkfilechooserutils.h" #include "gtkfilechooserwidgetprivate.h" -#include "gtklistitem.h" struct _GtkFileChooserCell { GtkWidget parent_instance; GFileInfo *item; - GtkListItem *list_item; + GtkColumnViewCell *list_item; + + gboolean date_column; + guint type_format; gboolean show_time; }; @@ -52,7 +55,8 @@ G_DEFINE_TYPE (GtkFileChooserCell, gtk_file_chooser_cell, GTK_TYPE_WIDGET) enum { - PROP_POSITION = 1, + PROP_DATE_COLUMN = 1, + PROP_POSITION, PROP_ITEM, PROP_SHOW_TIME, PROP_LIST_ITEM, @@ -60,6 +64,12 @@ enum #define ICON_SIZE 16 +guint +gtk_file_chooser_cell_get_type_format (GtkFileChooserCell *self) +{ + return self->type_format; +} + static void popup_menu (GtkFileChooserCell *self, double x, @@ -79,7 +89,7 @@ popup_menu (GtkFileChooserCell *self, if (self->list_item) gtk_widget_activate_action (widget, "item.popup-file-list-menu", - "(udd)", gtk_list_item_get_position (self->list_item), p.x, p.y); + "(udd)", gtk_column_view_cell_get_position (self->list_item), p.x, p.y); } static void @@ -125,7 +135,7 @@ drag_prepare_cb (GtkDragSource *source, impl = GTK_FILE_CHOOSER_WIDGET (gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_FILE_CHOOSER_WIDGET)); - if (self->list_item && !gtk_list_item_get_selected (self->list_item)) + if (self->list_item && !gtk_column_view_cell_get_selected (self->list_item)) { gtk_widget_activate_action (GTK_WIDGET (self), "listitem.select", "(bb)", FALSE, FALSE); } @@ -161,6 +171,23 @@ gtk_file_chooser_cell_realize (GtkWidget *widget) GTK_TYPE_FILE_CHOOSER_WIDGET)); g_object_bind_property (impl, "show-time", self, "show-time", G_BINDING_SYNC_CREATE); + + if (self->date_column) + { + GtkWidget *box; + GtkWidget *label; + char *text; + + box = gtk_widget_get_first_child (GTK_WIDGET (self)); + label = gtk_widget_get_first_child (box); + text = gtk_file_chooser_widget_get_file_date (self->list_item, self->item); + gtk_label_set_text (GTK_LABEL (label), text); + g_free (text); + label = gtk_widget_get_last_child (box); + text = gtk_file_chooser_widget_get_file_time (self->list_item, self->item); + gtk_label_set_text (GTK_LABEL (label), text); + g_free (text); + } } static void @@ -168,6 +195,11 @@ gtk_file_chooser_cell_init (GtkFileChooserCell *self) { GtkGesture *gesture; GtkDragSource *drag_source; + GSettings *settings; + + settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (self)); + + self->type_format = g_settings_get_enum (settings, SETTINGS_KEY_TYPE_FORMAT); gesture = gtk_gesture_click_new (); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_SECONDARY); @@ -206,13 +238,6 @@ get_selectable (GtkFileChooserCell *self) } static void -update_list_item (GtkFileChooserCell *self) -{ - if (self->list_item) - gtk_list_item_set_selectable (self->list_item, get_selectable (self)); -} - -static void gtk_file_chooser_cell_set_property (GObject *object, guint prop_id, const GValue *value, @@ -222,6 +247,10 @@ gtk_file_chooser_cell_set_property (GObject *object, switch (prop_id) { + case PROP_DATE_COLUMN: + self->date_column = g_value_get_boolean (value); + break; + case PROP_ITEM: self->item = g_value_get_object (value); @@ -230,7 +259,6 @@ gtk_file_chooser_cell_set_property (GObject *object, else gtk_widget_add_css_class (GTK_WIDGET (self), "dim-label"); - update_list_item (self); break; case PROP_SHOW_TIME: @@ -239,8 +267,6 @@ gtk_file_chooser_cell_set_property (GObject *object, case PROP_LIST_ITEM: self->list_item = g_value_get_object (value); - - update_list_item (self); break; default: @@ -259,6 +285,10 @@ gtk_file_chooser_cell_get_property (GObject *object, switch (prop_id) { + case PROP_DATE_COLUMN: + g_value_set_boolean (value, self->date_column); + break; + case PROP_ITEM: g_value_set_object (value, self->item); break; @@ -284,6 +314,12 @@ gtk_file_chooser_cell_class_init (GtkFileChooserCellClass *klass) object_class->set_property = gtk_file_chooser_cell_set_property; object_class->get_property = gtk_file_chooser_cell_get_property; + g_object_class_install_property (object_class, PROP_DATE_COLUMN, + g_param_spec_boolean ("date-column", NULL, NULL, + FALSE, + GTK_PARAM_READWRITE)); + + g_object_class_install_property (object_class, PROP_ITEM, g_param_spec_object ("item", NULL, NULL, G_TYPE_FILE_INFO, diff --git a/gtk/gtkfilechoosercellprivate.h b/gtk/gtkfilechoosercellprivate.h index 55c52e9c46..dfe9792e7c 100644 --- a/gtk/gtkfilechoosercellprivate.h +++ b/gtk/gtkfilechoosercellprivate.h @@ -31,5 +31,7 @@ G_DECLARE_FINAL_TYPE (GtkFileChooserCell, gtk_file_chooser_cell, GTK, FILE_CHOOS GtkFileChooserCell * gtk_file_chooser_cell_new (void); +guint gtk_file_chooser_cell_get_type_format (GtkFileChooserCell *self); + G_END_DECLS diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index cc7136f156..51607dfe87 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -27,6 +27,7 @@ #include "gtkbutton.h" #include "gtkdropdown.h" #include "gtkcolumnview.h" +#include "gtkcolumnviewcell.h" #include "gtkcolumnviewcolumn.h" #include "gtkcolumnviewrow.h" #include "gtkcssnumbervalueprivate.h" @@ -44,7 +45,6 @@ #include "gtkgesturelongpress.h" #include "gtkgrid.h" #include "gtklabel.h" -#include "gtklistitem.h" #include "gtkmarshalers.h" #include "gtkalertdialog.h" #include "gtkmountoperation.h" @@ -505,8 +505,8 @@ static void set_model_filter (GtkFileChooserWidget *impl, static void switch_to_home_dir (GtkFileChooserWidget *impl); static void set_show_hidden (GtkFileChooserWidget *impl, gboolean show_hidden); -static char * get_type_information (GtkFileChooserWidget *impl, - GFileInfo *info); +static char * get_type_information (TypeFormat type_format, + GFileInfo *info); static char * my_g_format_date_for_display (GtkFileChooserWidget *impl, glong secs); static char * my_g_format_time_for_display (GtkFileChooserWidget *impl, @@ -1945,9 +1945,9 @@ files_list_restrict_key_presses (GtkEventControllerKey *controller, return GDK_EVENT_PROPAGATE; } -static char * -column_view_get_file_date (GtkListItem *item, - GFileInfo *info) +char * +gtk_file_chooser_widget_get_file_date (GtkColumnViewCell *cell, + GFileInfo *info) { GtkFileChooserWidget *impl; glong time; @@ -1955,7 +1955,7 @@ column_view_get_file_date (GtkListItem *item, if (!info) return NULL; - impl = GTK_FILE_CHOOSER_WIDGET (gtk_widget_get_ancestor (gtk_list_item_get_child (item), + impl = GTK_FILE_CHOOSER_WIDGET (gtk_widget_get_ancestor (gtk_column_view_cell_get_child (cell), GTK_TYPE_FILE_CHOOSER_WIDGET)); if (!impl) return NULL; @@ -1972,8 +1972,8 @@ column_view_get_file_date (GtkListItem *item, } static char * -column_view_get_file_display_name (GtkListItem *item, - GFileInfo *info) +column_view_get_file_display_name (GtkColumnViewCell *cell, + GFileInfo *info) { if (info) return g_strdup (g_file_info_get_display_name (info)); @@ -1981,9 +1981,9 @@ column_view_get_file_display_name (GtkListItem *item, return NULL; } -static char * -column_view_get_file_time (GtkListItem *item, - GFileInfo *info) +char * +gtk_file_chooser_widget_get_file_time (GtkColumnViewCell *cell, + GFileInfo *info) { GtkFileChooserWidget *impl; glong time; @@ -1991,7 +1991,7 @@ column_view_get_file_time (GtkListItem *item, if (!info) return NULL; - impl = GTK_FILE_CHOOSER_WIDGET (gtk_widget_get_ancestor (gtk_list_item_get_child (item), + impl = GTK_FILE_CHOOSER_WIDGET (gtk_widget_get_ancestor (gtk_column_view_cell_get_child (cell), GTK_TYPE_FILE_CHOOSER_WIDGET)); if (!impl) return NULL; @@ -2008,20 +2008,20 @@ column_view_get_file_time (GtkListItem *item, } static char * -column_view_get_file_type (GtkListItem *item, - GFileInfo *info) +column_view_get_file_type (GtkColumnViewCell *cell, + GFileInfo *info) { - GtkFileChooserWidget *impl; + GtkFileChooserCell *child; if (!info || _gtk_file_info_consider_as_directory (info)) return NULL; - impl = GTK_FILE_CHOOSER_WIDGET (gtk_widget_get_ancestor (gtk_list_item_get_child (item), - GTK_TYPE_FILE_CHOOSER_WIDGET)); - if (!impl) + child = GTK_FILE_CHOOSER_CELL (gtk_column_view_cell_get_child (cell)); + + if (!child) return NULL; - return get_type_information (impl, info); + return get_type_information (gtk_file_chooser_cell_get_type_format (child), info); } static void @@ -2097,12 +2097,12 @@ file_chooser_get_location (GtkFileChooserWidget *impl, } static char * -column_view_get_location (GtkListItem *list_item, - GFileInfo *info) +column_view_get_location (GtkColumnViewCell *cell, + GFileInfo *info) { GtkFileChooserWidget *impl; - impl = GTK_FILE_CHOOSER_WIDGET (gtk_widget_get_ancestor (gtk_list_item_get_child (list_item), + impl = GTK_FILE_CHOOSER_WIDGET (gtk_widget_get_ancestor (gtk_column_view_cell_get_child (cell), GTK_TYPE_FILE_CHOOSER_WIDGET)); if (!impl) return NULL; @@ -2111,8 +2111,8 @@ column_view_get_location (GtkListItem *list_item, } static char * -column_view_get_size (GtkListItem *item, - GFileInfo *info) +column_view_get_size (GtkColumnViewCell *cell, + GFileInfo *info) { if (info && !_gtk_file_info_consider_as_directory (info)) return g_format_size (g_file_info_get_size (info)); @@ -2121,8 +2121,8 @@ column_view_get_size (GtkListItem *item, } static char * -column_view_get_tooltip_text (GtkListItem *list_item, - GFileInfo *info) +column_view_get_tooltip_text (GtkColumnViewCell *cell, + GFileInfo *info) { GFile *file; @@ -3284,7 +3284,6 @@ settings_save (GtkFileChooserWidget *impl) g_settings_set_int (settings, SETTINGS_KEY_SIDEBAR_WIDTH, gtk_paned_get_position (GTK_PANED (impl->browse_widgets_hpaned))); g_settings_set_enum (settings, SETTINGS_KEY_DATE_FORMAT, impl->show_time ? DATE_FORMAT_WITH_TIME : DATE_FORMAT_REGULAR); - g_settings_set_enum (settings, SETTINGS_KEY_TYPE_FORMAT, impl->type_format); g_settings_set_enum (settings, SETTINGS_KEY_VIEW_TYPE, impl->view_type); /* Now apply the settings */ @@ -3947,8 +3946,8 @@ get_category_from_content_type (const char *content_type) } static char * -get_type_information (GtkFileChooserWidget *impl, - GFileInfo *info) +get_type_information (TypeFormat type_format, + GFileInfo *info) { const char *content_type; char *mime_type; @@ -3960,7 +3959,7 @@ get_type_information (GtkFileChooserWidget *impl, if (!content_type) goto end; - switch (impl->type_format) + switch (type_format) { case TYPE_FORMAT_MIME: mime_type = g_content_type_get_mime_type (content_type); @@ -6848,9 +6847,7 @@ gtk_file_chooser_widget_class_init (GtkFileChooserWidgetClass *class) gtk_widget_class_bind_template_callback (widget_class, rename_file_name_changed); gtk_widget_class_bind_template_callback (widget_class, rename_file_rename_clicked); gtk_widget_class_bind_template_callback (widget_class, rename_file_end); - gtk_widget_class_bind_template_callback (widget_class, column_view_get_file_date); gtk_widget_class_bind_template_callback (widget_class, column_view_get_file_display_name); - gtk_widget_class_bind_template_callback (widget_class, column_view_get_file_time); gtk_widget_class_bind_template_callback (widget_class, column_view_get_file_type); gtk_widget_class_bind_template_callback (widget_class, column_view_get_location); gtk_widget_class_bind_template_callback (widget_class, column_view_get_size); @@ -7085,8 +7082,8 @@ type_sort_func (gconstpointer a, GtkOrdering result; /* FIXME: use sortkeys for these */ - key_a = get_type_information (impl, (GFileInfo *)a); - key_b = get_type_information (impl, (GFileInfo *)b); + key_a = get_type_information (impl->type_format, (GFileInfo *)a); + key_b = get_type_information (impl->type_format, (GFileInfo *)b); result = g_strcmp0 (key_a, key_b); diff --git a/gtk/gtkfilechooserwidgetprivate.h b/gtk/gtkfilechooserwidgetprivate.h index 319209c58d..e99e60cbdd 100644 --- a/gtk/gtkfilechooserwidgetprivate.h +++ b/gtk/gtkfilechooserwidgetprivate.h @@ -22,6 +22,7 @@ #include <glib.h> #include "deprecated/gtkfilechooserwidget.h" +#include "gtkcolumnviewcell.h" #include "gtkselectionmodel.h" G_BEGIN_DECLS @@ -36,6 +37,14 @@ gtk_file_chooser_widget_should_respond (GtkFileChooserWidget *chooser); void gtk_file_chooser_widget_initial_focus (GtkFileChooserWidget *chooser); +char * +gtk_file_chooser_widget_get_file_date (GtkColumnViewCell *cell, + GFileInfo *info); + +char * +gtk_file_chooser_widget_get_file_time (GtkColumnViewCell *cell, + GFileInfo *info); + GSList * gtk_file_chooser_widget_get_selected_files (GtkFileChooserWidget *impl); diff --git a/gtk/ui/gtkfilechooserwidget.ui b/gtk/ui/gtkfilechooserwidget.ui index 71a0d1d258..acc3b57e94 100644 --- a/gtk/ui/gtkfilechooserwidget.ui +++ b/gtk/ui/gtkfilechooserwidget.ui @@ -330,25 +330,25 @@ <property name="bytes"><![CDATA[ <?xml version="1.0" encoding="UTF-8"?> <interface> - <template class="GtkListItem"> + <template class="GtkColumnViewCell"> <property name="child"> <object class="GtkFileChooserCell"> <binding name="item"> - <lookup name="item">GtkListItem</lookup> + <lookup name="item">GtkColumnViewCell</lookup> </binding> - <property name="list-item">GtkListItem</property> + <property name="list-item">GtkColumnViewCell</property> <child> <object class="GtkLabel"> <property name="hexpand">1</property> <property name="xalign">0</property> <binding name="label"> <closure type="gchararray" function="column_view_get_file_type"> - <lookup name="item">GtkListItem</lookup> + <lookup name="item">GtkColumnViewCell</lookup> </closure> </binding> <binding name="tooltip-text"> <closure type="gchararray" function="column_view_get_tooltip_text"> - <lookup name="item">GtkListItem</lookup> + <lookup name="item">GtkColumnViewCell</lookup> </closure> </binding> </object> @@ -378,6 +378,7 @@ <lookup name="item">GtkColumnViewCell</lookup> </binding> <property name="list-item">GtkColumnViewCell</property> + <property name="date-column">true</property> <child> <object class="GtkBox"> <property name="spacing">6</property> @@ -388,21 +389,11 @@ </binding> <child> <object class="GtkLabel"> - <binding name="label"> - <closure type="gchararray" function="column_view_get_file_date"> - <lookup name="item">GtkColumnViewCell</lookup> - </closure> - </binding> </object> </child> <child> <object class="GtkLabel"> <property name="visible" bind-source="file_chooser_cell" bind-property="show-time" bind-flags="sync-create"/> - <binding name="label"> - <closure type="gchararray" function="column_view_get_file_time"> - <lookup name="item">GtkColumnViewCell</lookup> - </closure> - </binding> </object> </child> </object> @@ -680,19 +671,19 @@ <property name="bytes"><![CDATA[ <?xml version="1.0" encoding="UTF-8"?> <interface> - <template class="GtkListItem"> + <template class="GtkColumnViewCell"> <property name="child"> <object class="GtkFileChooserCell"> <binding name="item"> - <lookup name="item">GtkListItem</lookup> + <lookup name="item">GtkColumnViewCell</lookup> </binding> - <property name="list-item">GtkListItem</property> + <property name="list-item">GtkColumnViewCell</property> <child> <object class="GtkBox"> <property name="orientation">vertical</property> <binding name="tooltip-text"> <closure type="gchararray" function="column_view_get_tooltip_text"> - <lookup name="item">GtkListItem</lookup> + <lookup name="item">GtkColumnViewCell</lookup> </closure> </binding> <child> @@ -701,7 +692,7 @@ <property name="margin-start">6</property> <property name="margin-end">6</property> <binding name="file-info"> - <lookup name="item">GtkListItem</lookup> + <lookup name="item">GtkColumnViewCell</lookup> </binding> </object> </child> @@ -717,7 +708,7 @@ </attributes> <binding name="label"> <closure type="gchararray" function="column_view_get_file_display_name"> - <lookup name="item">GtkListItem</lookup> + <lookup name="item">GtkColumnViewCell</lookup> </closure> </binding> </object> |