filechooser: Set date and time after cell is a child of filechooserwidget
The date/time column relies on the filechooserwidget to format the date properly. During bind, the filechoosercell, get the filechooserwidget ancestor, but now due to changes in the listview, the cell isn't a child of the filechooserwidget at that point. Since this is deeply ingrained into the filechooserwidget, let's keep the same behavior, but move it to filechoosercell in realize. Alternatively, we could have used a signal factory (with the file chooser widget as the user data), but that would have been a major overhaul.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "gtkgestureclick.h"
|
||||
#include "gtkgesturelongpress.h"
|
||||
#include "gtkicontheme.h"
|
||||
#include "gtklabel.h"
|
||||
#include "gtkselectionmodel.h"
|
||||
#include "gtkfilechooserutils.h"
|
||||
#include "gtkfilechooserwidgetprivate.h"
|
||||
@@ -39,6 +40,7 @@ struct _GtkFileChooserCell
|
||||
GFileInfo *item;
|
||||
GtkColumnViewCell *list_item;
|
||||
|
||||
gboolean date_column;
|
||||
guint type_format;
|
||||
|
||||
gboolean show_time;
|
||||
@@ -53,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,
|
||||
@@ -168,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
|
||||
@@ -227,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);
|
||||
|
||||
@@ -261,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;
|
||||
@@ -286,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,
|
||||
|
||||
@@ -1945,9 +1945,9 @@ files_list_restrict_key_presses (GtkEventControllerKey *controller,
|
||||
return GDK_EVENT_PROPAGATE;
|
||||
}
|
||||
|
||||
static char *
|
||||
column_view_get_file_date (GtkColumnViewCell *cell,
|
||||
GFileInfo *info)
|
||||
char *
|
||||
gtk_file_chooser_widget_get_file_date (GtkColumnViewCell *cell,
|
||||
GFileInfo *info)
|
||||
{
|
||||
GtkFileChooserWidget *impl;
|
||||
glong time;
|
||||
@@ -1981,9 +1981,9 @@ column_view_get_file_display_name (GtkColumnViewCell *cell,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char *
|
||||
column_view_get_file_time (GtkColumnViewCell *cell,
|
||||
GFileInfo *info)
|
||||
char *
|
||||
gtk_file_chooser_widget_get_file_time (GtkColumnViewCell *cell,
|
||||
GFileInfo *info)
|
||||
{
|
||||
GtkFileChooserWidget *impl;
|
||||
glong time;
|
||||
@@ -6847,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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user