[geary/wip/765516-gtk-widget-conversation-viewer: 105/207] Emulate browser-style scroll-on-spacebar.



commit 1c6745256e7a1bbe2f5b7fb6b6163af335cda757
Author: Michael James Gratton <mike vee net>
Date:   Fri Jul 8 18:21:52 2016 +1000

    Emulate browser-style scroll-on-spacebar.

 .../conversation-viewer/conversation-viewer.vala   |   23 ++++++++++++++++++++
 ui/conversation-viewer.ui                          |    2 +
 2 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/src/client/conversation-viewer/conversation-viewer.vala 
b/src/client/conversation-viewer/conversation-viewer.vala
index 8c21b9a..74acfa7 100644
--- a/src/client/conversation-viewer/conversation-viewer.vala
+++ b/src/client/conversation-viewer/conversation-viewer.vala
@@ -705,6 +705,13 @@ public class ConversationViewer : Gtk.Stack {
                 return true;
             });
 
+        // Capture key events on the email's web views to allow
+        // scrolling on Space, etc.
+        conversation_message.web_view.key_press_event.connect(on_conversation_key_press);
+        foreach (ConversationMessage attached in conversation_email.attached_messages) {
+            attached.web_view.key_press_event.connect(on_conversation_key_press);
+        }
+
         Gtk.ListBoxRow row = new Gtk.ListBoxRow();
         row.show();
         row.add(conversation_email);
@@ -846,6 +853,22 @@ public class ConversationViewer : Gtk.Stack {
         return SearchState.SEARCH_FOLDER;
     }
 
+    [GtkCallback]
+    private bool on_conversation_key_press(Gtk.Widget widget, Gdk.EventKey event) {
+        // Override some key bindings to get something that works more
+        // like a browser page.
+        if (event.keyval == Gdk.Key.space) {
+            Gtk.ScrollType dir = Gtk.ScrollType.PAGE_DOWN;
+            if ((event.state & Gdk.ModifierType.SHIFT_MASK) ==
+                Gdk.ModifierType.SHIFT_MASK) {
+                dir = Gtk.ScrollType.PAGE_UP;
+            }
+            conversation_page.scroll_child(dir, false);
+            return true;
+        }
+        return false;
+    }
+
     private ConversationEmail? conversation_email_for_id(Geary.EmailIdentifier id) {
         return (ConversationEmail) email_to_row.get(id).get_child();
     }
diff --git a/ui/conversation-viewer.ui b/ui/conversation-viewer.ui
index 75e3c00..d7e2bce 100644
--- a/ui/conversation-viewer.ui
+++ b/ui/conversation-viewer.ui
@@ -34,8 +34,10 @@
       <object class="GtkScrolledWindow" id="conversation_page">
         <property name="visible">True</property>
         <property name="can_focus">True</property>
+        <property name="events">GDK_KEY_PRESS_MASK | GDK_STRUCTURE_MASK</property>
         <property name="hscrollbar_policy">never</property>
         <property name="shadow_type">in</property>
+        <signal name="key-press-event" handler="on_conversation_key_press" swapped="no"/>
         <child>
           <object class="GtkViewport">
             <property name="visible">True</property>


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