[evolution] I#140 - Single key accelerator triggered in search box



commit 048db5d2f28731728f8fcde2385582fa3b64deb0
Author: Milan Crha <mcrha redhat com>
Date:   Wed Sep 26 19:15:26 2018 +0200

    I#140 - Single key accelerator triggered in search box
    
    Closes https://gitlab.gnome.org/GNOME/evolution/issues/140

 src/modules/mail/e-mail-shell-view-private.c | 37 +++++++++++++++++++++++-----
 src/shell/e-shell-window-private.c           | 33 +++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 6 deletions(-)
---
diff --git a/src/modules/mail/e-mail-shell-view-private.c b/src/modules/mail/e-mail-shell-view-private.c
index d3dd552c4b..0b5ef35444 100644
--- a/src/modules/mail/e-mail-shell-view-private.c
+++ b/src/modules/mail/e-mail-shell-view-private.c
@@ -248,8 +248,9 @@ mail_shell_view_folder_tree_popup_event_cb (EShellView *shell_view,
 }
 
 static gboolean
-mail_shell_view_key_press_event_cb (EMailShellView *mail_shell_view,
-                                    GdkEventKey *event)
+mail_shell_view_process_key_press_event (EMailShellView *mail_shell_view,
+                                        GdkEventKey *event,
+                                        gboolean pass_event)
 {
        EShellView *shell_view;
        EShellWindow *shell_window;
@@ -270,6 +271,14 @@ mail_shell_view_key_press_event_cb (EMailShellView *mail_shell_view,
        reader = E_MAIL_READER (mail_view);
        mail_display = e_mail_reader_get_mail_display (reader);
 
+       if (e_web_view_get_need_input (E_WEB_VIEW (mail_display)) &&
+           gtk_widget_has_focus (GTK_WIDGET (mail_display))) {
+               if (pass_event)
+                       gtk_widget_event (GTK_WIDGET (mail_display), (GdkEvent *) event);
+
+               return pass_event;
+       }
+
        switch (event->keyval) {
                case GDK_KEY_space:
                        action = ACTION (MAIL_SMART_FORWARD);
@@ -283,15 +292,26 @@ mail_shell_view_key_press_event_cb (EMailShellView *mail_shell_view,
                        return FALSE;
        }
 
-       if (e_web_view_get_need_input (E_WEB_VIEW (mail_display)) &&
-           gtk_widget_has_focus (GTK_WIDGET (mail_display)))
-               return FALSE;
-
        gtk_action_activate (action);
 
        return TRUE;
 }
 
+static gboolean
+mail_shell_view_key_press_event_cb (EMailShellView *mail_shell_view,
+                                    GdkEventKey *event)
+{
+       return mail_shell_view_process_key_press_event (mail_shell_view, event, FALSE);
+}
+
+static gboolean
+mail_shell_window_key_press_event_cb (EMailShellView *mail_shell_view,
+                                     GdkEventKey *event,
+                                     EShellWindow *shell_window)
+{
+       return mail_shell_view_process_key_press_event (mail_shell_view, event, TRUE);
+}
+
 static gboolean
 mail_shell_view_message_list_key_press_cb (EMailShellView *mail_shell_view,
                                            gint row,
@@ -655,6 +675,11 @@ e_mail_shell_view_private_constructed (EMailShellView *mail_shell_view)
                G_CALLBACK (e_mail_shell_view_update_send_receive_menus),
                mail_shell_view, G_CONNECT_AFTER | G_CONNECT_SWAPPED);
 
+       g_signal_connect_object (
+               shell_window, "key-press-event",
+               G_CALLBACK (mail_shell_window_key_press_event_cb),
+               mail_shell_view, G_CONNECT_SWAPPED);
+
        /* Need to keep the handler ID so we can disconnect it in
         * dispose().  The shell outlives us and we don't want it
         * invoking callbacks on finalized shell views. */
diff --git a/src/shell/e-shell-window-private.c b/src/shell/e-shell-window-private.c
index 305516e88a..81432c5744 100644
--- a/src/shell/e-shell-window-private.c
+++ b/src/shell/e-shell-window-private.c
@@ -345,6 +345,36 @@ e_shell_window_event_after_cb (EShellWindow *shell_window,
        }
 }
 
+static gboolean
+e_shell_window_key_press_event_cb (GtkWidget *widget,
+                                  GdkEventKey *event)
+{
+       GtkWindow *window;
+       GtkWidget *focused;
+
+       g_return_val_if_fail (E_IS_SHELL_WINDOW (widget), FALSE);
+
+       window = GTK_WINDOW (widget);
+       focused = gtk_window_get_focus (window);
+
+       if ((event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK)) != 0 ||
+           event->keyval == GDK_KEY_Tab ||
+           event->keyval == GDK_KEY_Return ||
+           event->keyval == GDK_KEY_Escape ||
+           event->keyval == GDK_KEY_KP_Tab ||
+           event->keyval == GDK_KEY_KP_Enter)
+               return FALSE;
+
+       if (GTK_IS_ENTRY (focused) ||
+           GTK_IS_EDITABLE (focused) ||
+           (GTK_IS_TREE_VIEW (focused) && gtk_tree_view_get_search_column (GTK_TREE_VIEW (focused)) >= 0)) {
+               gtk_widget_event (focused, (GdkEvent *) event);
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
 static gboolean
 shell_window_check_is_main_instance (GtkApplication *application,
                                     GtkWindow *window)
@@ -634,6 +664,9 @@ e_shell_window_private_constructed (EShellWindow *shell_window)
 
        g_signal_connect (shell_window, "event-after",
                G_CALLBACK (e_shell_window_event_after_cb), NULL);
+
+       g_signal_connect (shell_window, "key-press-event",
+               G_CALLBACK (e_shell_window_key_press_event_cb), NULL);
 }
 
 void


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