edit-dialog: simplify action handling
Instead of keeping a ref to the GcalEditDialog::select-calendar action, use the builtin facilities and simplify the action handling by using a const structure. This is also a preparation for the next few commits where alarms will be added.
This commit is contained in:
+24
-23
@@ -56,7 +56,6 @@ struct _GcalEditDialog
|
|||||||
|
|
||||||
/* actions */
|
/* actions */
|
||||||
GMenu *sources_menu;
|
GMenu *sources_menu;
|
||||||
GSimpleAction *action;
|
|
||||||
GSimpleActionGroup *action_group;
|
GSimpleActionGroup *action_group;
|
||||||
|
|
||||||
/* new data holders */
|
/* new data holders */
|
||||||
@@ -70,7 +69,7 @@ struct _GcalEditDialog
|
|||||||
|
|
||||||
static void fill_sources_menu (GcalEditDialog *dialog);
|
static void fill_sources_menu (GcalEditDialog *dialog);
|
||||||
|
|
||||||
static void on_calendar_selected (GtkWidget *menu_item,
|
static void on_calendar_selected (GSimpleAction *menu_item,
|
||||||
GVariant *value,
|
GVariant *value,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
@@ -108,6 +107,11 @@ enum
|
|||||||
LAST_PROP
|
LAST_PROP
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const GActionEntry action_entries[] =
|
||||||
|
{
|
||||||
|
{ "select-calendar", on_calendar_selected, "s" },
|
||||||
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
fill_sources_menu (GcalEditDialog *dialog)
|
fill_sources_menu (GcalEditDialog *dialog)
|
||||||
{
|
{
|
||||||
@@ -134,17 +138,17 @@ fill_sources_menu (GcalEditDialog *dialog)
|
|||||||
pix = gcal_get_pixbuf_from_color (&color, 16);;
|
pix = gcal_get_pixbuf_from_color (&color, 16);;
|
||||||
|
|
||||||
/* menu item */
|
/* menu item */
|
||||||
item = g_menu_item_new (e_source_get_display_name (source), "select_calendar");
|
item = g_menu_item_new (e_source_get_display_name (source), "select-calendar");
|
||||||
g_menu_item_set_icon (item, G_ICON (pix));
|
g_menu_item_set_icon (item, G_ICON (pix));
|
||||||
|
|
||||||
/* set insensitive for read-only calendars */
|
/* set insensitive for read-only calendars */
|
||||||
if (!gcal_manager_is_client_writable (dialog->manager, source))
|
if (!gcal_manager_is_client_writable (dialog->manager, source))
|
||||||
{
|
{
|
||||||
g_menu_item_set_action_and_target_value (item, "select_calendar", NULL);
|
g_menu_item_set_action_and_target_value (item, "select-calendar", NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_menu_item_set_action_and_target_value (item, "select_calendar",
|
g_menu_item_set_action_and_target_value (item, "select-calendar",
|
||||||
g_variant_new_string (e_source_get_uid (source)));
|
g_variant_new_string (e_source_get_uid (source)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,9 +167,9 @@ fill_sources_menu (GcalEditDialog *dialog)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_calendar_selected (GtkWidget *menu_item,
|
on_calendar_selected (GSimpleAction *action,
|
||||||
GVariant *value,
|
GVariant *value,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
GcalEditDialog *dialog;
|
GcalEditDialog *dialog;
|
||||||
GList *list;
|
GList *list;
|
||||||
@@ -377,9 +381,9 @@ gcal_edit_dialog_init (GcalEditDialog *self)
|
|||||||
static void
|
static void
|
||||||
gcal_edit_dialog_constructed (GObject* object)
|
gcal_edit_dialog_constructed (GObject* object)
|
||||||
{
|
{
|
||||||
GcalEditDialog *dialog;
|
GcalEditDialog *self;
|
||||||
|
|
||||||
dialog = GCAL_EDIT_DIALOG (object);
|
self = GCAL_EDIT_DIALOG (object);
|
||||||
|
|
||||||
/* chaining up */
|
/* chaining up */
|
||||||
G_OBJECT_CLASS (gcal_edit_dialog_parent_class)->constructed (object);
|
G_OBJECT_CLASS (gcal_edit_dialog_parent_class)->constructed (object);
|
||||||
@@ -387,20 +391,18 @@ gcal_edit_dialog_constructed (GObject* object)
|
|||||||
gtk_window_set_title (GTK_WINDOW (object), "");
|
gtk_window_set_title (GTK_WINDOW (object), "");
|
||||||
|
|
||||||
/* titlebar */
|
/* titlebar */
|
||||||
gtk_window_set_titlebar (GTK_WINDOW (object), dialog->titlebar);
|
gtk_window_set_titlebar (GTK_WINDOW (object), self->titlebar);
|
||||||
|
|
||||||
/* actions */
|
/* Actions */
|
||||||
dialog->action_group = g_simple_action_group_new ();
|
self->action_group = g_simple_action_group_new ();
|
||||||
gtk_widget_insert_action_group (GTK_WIDGET (object),
|
g_action_map_add_action_entries (G_ACTION_MAP (self->action_group),
|
||||||
|
action_entries,
|
||||||
|
G_N_ELEMENTS (action_entries),
|
||||||
|
self);
|
||||||
|
|
||||||
|
gtk_widget_insert_action_group (GTK_WIDGET (self),
|
||||||
"edit",
|
"edit",
|
||||||
G_ACTION_GROUP (dialog->action_group));
|
G_ACTION_GROUP (self->action_group));
|
||||||
|
|
||||||
dialog->action = g_simple_action_new ("select_calendar", G_VARIANT_TYPE_STRING);
|
|
||||||
g_signal_connect (dialog->action,
|
|
||||||
"activate",
|
|
||||||
G_CALLBACK (on_calendar_selected), object);
|
|
||||||
|
|
||||||
g_action_map_add_action (G_ACTION_MAP (dialog->action_group), G_ACTION (dialog->action));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -411,7 +413,6 @@ gcal_edit_dialog_finalize (GObject *object)
|
|||||||
dialog = GCAL_EDIT_DIALOG (object);
|
dialog = GCAL_EDIT_DIALOG (object);
|
||||||
|
|
||||||
g_clear_object (&dialog->action_group);
|
g_clear_object (&dialog->action_group);
|
||||||
g_clear_object (&dialog->action);
|
|
||||||
g_clear_object (&dialog->manager);
|
g_clear_object (&dialog->manager);
|
||||||
g_clear_object (&dialog->event);
|
g_clear_object (&dialog->event);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user