[gnome-calendar/wip/gbsneto/alarms: 2/6] edit-dialog: simplify action handling
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/gbsneto/alarms: 2/6] edit-dialog: simplify action handling
- Date: Wed, 6 Jul 2016 05:39:38 +0000 (UTC)
commit beaa64736d5596352de6811c310e24479106d932
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Sun Jun 19 12:26:51 2016 -0300
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.
src/gcal-edit-dialog.c | 47 ++++++++++++++++++++++++-----------------------
1 files changed, 24 insertions(+), 23 deletions(-)
---
diff --git a/src/gcal-edit-dialog.c b/src/gcal-edit-dialog.c
index 41cc0e5..b2a510a 100644
--- a/src/gcal-edit-dialog.c
+++ b/src/gcal-edit-dialog.c
@@ -56,7 +56,6 @@ struct _GcalEditDialog
/* actions */
GMenu *sources_menu;
- GSimpleAction *action;
GSimpleActionGroup *action_group;
/* new data holders */
@@ -70,7 +69,7 @@ struct _GcalEditDialog
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,
gpointer user_data);
@@ -108,6 +107,11 @@ enum
LAST_PROP
};
+const GActionEntry action_entries[] =
+{
+ { "select-calendar", on_calendar_selected, "s" },
+};
+
static void
fill_sources_menu (GcalEditDialog *dialog)
{
@@ -134,17 +138,17 @@ fill_sources_menu (GcalEditDialog *dialog)
pix = gcal_get_pixbuf_from_color (&color, 16);;
/* 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));
/* set insensitive for read-only calendars */
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
{
- 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)));
}
@@ -163,9 +167,9 @@ fill_sources_menu (GcalEditDialog *dialog)
}
static void
-on_calendar_selected (GtkWidget *menu_item,
- GVariant *value,
- gpointer user_data)
+on_calendar_selected (GSimpleAction *action,
+ GVariant *value,
+ gpointer user_data)
{
GcalEditDialog *dialog;
GList *list;
@@ -377,9 +381,9 @@ gcal_edit_dialog_init (GcalEditDialog *self)
static void
gcal_edit_dialog_constructed (GObject* object)
{
- GcalEditDialog *dialog;
+ GcalEditDialog *self;
- dialog = GCAL_EDIT_DIALOG (object);
+ self = GCAL_EDIT_DIALOG (object);
/* chaining up */
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), "");
/* titlebar */
- gtk_window_set_titlebar (GTK_WINDOW (object), dialog->titlebar);
+ gtk_window_set_titlebar (GTK_WINDOW (object), self->titlebar);
- /* actions */
- dialog->action_group = g_simple_action_group_new ();
- gtk_widget_insert_action_group (GTK_WIDGET (object),
- "edit",
- G_ACTION_GROUP (dialog->action_group));
+ /* Actions */
+ self->action_group = g_simple_action_group_new ();
+ g_action_map_add_action_entries (G_ACTION_MAP (self->action_group),
+ action_entries,
+ G_N_ELEMENTS (action_entries),
+ self);
- 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));
+ gtk_widget_insert_action_group (GTK_WIDGET (self),
+ "edit",
+ G_ACTION_GROUP (self->action_group));
}
static void
@@ -411,7 +413,6 @@ gcal_edit_dialog_finalize (GObject *object)
dialog = GCAL_EDIT_DIALOG (object);
g_clear_object (&dialog->action_group);
- g_clear_object (&dialog->action);
g_clear_object (&dialog->manager);
g_clear_object (&dialog->event);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]