aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2010-01-23 00:46:34 +0800
committerMatthew Barnes <mbarnes@redhat.com>2010-01-23 00:46:34 +0800
commit48462592cb67d956cf8b4a69eba00153d585c462 (patch)
treee23046a3bcadc5b27457c85b13ec3a2c9460741c
parent97ec849ee54387df954ee461ae371c3054443bfa (diff)
downloadgsoc2013-evolution-48462592cb67d956cf8b4a69eba00153d585c462.tar.gz
gsoc2013-evolution-48462592cb67d956cf8b4a69eba00153d585c462.tar.zst
gsoc2013-evolution-48462592cb67d956cf8b4a69eba00153d585c462.zip
Add a EShellWindow::shell-view-created signal.
The signal uses the name of the newly created shell view as the detail, so for example "shell-view-created::mail" is emitted when the "mail" view is created. Also, add e_shell_window_peek_shell_view() to obtain a shell view if it exists but without instantiating it. Using these new tools, teach the templates plugin to wait for the user to switch to the "mail" view before connecting to its "update-actions" signal. Previously is was instantiating the "mail" view itself.
-rw-r--r--doc/reference/shell/eshell-sections.txt1
-rw-r--r--doc/reference/shell/tmpl/e-shell-window.sgml18
-rw-r--r--plugins/templates/templates.c22
-rw-r--r--shell/e-shell-window.c70
-rw-r--r--shell/e-shell-window.h7
5 files changed, 108 insertions, 10 deletions
diff --git a/doc/reference/shell/eshell-sections.txt b/doc/reference/shell/eshell-sections.txt
index 7dc8df9e72..f65ce604a2 100644
--- a/doc/reference/shell/eshell-sections.txt
+++ b/doc/reference/shell/eshell-sections.txt
@@ -290,6 +290,7 @@ EShellWindow
e_shell_window_new
e_shell_window_get_shell
e_shell_window_get_shell_view
+e_shell_window_peek_shell_view
e_shell_window_get_shell_view_action
e_shell_window_get_ui_manager
e_shell_window_get_action
diff --git a/doc/reference/shell/tmpl/e-shell-window.sgml b/doc/reference/shell/tmpl/e-shell-window.sgml
index 89da4a143c..383c782da2 100644
--- a/doc/reference/shell/tmpl/e-shell-window.sgml
+++ b/doc/reference/shell/tmpl/e-shell-window.sgml
@@ -23,6 +23,14 @@ EShellWindow
</para>
+<!-- ##### SIGNAL EShellWindow::shell-view-created ##### -->
+<para>
+
+</para>
+
+@eshellwindow: the object which received the signal.
+@arg1:
+
<!-- ##### ARG EShellWindow:active-view ##### -->
<para>
@@ -103,6 +111,16 @@ EShellWindow
@Returns:
+<!-- ##### FUNCTION e_shell_window_peek_shell_view ##### -->
+<para>
+
+</para>
+
+@shell_window:
+@view_name:
+@Returns:
+
+
<!-- ##### FUNCTION e_shell_window_get_shell_view_action ##### -->
<para>
diff --git a/plugins/templates/templates.c b/plugins/templates/templates.c
index 1ed02dd22d..b88e26d29d 100644
--- a/plugins/templates/templates.c
+++ b/plugins/templates/templates.c
@@ -767,6 +767,15 @@ init_composer_actions (GtkUIManager *ui_manager,
return TRUE;
}
+static void
+mail_shell_view_created_cb (EShellWindow *shell_window,
+ EShellView *shell_view)
+{
+ g_signal_connect (
+ shell_view, "update-actions",
+ G_CALLBACK (update_actions_cb), NULL);
+}
+
gboolean
init_shell_actions (GtkUIManager *ui_manager,
EShellWindow *shell_window)
@@ -775,8 +784,6 @@ init_shell_actions (GtkUIManager *ui_manager,
GtkActionGroup *action_group;
guint merge_id;
- shell_view = e_shell_window_get_shell_view (shell_window, "mail");
-
/* This is where we keep dynamically-built menu items. */
e_shell_window_add_action_group (shell_window, "templates");
action_group = e_lookup_action_group (ui_manager, "templates");
@@ -787,9 +794,14 @@ init_shell_actions (GtkUIManager *ui_manager,
G_OBJECT (action_group), "merge-id",
GUINT_TO_POINTER (merge_id));
- g_signal_connect (
- shell_view, "update-actions",
- G_CALLBACK (update_actions_cb), NULL);
+ /* Be careful not to instantiate the mail view ourselves. */
+ shell_view = e_shell_window_peek_shell_view (shell_window, "mail");
+ if (shell_view != NULL)
+ mail_shell_view_created_cb (shell_window, shell_view);
+ else
+ g_signal_connect (
+ shell_window, "shell-view-created::mail",
+ G_CALLBACK (mail_shell_view_created_cb), NULL);
return TRUE;
}
diff --git a/shell/e-shell-window.c b/shell/e-shell-window.c
index d3d6107e24..d159406e08 100644
--- a/shell/e-shell-window.c
+++ b/shell/e-shell-window.c
@@ -40,7 +40,13 @@ enum {
PROP_UI_MANAGER
};
+enum {
+ SHELL_VIEW_CREATED,
+ LAST_SIGNAL
+};
+
static gpointer parent_class;
+static gulong signals[LAST_SIGNAL];
static void
shell_window_menubar_update_new_menu (EShellWindow *shell_window)
@@ -753,6 +759,26 @@ shell_window_class_init (EShellWindowClass *class)
_("The shell window's GtkUIManager"),
GTK_TYPE_UI_MANAGER,
G_PARAM_READABLE));
+
+ /**
+ * EShellWindow::shell-view-created
+ * @shell_window: the #EShellWindow which emitted the signal
+ * @shell_view: the new #EShellView
+ *
+ * Emitted when a new #EShellView is instantiated by way of
+ * e_shell_window_get_shell_view(). The signal detail denotes
+ * the new view name, which can be used to obtain notification
+ * of when a particular #EShellView is created.
+ **/
+ signals[SHELL_VIEW_CREATED] = g_signal_new (
+ "shell-view-created",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
+ G_STRUCT_OFFSET (EShellWindowClass, shell_view_created),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE, 1,
+ E_TYPE_SHELL_VIEW);
}
static void
@@ -849,6 +875,9 @@ e_shell_window_get_shell (EShellWindow *shell_window)
* active view name, as returned by e_shell_window_get_active_view(),
* should be requested.
*
+ * The function emits a #EShellWindow::shell-view-created signal with
+ * @view_name as the signal detail when it instantiates an #EShellView.
+ *
* Returns: the requested #EShellView, or %NULL if no such view is
* registered
**/
@@ -858,21 +887,52 @@ e_shell_window_get_shell_view (EShellWindow *shell_window,
{
EShellView *shell_view;
EShellWindowClass *class;
- GHashTable *loaded_views;
g_return_val_if_fail (E_IS_SHELL_WINDOW (shell_window), NULL);
g_return_val_if_fail (view_name != NULL, NULL);
- loaded_views = shell_window->priv->loaded_views;
- shell_view = g_hash_table_lookup (loaded_views, view_name);
-
+ shell_view = e_shell_window_peek_shell_view (shell_window, view_name);
if (shell_view != NULL)
return shell_view;
class = E_SHELL_WINDOW_GET_CLASS (shell_window);
g_return_val_if_fail (class->create_shell_view != NULL, NULL);
- return class->create_shell_view (shell_window, view_name);
+ shell_view = class->create_shell_view (shell_window, view_name);
+
+ g_signal_emit (
+ shell_window, signals[SHELL_VIEW_CREATED],
+ g_quark_from_string (view_name), shell_view);
+
+ return shell_view;
+}
+
+/**
+ * e_shell_window_peek_shell_view:
+ * @shell_window: an #EShellWindow
+ * @view_name: name of a shell view
+ *
+ * Returns the #EShellView named @view_name (see the
+ * <structfield>name</structfield> field in #EShellBackendInfo), or
+ * %NULL if the requested view has not yet been instantiated. Unlike
+ * e_shell_window_get_shell_view(), this function will not instantiate
+ * the view itself.
+ *
+ * Returns: the requested #EShellView, or %NULL if no such view is
+ * instantiated
+ **/
+EShellView *
+e_shell_window_peek_shell_view (EShellWindow *shell_window,
+ const gchar *view_name)
+{
+ GHashTable *loaded_views;
+
+ g_return_val_if_fail (E_IS_SHELL_WINDOW (shell_window), NULL);
+ g_return_val_if_fail (view_name != NULL, NULL);
+
+ loaded_views = shell_window->priv->loaded_views;
+
+ return g_hash_table_lookup (loaded_views, view_name);
}
/**
diff --git a/shell/e-shell-window.h b/shell/e-shell-window.h
index 4ac76ba5d4..0bd71075c9 100644
--- a/shell/e-shell-window.h
+++ b/shell/e-shell-window.h
@@ -73,6 +73,10 @@ struct _EShellWindow {
struct _EShellWindowClass {
GtkWindowClass parent_class;
+ /* Signals */
+ void (*shell_view_created) (EShellWindow *shell_window,
+ struct _EShellView *shell_view);
+
/* These are all protected methods. Not for public use. */
GtkWidget * (*construct_menubar) (EShellWindow *shell_window);
GtkWidget * (*construct_toolbar) (EShellWindow *shell_window);
@@ -92,6 +96,9 @@ EShell * e_shell_window_get_shell (EShellWindow *shell_window);
struct _EShellView *
e_shell_window_get_shell_view (EShellWindow *shell_window,
const gchar *view_name);
+struct _EShellView *
+ e_shell_window_peek_shell_view (EShellWindow *shell_window,
+ const gchar *view_name);
GtkAction * e_shell_window_get_shell_view_action
(EShellWindow *shell_window,
const gchar *view_name);