Skip to content

Commit 29da72f

Browse files
authored
AttachmentButton: Use Gtk.Gesture (#1001)
1 parent b8584dd commit 29da72f

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/MessageList/AttachmentButton.vala

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,6 @@ public class AttachmentButton : Gtk.FlowBoxChild {
5959

6060
var menu = new Gtk.Menu.from_model (context_menu_model);
6161

62-
var event_box = new Gtk.EventBox ();
63-
event_box.events |= Gdk.EventMask.BUTTON_PRESS_MASK;
64-
event_box.button_press_event.connect ((event) => {
65-
if (event.button == Gdk.BUTTON_SECONDARY) {
66-
menu.attach_widget = this;
67-
menu.show_all ();
68-
menu.popup_at_pointer (event);
69-
} else {
70-
activate ();
71-
}
72-
73-
return true;
74-
});
75-
7662
var grid = new Gtk.Grid () {
7763
margin_top = 6,
7864
margin_bottom = 6,
@@ -124,9 +110,28 @@ public class AttachmentButton : Gtk.FlowBoxChild {
124110
grid.attach (preview_image, 0, 0, 1, 2);
125111
grid.attach (name_label, 1, 0, 1, 1);
126112
grid.attach (size_label, 1, 1, 1, 1);
127-
event_box.add (grid);
128-
add (event_box);
113+
114+
var event_box = new Gtk.EventBox () {
115+
child = grid
116+
};
117+
118+
child = event_box;
129119
show_all ();
120+
121+
var gesture_click = new Gtk.GestureMultiPress (event_box) {
122+
button = 0
123+
};
124+
125+
gesture_click.released.connect ((n_press, x, y) => {
126+
if (gesture_click.get_current_button () == Gdk.BUTTON_SECONDARY) {
127+
menu.attach_widget = this;
128+
menu.popup_at_pointer ();
129+
} else {
130+
activate ();
131+
}
132+
133+
gesture_click.set_state (CLAIMED);
134+
});
130135
}
131136

132137
private void on_save_as () {

0 commit comments

Comments
 (0)