[evolution/gnome-3-36] I#836 - Shell: Executes shortcuts from inactive view



commit 50c3e3ebccb252f75e8f1c567c3298bb2d37ebcf
Author: Milan Crha <mcrha redhat com>
Date:   Mon Mar 16 14:30:45 2020 +0100

    I#836 - Shell: Executes shortcuts from inactive view
    
    Closes https://gitlab.gnome.org/GNOME/evolution/issues/836

 .../addressbook/e-book-shell-view-private.c        |  4 +--
 src/modules/calendar/e-cal-shell-view-private.c    |  4 +--
 src/modules/calendar/e-memo-shell-view-private.c   |  4 +--
 src/modules/calendar/e-task-shell-view-private.c   |  4 +--
 src/modules/mail/e-mail-shell-view-private.c       |  8 ++---
 src/plugins/templates/templates.c                  |  2 +-
 src/shell/e-shell-window-private.c                 | 40 ++++++++++++++++++++++
 src/shell/e-shell-window-private.h                 |  1 +
 src/shell/e-shell-window.c                         | 25 +++++++++++++-
 src/shell/e-shell-window.h                         |  4 +++
 10 files changed, 82 insertions(+), 14 deletions(-)
---
diff --git a/src/modules/addressbook/e-book-shell-view-private.c 
b/src/modules/addressbook/e-book-shell-view-private.c
index de22fa845c..8cd6842ddd 100644
--- a/src/modules/addressbook/e-book-shell-view-private.c
+++ b/src/modules/addressbook/e-book-shell-view-private.c
@@ -588,8 +588,8 @@ e_book_shell_view_private_constructed (EBookShellView *book_shell_view)
        shell_window = e_shell_view_get_shell_window (shell_view);
        shell = e_shell_window_get_shell (shell_window);
 
-       e_shell_window_add_action_group (shell_window, "contacts");
-       e_shell_window_add_action_group (shell_window, "contacts-filter");
+       e_shell_window_add_action_group_full (shell_window, "contacts", "addressbook");
+       e_shell_window_add_action_group_full (shell_window, "contacts-filter", "addressbook");
 
        /* Cache these to avoid lots of awkward casting. */
        priv->book_shell_backend = g_object_ref (shell_backend);
diff --git a/src/modules/calendar/e-cal-shell-view-private.c b/src/modules/calendar/e-cal-shell-view-private.c
index 3701d390ed..4a1000362f 100644
--- a/src/modules/calendar/e-cal-shell-view-private.c
+++ b/src/modules/calendar/e-cal-shell-view-private.c
@@ -384,8 +384,8 @@ e_cal_shell_view_private_constructed (ECalShellView *cal_shell_view)
        shell_window = e_shell_view_get_shell_window (shell_view);
        shell = e_shell_window_get_shell (shell_window);
 
-       e_shell_window_add_action_group (shell_window, "calendar");
-       e_shell_window_add_action_group (shell_window, "calendar-filter");
+       e_shell_window_add_action_group_full (shell_window, "calendar", "calendar");
+       e_shell_window_add_action_group_full (shell_window, "calendar-filter", "calendar");
 
        /* Cache these to avoid lots of awkward casting. */
        priv->cal_shell_backend = g_object_ref (shell_backend);
diff --git a/src/modules/calendar/e-memo-shell-view-private.c 
b/src/modules/calendar/e-memo-shell-view-private.c
index 8ac5946208..e6bff42d85 100644
--- a/src/modules/calendar/e-memo-shell-view-private.c
+++ b/src/modules/calendar/e-memo-shell-view-private.c
@@ -113,8 +113,8 @@ e_memo_shell_view_private_constructed (EMemoShellView *memo_shell_view)
        shell_window = e_shell_view_get_shell_window (shell_view);
        shell = e_shell_window_get_shell (shell_window);
 
-       e_shell_window_add_action_group (shell_window, "memos");
-       e_shell_window_add_action_group (shell_window, "memos-filter");
+       e_shell_window_add_action_group_full (shell_window, "memos", "memos");
+       e_shell_window_add_action_group_full (shell_window, "memos-filter", "memos");
 
        /* Cache these to avoid lots of awkward casting. */
        priv->memo_shell_backend = g_object_ref (shell_backend);
diff --git a/src/modules/calendar/e-task-shell-view-private.c 
b/src/modules/calendar/e-task-shell-view-private.c
index 6bbbced2b2..79482a5d90 100644
--- a/src/modules/calendar/e-task-shell-view-private.c
+++ b/src/modules/calendar/e-task-shell-view-private.c
@@ -228,8 +228,8 @@ e_task_shell_view_private_constructed (ETaskShellView *task_shell_view)
        shell_window = e_shell_view_get_shell_window (shell_view);
        shell = e_shell_window_get_shell (shell_window);
 
-       e_shell_window_add_action_group (shell_window, "tasks");
-       e_shell_window_add_action_group (shell_window, "tasks-filter");
+       e_shell_window_add_action_group_full (shell_window, "tasks", "tasks");
+       e_shell_window_add_action_group_full (shell_window, "tasks-filter", "tasks");
 
        /* Cache these to avoid lots of awkward casting. */
        priv->task_shell_backend = g_object_ref (shell_backend);
diff --git a/src/modules/mail/e-mail-shell-view-private.c b/src/modules/mail/e-mail-shell-view-private.c
index f5022176cb..e99b76a621 100644
--- a/src/modules/mail/e-mail-shell-view-private.c
+++ b/src/modules/mail/e-mail-shell-view-private.c
@@ -543,10 +543,10 @@ e_mail_shell_view_private_constructed (EMailShellView *mail_shell_view)
        label_store = e_mail_ui_session_get_label_store (
                E_MAIL_UI_SESSION (session));
 
-       e_shell_window_add_action_group (shell_window, "mail");
-       e_shell_window_add_action_group (shell_window, "mail-filter");
-       e_shell_window_add_action_group (shell_window, "mail-labels");
-       e_shell_window_add_action_group (shell_window, "search-folders");
+       e_shell_window_add_action_group_full (shell_window, "mail", "mail");
+       e_shell_window_add_action_group_full (shell_window, "mail-filter", "mail");
+       e_shell_window_add_action_group_full (shell_window, "mail-labels", "mail");
+       e_shell_window_add_action_group_full (shell_window, "search-folders", "mail");
 
        /* Cache these to avoid lots of awkward casting. */
        priv->mail_shell_backend = g_object_ref (shell_backend);
diff --git a/src/plugins/templates/templates.c b/src/plugins/templates/templates.c
index 6345be0bef..6239555450 100644
--- a/src/plugins/templates/templates.c
+++ b/src/plugins/templates/templates.c
@@ -971,7 +971,7 @@ mail_shell_view_created_cb (EShellWindow *shell_window,
        TemplatesData *td;
 
        ui_manager = e_shell_window_get_ui_manager (shell_window);
-       e_shell_window_add_action_group (shell_window, "templates");
+       e_shell_window_add_action_group_full (shell_window, "templates", "mail");
        action_group = e_lookup_action_group (ui_manager, "templates");
 
        shell_backend = e_shell_view_get_shell_backend (shell_view);
diff --git a/src/shell/e-shell-window-private.c b/src/shell/e-shell-window-private.c
index c941d9c304..008eeb6890 100644
--- a/src/shell/e-shell-window-private.c
+++ b/src/shell/e-shell-window-private.c
@@ -220,6 +220,7 @@ e_shell_window_private_init (EShellWindow *shell_window)
        priv->ui_manager = gtk_ui_manager_new ();
        priv->loaded_views = loaded_views;
        priv->signal_handler_ids = signal_handler_ids;
+       priv->action_groups_by_view = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, 
(GDestroyNotify) g_ptr_array_unref);
 
        /* XXX This kind of violates the shell window being unaware
         *     of specific shell views, but we need a sane fallback. */
@@ -724,11 +725,48 @@ e_shell_window_private_finalize (EShellWindow *shell_window)
        EShellWindowPrivate *priv = shell_window->priv;
 
        g_hash_table_destroy (priv->loaded_views);
+       g_hash_table_destroy (priv->action_groups_by_view);
 
        g_slist_free_full (priv->postponed_alerts, g_object_unref);
        g_free (priv->geometry);
 }
 
+static void
+e_shell_window_activate_action_groups_for_view (EShellWindow *shell_window,
+                                               const gchar *view_name)
+{
+       GHashTableIter iter;
+       gpointer key, value;
+
+       g_return_if_fail (E_IS_SHELL_WINDOW (shell_window));
+
+       if (!e_shell_window_get_ui_manager (shell_window))
+               return;
+
+       g_hash_table_iter_init (&iter, shell_window->priv->action_groups_by_view);
+
+       while (g_hash_table_iter_next (&iter, &key, &value)) {
+               gboolean is_active = g_strcmp0 (key, view_name) == 0;
+               GPtrArray *action_groups = value;
+               guint ii;
+
+               /* The 'calendar' view uses actions from 'memos' and 'tasks',
+                  thus make sure these are active too. */
+               if (!is_active && g_strcmp0 (view_name, "calendar") == 0 &&
+                   (g_strcmp0 (key, "memos") == 0 || g_strcmp0 (key, "tasks") == 0))
+                       is_active = TRUE;
+
+               for (ii = 0; ii < action_groups->len; ii++) {
+                       GtkActionGroup *action_group = g_ptr_array_index (action_groups, ii);
+
+                       /* Set both, because using 'visible' doesn't work for the first key press,
+                          while 'sensitive' does, even it is used by some 'update-actions' handlers. */
+                       gtk_action_group_set_visible (action_group, is_active);
+                       gtk_action_group_set_sensitive (action_group, is_active);
+               }
+       }
+}
+
 void
 e_shell_window_switch_to_view (EShellWindow *shell_window,
                                const gchar *view_name)
@@ -743,6 +781,8 @@ e_shell_window_switch_to_view (EShellWindow *shell_window,
 
        shell_view = e_shell_window_get_shell_view (shell_window, view_name);
 
+       e_shell_window_activate_action_groups_for_view (shell_window, view_name);
+
        shell_window->priv->active_view = view_name;
        g_object_notify (G_OBJECT (shell_window), "active-view");
 
diff --git a/src/shell/e-shell-window-private.h b/src/shell/e-shell-window-private.h
index 8dbad3a5e2..ae10390521 100644
--- a/src/shell/e-shell-window-private.h
+++ b/src/shell/e-shell-window-private.h
@@ -69,6 +69,7 @@ struct _EShellWindowPrivate {
 
        GHashTable *loaded_views;
        const gchar *active_view;
+       GHashTable *action_groups_by_view;
 
        /*** Widgetry ***/
 
diff --git a/src/shell/e-shell-window.c b/src/shell/e-shell-window.c
index 20d8f67c55..fcd843be0e 100644
--- a/src/shell/e-shell-window.c
+++ b/src/shell/e-shell-window.c
@@ -1574,6 +1574,14 @@ e_shell_window_set_safe_mode (EShellWindow *shell_window,
 void
 e_shell_window_add_action_group (EShellWindow *shell_window,
                                  const gchar *group_name)
+{
+       e_shell_window_add_action_group_full (shell_window, group_name, NULL);
+}
+
+void
+e_shell_window_add_action_group_full (EShellWindow *shell_window,
+                                     const gchar *group_name,
+                                     const gchar *for_view_name)
 {
        GtkActionGroup *action_group;
        GtkUIManager *ui_manager;
@@ -1588,7 +1596,22 @@ e_shell_window_add_action_group (EShellWindow *shell_window,
        action_group = gtk_action_group_new (group_name);
        gtk_action_group_set_translation_domain (action_group, domain);
        gtk_ui_manager_insert_action_group (ui_manager, action_group, 0);
-       g_object_unref (action_group);
+
+       if (for_view_name) {
+               GPtrArray *view_groups;
+
+               view_groups = g_hash_table_lookup (shell_window->priv->action_groups_by_view, for_view_name);
+
+               if (!view_groups) {
+                       view_groups = g_ptr_array_new_with_free_func (g_object_unref);
+                       g_hash_table_insert (shell_window->priv->action_groups_by_view, g_strdup 
(for_view_name), view_groups);
+               }
+
+               /* Takes ownership of the action_group. */
+               g_ptr_array_add (view_groups, action_group);
+       } else {
+               g_object_unref (action_group);
+       }
 }
 
 static void
diff --git a/src/shell/e-shell-window.h b/src/shell/e-shell-window.h
index b678f37803..df0a07cc4c 100644
--- a/src/shell/e-shell-window.h
+++ b/src/shell/e-shell-window.h
@@ -102,6 +102,10 @@ EFocusTracker *    e_shell_window_get_focus_tracker
 GtkUIManager * e_shell_window_get_ui_manager   (EShellWindow *shell_window);
 GtkAction *    e_shell_window_get_action       (EShellWindow *shell_window,
                                                 const gchar *action_name);
+void           e_shell_window_add_action_group_full
+                                               (EShellWindow *shell_window,
+                                                const gchar *group_name,
+                                                const gchar *for_view_name);
 GtkActionGroup *e_shell_window_get_action_group        (EShellWindow *shell_window,
                                                 const gchar *group_name);
 GtkWidget *    e_shell_window_get_managed_widget


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]