filechoosercell: Store type_format in filechoosercell

The format of the type column depends on the the type_format, which
is stored in the filechooserwidget.  We get that setting by looking
for the filechooserwidget ancestor, which no longer works after recent
changes to the list views (it was fragile to begin with).  At one point,
the setting appears to have been dynamic, but now it is only loading
from GSettings, so let's simply do the same within FileChooserCell.
This commit is contained in:
Corey Berla 2023-04-10 15:14:42 -07:00
parent ccae75022b
commit dd407dab00
3 changed files with 27 additions and 13 deletions

View File

@ -39,6 +39,8 @@ struct _GtkFileChooserCell
GFileInfo *item;
GtkColumnViewCell *list_item;
guint type_format;
gboolean show_time;
};
@ -59,6 +61,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,
@ -167,6 +175,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);

View File

@ -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

View File

@ -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,
@ -2011,17 +2011,17 @@ static char *
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
@ -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);
@ -7085,8 +7084,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);