gui/event-widget: Use more bindings in the UI file

Instead of manually connecting to signals and binding to properties
in code.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-calendar/-/merge_requests/758>
This commit is contained in:
Georges Basile Stavracas Neto
2026-05-19 22:20:09 +00:00
committed by Marge Bot
parent c939c7176d
commit e4d1fdf13c
2 changed files with 12 additions and 39 deletions
+6 -1
View File
@@ -11,6 +11,9 @@ template $GcalEventWidget: Widget {
} }
DragSource drag_source { DragSource drag_source {
propagation-phase: bind $read_only_to_propagation_phase_cb(
template.event as <$GcalEvent>.calendar as <$GcalCalendar>.read-only
);
prepare => $on_drag_source_prepare_cb(template) not-swapped; prepare => $on_drag_source_prepare_cb(template) not-swapped;
begin => $on_drag_source_begin_cb(template) not-swapped; begin => $on_drag_source_begin_cb(template) not-swapped;
} }
@@ -64,7 +67,9 @@ template $GcalEventWidget: Widget {
Box horizontal_box { Box horizontal_box {
spacing: 4; spacing: 4;
$GcalFadingLabel summary_label {} $GcalFadingLabel summary_label {
label: bind template.event as <$GcalEvent>.summary;
}
Label timestamp_label { Label timestamp_label {
halign: end; halign: end;
+6 -38
View File
@@ -98,11 +98,6 @@ typedef enum
static guint signals[NUM_SIGNALS] = { 0, }; static guint signals[NUM_SIGNALS] = { 0, };
static GParamSpec *properties[N_PROPS] = { NULL, }; static GParamSpec *properties[N_PROPS] = { NULL, };
static gboolean read_only_to_propagation_phase_cb (GBinding *binding,
const GValue *from_value,
GValue *to_value,
gpointer user_data);
G_DEFINE_TYPE_WITH_CODE (GcalEventWidget, gcal_event_widget, GTK_TYPE_WIDGET, G_DEFINE_TYPE_WITH_CODE (GcalEventWidget, gcal_event_widget, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)); G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL));
@@ -518,24 +513,6 @@ gcal_event_widget_set_event_internal (GcalEventWidget *self,
/* Tooltip */ /* Tooltip */
gcal_event_widget_set_event_tooltip (self, event); gcal_event_widget_set_event_tooltip (self, event);
/* Summary label */
g_object_bind_property (event,
"summary",
self->summary_label,
"label",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
g_object_bind_property_full (gcal_event_get_calendar (event),
"read-only",
self->drag_source,
"propagation-phase",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE,
read_only_to_propagation_phase_cb,
NULL,
self,
NULL);
gcal_event_widget_update_style (self); gcal_event_widget_update_style (self);
gcal_event_widget_update_timestamp (self); gcal_event_widget_update_timestamp (self);
} }
@@ -635,22 +612,12 @@ on_event_popover_edit_cb (GtkWidget *event_popover,
reply_preview_callback (event_popover, data, GCAL_EVENT_PREVIEW_ACTION_EDIT); reply_preview_callback (event_popover, data, GCAL_EVENT_PREVIEW_ACTION_EDIT);
} }
static gboolean static GtkPropagationPhase
read_only_to_propagation_phase_cb (GBinding *binding, read_only_to_propagation_phase_cb (gpointer source_object,
const GValue *from_value, gboolean read_only,
GValue *to_value, gpointer user_data)
gpointer user_data)
{ {
GtkPropagationPhase phase; return read_only ? GTK_PHASE_NONE : GTK_PHASE_BUBBLE;
if (g_value_get_boolean (from_value))
phase = GTK_PHASE_NONE;
else
phase = GTK_PHASE_BUBBLE;
g_value_set_enum (to_value, phase);
return TRUE;
} }
@@ -805,6 +772,7 @@ gcal_event_widget_class_init (GcalEventWidgetClass *klass)
gtk_widget_class_bind_template_callback (widget_class, on_click_gesture_release_cb); gtk_widget_class_bind_template_callback (widget_class, on_click_gesture_release_cb);
gtk_widget_class_bind_template_callback (widget_class, on_drag_source_begin_cb); gtk_widget_class_bind_template_callback (widget_class, on_drag_source_begin_cb);
gtk_widget_class_bind_template_callback (widget_class, on_drag_source_prepare_cb); gtk_widget_class_bind_template_callback (widget_class, on_drag_source_prepare_cb);
gtk_widget_class_bind_template_callback (widget_class, read_only_to_propagation_phase_cb);
gtk_widget_class_set_css_name (widget_class, "event"); gtk_widget_class_set_css_name (widget_class, "event");
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_TOGGLE_BUTTON); gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_TOGGLE_BUTTON);