From 4f7b4d81e757bfed1b42b888207a0fdf6fae8533 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 10 Jun 2013 15:21:10 -0400 Subject: Reimplement the main toolbar's "prefer-item" feature. This fixes a bug in the old implementation where the application could crash after a second shell window was created and destroyed, because a signal handler with the destroyed shell window as the closure was left connected. But moreover this simplifies the implementation by using a property binding plus transform function instead of juggling signal handlers, and also adds code comments where things get a little tricky. Removed (now unused) functions: e_shell_window_get_toolbar_new_prefer_item e_shell_window_set_toolbar_new_prefer_item --- modules/calendar/e-cal-shell-backend.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'modules/calendar') diff --git a/modules/calendar/e-cal-shell-backend.c b/modules/calendar/e-cal-shell-backend.c index ab8ecd550f..6a9bc1aac8 100644 --- a/modules/calendar/e-cal-shell-backend.c +++ b/modules/calendar/e-cal-shell-backend.c @@ -215,6 +215,7 @@ action_event_new_cb (GtkAction *action, * the view. */ shell_view = e_shell_window_peek_shell_view (shell_window, "calendar"); if (shell_view != NULL) { + EShellWindow *shell_window; EShellContent *shell_content; GnomeCalendar *gcal; GnomeCalendarViewType view_type; @@ -222,6 +223,16 @@ action_event_new_cb (GtkAction *action, shell_backend = e_shell_view_get_shell_backend (shell_view); shell_content = e_shell_view_get_shell_content (shell_view); + shell_window = e_shell_view_get_shell_window (shell_view); + + e_shell_backend_set_prefer_new_item ( + shell_backend, action_name); + + /* This forces the shell window to update the "New" toolbar + * button menu, and the toolbar button will then update its + * button image to reflect the "preferred new item" we just + * set on the shell backend. */ + g_object_notify (G_OBJECT (shell_window), "active-view"); gcal = e_cal_shell_content_get_calendar ( E_CAL_SHELL_CONTENT (shell_content)); @@ -229,11 +240,7 @@ action_event_new_cb (GtkAction *action, view_type = gnome_calendar_get_view (gcal); view = gnome_calendar_get_calendar_view (gcal, view_type); - if (view) { - g_object_set ( - G_OBJECT (shell_backend), - "prefer-new-item", action_name, NULL); - + if (view != NULL) { e_calendar_view_new_appointment_full ( view, g_str_equal (action_name, "event-all-day-new"), @@ -250,7 +257,7 @@ action_event_new_cb (GtkAction *action, source = e_source_registry_ref_default_calendar (registry); shell_backend = e_shell_get_backend_by_name (shell, "calendar"); - g_object_set (G_OBJECT (shell_backend), "prefer-new-item", action_name, NULL); + e_shell_backend_set_prefer_new_item (shell_backend, action_name); /* Use a callback function appropriate for the action. */ if (strcmp (action_name, "event-all-day-new") == 0) -- cgit v1.2.3