diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2013-07-04 23:04:51 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2013-07-06 04:40:48 +0800 |
commit | 31b5261fdbe2c98e7f4f71e908e5d9b58609de94 (patch) | |
tree | e9157fa12b3978c68492b04c10137c74eee21b17 /shell | |
parent | 7d6027be1a9989549c80fdbe6dcf8317c54a6a6a (diff) | |
download | gsoc2013-evolution-31b5261fdbe2c98e7f4f71e908e5d9b58609de94.tar gsoc2013-evolution-31b5261fdbe2c98e7f4f71e908e5d9b58609de94.tar.gz gsoc2013-evolution-31b5261fdbe2c98e7f4f71e908e5d9b58609de94.tar.bz2 gsoc2013-evolution-31b5261fdbe2c98e7f4f71e908e5d9b58609de94.tar.lz gsoc2013-evolution-31b5261fdbe2c98e7f4f71e908e5d9b58609de94.tar.xz gsoc2013-evolution-31b5261fdbe2c98e7f4f71e908e5d9b58609de94.tar.zst gsoc2013-evolution-31b5261fdbe2c98e7f4f71e908e5d9b58609de94.zip |
EShellView: Add a "view-instance" property.
EShellView now holds a reference to the active GalViewInstance. Where
applicable, the EShellView subclass is responsible for keeping this up
to date when the sidebar selection changes.
Holding a reference allows EShellView to implement common actions like
"Save Current View" directly instead pushing it on to subclasses.
New functions:
e_shell_view_get_view_instance
e_shell_view_set_view_instance
Diffstat (limited to 'shell')
-rw-r--r-- | shell/e-shell-view.c | 188 | ||||
-rw-r--r-- | shell/e-shell-view.h | 10 | ||||
-rw-r--r-- | shell/e-shell-window-actions.c | 16 |
3 files changed, 173 insertions, 41 deletions
diff --git a/shell/e-shell-view.c b/shell/e-shell-view.c index 1f979e6ccb..efdebc8b8c 100644 --- a/shell/e-shell-view.c +++ b/shell/e-shell-view.c @@ -53,6 +53,10 @@ struct _EShellViewPrivate { gpointer state_save_activity; /* weak pointer */ guint state_save_timeout_id; + GalViewInstance *view_instance; + gulong view_instance_changed_handler_id; + gulong view_instance_loaded_handler_id; + gchar *title; gchar *view_id; gint page_num; @@ -85,7 +89,8 @@ enum { PROP_SHELL_WINDOW, PROP_STATE_KEY_FILE, PROP_TITLE, - PROP_VIEW_ID + PROP_VIEW_ID, + PROP_VIEW_INSTANCE }; enum { @@ -404,6 +409,12 @@ shell_view_set_property (GObject *object, E_SHELL_VIEW (object), g_value_get_string (value)); return; + + case PROP_VIEW_INSTANCE: + e_shell_view_set_view_instance ( + E_SHELL_VIEW (object), + g_value_get_object (value)); + return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -486,6 +497,12 @@ shell_view_get_property (GObject *object, value, e_shell_view_get_view_id ( E_SHELL_VIEW (object))); return; + + case PROP_VIEW_INSTANCE: + g_value_set_object ( + value, e_shell_view_get_view_instance ( + E_SHELL_VIEW (object))); + return; } G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -513,6 +530,20 @@ shell_view_dispose (GObject *object) priv->state_save_activity = NULL; } + if (priv->view_instance_changed_handler_id > 0) { + g_signal_handler_disconnect ( + priv->view_instance, + priv->view_instance_changed_handler_id); + priv->view_instance_changed_handler_id = 0; + } + + if (priv->view_instance_loaded_handler_id > 0) { + g_signal_handler_disconnect ( + priv->view_instance, + priv->view_instance_loaded_handler_id); + priv->view_instance_loaded_handler_id = 0; + } + if (priv->preferences_window != NULL) { g_signal_handler_disconnect ( priv->preferences_window, @@ -526,6 +557,7 @@ shell_view_dispose (GObject *object) priv->shell_window = NULL; } + g_clear_object (&priv->view_instance); g_clear_object (&priv->shell_content); g_clear_object (&priv->shell_sidebar); g_clear_object (&priv->shell_taskbar); @@ -923,6 +955,21 @@ e_shell_view_class_init (EShellViewClass *class) G_PARAM_STATIC_STRINGS)); /** + * EShellView:view-instance: + * + * The current #GalViewInstance. + **/ + g_object_class_install_property ( + object_class, + PROP_VIEW_INSTANCE, + g_param_spec_object ( + "view-instance", + "View Instance", + "The current view instance", + GAL_TYPE_VIEW_INSTANCE, + G_PARAM_READWRITE)); + + /** * EShellView::toggled * @shell_view: the #EShellView which emitted the signal * @@ -1214,6 +1261,109 @@ e_shell_view_set_view_id (EShellView *shell_view, } /** + * e_shell_view_new_view_instance: + * @shell_view: an #EShellView + * @instance_id: a name for the #GalViewInstance + * + * Convenience function creates a new #GalViewInstance from the + * #GalViewCollection in @shell_view's #EShellViewClass. + * + * Returns: a new #GalViewInstance + **/ +GalViewInstance * +e_shell_view_new_view_instance (EShellView *shell_view, + const gchar *instance_id) +{ + EShellViewClass *class; + GalViewCollection *view_collection; + + g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL); + + class = E_SHELL_VIEW_GET_CLASS (shell_view); + + view_collection = class->view_collection; + + return gal_view_instance_new (view_collection, instance_id); +} + +/** + * e_shell_view_get_view_instance: + * @shell_view: an #EShellView + * + * Returns the current #GalViewInstance for @shell_view. + * + * #EShellView subclasses are responsible for creating and configuring a + * #GalViewInstance and handing it off so the @shell_view can monitor it + * and perform common actions on it. + * + * Returns: a #GalViewInstance, or %NULL + **/ +GalViewInstance * +e_shell_view_get_view_instance (EShellView *shell_view) +{ + g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL); + + return shell_view->priv->view_instance; +} + +/** + * e_shell_view_set_view_instance: + * @shell_view: an #EShellView + * @view_instance: a #GalViewInstance, or %NULL + * + * Sets the current #GalViewInstance for @shell_view. + * + * #EShellView subclasses are responsible for creating and configuring a + * #GalViewInstance and handing it off so the @shell_view can monitor it + * and perform common actions on it. + **/ +void +e_shell_view_set_view_instance (EShellView *shell_view, + GalViewInstance *view_instance) +{ + g_return_if_fail (E_IS_SHELL_VIEW (shell_view)); + + if (view_instance != NULL) { + g_return_if_fail (GAL_IS_VIEW_INSTANCE (view_instance)); + g_object_ref (view_instance); + } + + if (shell_view->priv->view_instance_changed_handler_id > 0) { + g_signal_handler_disconnect ( + shell_view->priv->view_instance, + shell_view->priv->view_instance_changed_handler_id); + shell_view->priv->view_instance_changed_handler_id = 0; + } + + if (shell_view->priv->view_instance_loaded_handler_id > 0) { + g_signal_handler_disconnect ( + shell_view->priv->view_instance, + shell_view->priv->view_instance_loaded_handler_id); + shell_view->priv->view_instance_loaded_handler_id = 0; + } + + g_clear_object (&shell_view->priv->view_instance); + + shell_view->priv->view_instance = view_instance; + + if (view_instance != NULL) { + gulong handler_id; + + handler_id = g_signal_connect_swapped ( + view_instance, "changed", + G_CALLBACK (shell_view_update_view_id), shell_view); + shell_view->priv->view_instance_changed_handler_id = handler_id; + + handler_id = g_signal_connect_swapped ( + view_instance, "loaded", + G_CALLBACK (shell_view_update_view_id), shell_view); + shell_view->priv->view_instance_loaded_handler_id = handler_id; + } + + g_object_notify (G_OBJECT (shell_view), "view-instance"); +} + +/** * e_shell_view_get_shell_window: * @shell_view: an #EShellView * @@ -1734,42 +1884,6 @@ e_shell_view_show_popup_menu (EShellView *shell_view, } /** - * e_shell_view_new_view_instance: - * @shell_view: an #EShellView - * @instance_id: a name for the #GalViewInstance - * - * Creates a new #GalViewInstance and configures it to keep - * @shell_view<!-- -->'s #EShellView:view-id property up-to-date. - * - * Returns: a new #GalViewInstance - **/ -GalViewInstance * -e_shell_view_new_view_instance (EShellView *shell_view, - const gchar *instance_id) -{ - EShellViewClass *class; - GalViewCollection *view_collection; - GalViewInstance *view_instance; - - g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL); - - class = E_SHELL_VIEW_GET_CLASS (shell_view); - - view_collection = class->view_collection; - view_instance = gal_view_instance_new (view_collection, instance_id); - - g_signal_connect_swapped ( - view_instance, "changed", - G_CALLBACK (shell_view_update_view_id), shell_view); - - g_signal_connect_swapped ( - view_instance, "loaded", - G_CALLBACK (shell_view_update_view_id), shell_view); - - return view_instance; -} - -/** * e_shell_view_write_source: * @shell_view: an #EShellView * @source: an #ESource diff --git a/shell/e-shell-view.h b/shell/e-shell-view.h index 5351e7226c..db51c31ca8 100644 --- a/shell/e-shell-view.h +++ b/shell/e-shell-view.h @@ -198,6 +198,13 @@ void e_shell_view_set_title (EShellView *shell_view, const gchar * e_shell_view_get_view_id (EShellView *shell_view); void e_shell_view_set_view_id (EShellView *shell_view, const gchar *view_id); +GalViewInstance * + e_shell_view_new_view_instance (EShellView *shell_view, + const gchar *instance_id); +GalViewInstance * + e_shell_view_get_view_instance (EShellView *shell_view); +void e_shell_view_set_view_instance (EShellView *shell_view, + GalViewInstance *view_instance); gboolean e_shell_view_is_active (EShellView *shell_view); gint e_shell_view_get_page_num (EShellView *shell_view); void e_shell_view_set_page_num (EShellView *shell_view, @@ -230,9 +237,6 @@ void e_shell_view_update_actions (EShellView *shell_view); GtkWidget * e_shell_view_show_popup_menu (EShellView *shell_view, const gchar *widget_path, GdkEvent *button_event); -GalViewInstance * - e_shell_view_new_view_instance (EShellView *shell_view, - const gchar *instance_id); void e_shell_view_write_source (EShellView *shell_view, ESource *source); void e_shell_view_remove_source (EShellView *shell_view, diff --git a/shell/e-shell-window-actions.c b/shell/e-shell-window-actions.c index 3dcaa73585..8dffb10399 100644 --- a/shell/e-shell-window-actions.c +++ b/shell/e-shell-window-actions.c @@ -231,6 +231,20 @@ action_gal_view_cb (GtkRadioAction *action, * * Main menu item: View -> Current View -> Save Custom View... **/ +static void +action_gal_save_custom_view_cb (GtkAction *action, + EShellWindow *shell_window) +{ + EShellView *shell_view; + GalViewInstance *view_instance; + const gchar *view_name; + + view_name = e_shell_window_get_active_view (shell_window); + shell_view = e_shell_window_get_shell_view (shell_window, view_name); + view_instance = e_shell_view_get_view_instance (shell_view); + + gal_view_instance_save_as (view_instance); +} /** * E_SHELL_WINDOW_ACTION_IMPORT: @@ -1181,7 +1195,7 @@ static GtkActionEntry shell_gal_view_entries[] = { N_("Save Custom View..."), NULL, N_("Save current custom view"), - NULL }, /* Handled by subclasses. */ + G_CALLBACK (action_gal_save_custom_view_cb) }, /*** Menus ***/ |