[fractal] widgets/message.rs: Implement hold to right click



commit ca3dd2d3b039074c4dad224c2c793d38b1b3a40b
Author: Christopher Davis <brainblasted disroot org>
Date:   Wed Jan 30 12:45:13 2019 -0500

    widgets/message.rs: Implement hold to right click
    
    Right click is not possible on touchscreens, so our right click menu would be inaccessible.
    
    Here we use GtkGestureLongPress to create our right click menu, but only on touch devices.

 fractal-gtk/src/uitypes.rs         |  2 +-
 fractal-gtk/src/widgets/message.rs | 20 ++++++++++++++++++--
 2 files changed, 19 insertions(+), 3 deletions(-)
---
diff --git a/fractal-gtk/src/uitypes.rs b/fractal-gtk/src/uitypes.rs
index f3078af3..111986aa 100644
--- a/fractal-gtk/src/uitypes.rs
+++ b/fractal-gtk/src/uitypes.rs
@@ -26,7 +26,7 @@ pub struct MessageContent {
 }
 
 /* To-Do: this should be moved to a file collecting all structs used in the UI */
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Copy, Clone, PartialEq)]
 pub enum RowType {
     #[allow(dead_code)]
     Divider,
diff --git a/fractal-gtk/src/widgets/message.rs b/fractal-gtk/src/widgets/message.rs
index c07b6b6b..f2c2c9e5 100644
--- a/fractal-gtk/src/widgets/message.rs
+++ b/fractal-gtk/src/widgets/message.rs
@@ -36,6 +36,7 @@ pub struct MessageBox {
     username: gtk::Label,
     pub username_event_box: gtk::EventBox,
     eventbox: gtk::EventBox,
+    gesture: gtk::GestureLongPress,
     row: gtk::ListBoxRow,
     image: Option<gtk::DrawingArea>,
     header: bool,
@@ -47,14 +48,18 @@ impl MessageBox {
         let eb = gtk::EventBox::new();
         let eventbox = gtk::EventBox::new();
         let row = gtk::ListBoxRow::new();
+        let gesture = gtk::GestureLongPress::new(&eventbox);
 
         username.set_ellipsize(pango::EllipsizeMode::End);
+        gesture.set_propagation_phase(gtk::PropagationPhase::Capture);
+        gesture.set_touch_only(true);
 
         MessageBox {
             backend: backend,
             username: username,
             username_event_box: eb,
             eventbox,
+            gesture,
             row,
             image: None,
             header: true,
@@ -499,15 +504,26 @@ impl MessageBox {
         } else {
             self.eventbox.upcast_ref::<gtk::Widget>()
         };
+
+        let evbox = eventbox_weak.clone();
+        let i = id.clone();
         widget.connect_button_press_event(move |w, e| {
             if e.get_button() == 3 {
-                let eventbox = upgrade_weak!(eventbox_weak, gtk::Inhibit(false));
-                MessageMenu::new(id.as_str(), &mtype, &redactable, &eventbox, w);
+                let eventbox = upgrade_weak!(evbox, gtk::Inhibit(false));
+                MessageMenu::new(i.as_str(), &mtype, &redactable, &eventbox, w);
                 Inhibit(true)
             } else {
                 Inhibit(false)
             }
         });
+
+        let widget_weak = widget.downgrade();
+        self.gesture.connect_pressed(move |_, _, _| {
+            let eventbox = upgrade_weak!(eventbox_weak);
+            let widget = upgrade_weak!(widget_weak);
+
+            MessageMenu::new(&id, &mtype, &redactable, &eventbox, &widget);
+        });
         None
     }
 


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