feat: show context menu on longpress

This commit is contained in:
Evangelos Paterakis 2023-01-22 11:15:47 +02:00
parent a43ce8d6ba
commit 4e53d0e4b5
No known key found for this signature in database
GPG Key ID: FE5185F095BFC8C9
2 changed files with 14 additions and 0 deletions

View File

@ -4,6 +4,7 @@ public class Tooth.Widgets.Attachment.Item : Adw.Bin {
public API.Attachment entity { get; set; default = null; }
protected GestureClick gesture_click_controller { get; set; }
protected GestureLongPress gesture_lp_controller { get; set; }
protected PopoverMenu context_menu { get; set; }
private const GLib.ActionEntry[] action_entries = {
{"copy-url", copy_url},
@ -76,9 +77,14 @@ public class Tooth.Widgets.Attachment.Item : Adw.Bin {
create_context_menu();
gesture_click_controller = new GestureClick();
gesture_lp_controller = new GestureLongPress();
add_controller(gesture_click_controller);
add_controller(gesture_lp_controller);
gesture_click_controller.button = Gdk.BUTTON_SECONDARY;
gesture_lp_controller.button = Gdk.BUTTON_PRIMARY;
gesture_lp_controller.touch_only = true;
gesture_click_controller.pressed.connect(on_secondary_click);
gesture_lp_controller.pressed.connect(on_secondary_click);
badge = new Label ("") {
valign = Align.END,
@ -127,6 +133,7 @@ public class Tooth.Widgets.Attachment.Item : Adw.Bin {
protected virtual void on_secondary_click () {
gesture_click_controller.set_state(EventSequenceState.CLAIMED);
gesture_lp_controller.set_state(EventSequenceState.CLAIMED);
context_menu.popup();
}

View File

@ -74,6 +74,7 @@ public class Tooth.Widgets.Status : ListBoxRow {
protected StatusActionButton bookmark_button;
protected GestureClick gesture_click_controller { get; set; }
protected GestureLongPress gesture_lp_controller { get; set; }
protected PopoverMenu context_menu { get; set; }
private const GLib.ActionEntry[] action_entries = {
{"copy-url", copy_url},
@ -154,9 +155,14 @@ public class Tooth.Widgets.Status : ListBoxRow {
create_context_menu();
gesture_click_controller = new GestureClick();
gesture_lp_controller = new GestureLongPress();
add_controller(gesture_click_controller);
add_controller(gesture_lp_controller);
gesture_click_controller.button = Gdk.BUTTON_SECONDARY;
gesture_lp_controller.button = Gdk.BUTTON_PRIMARY;
gesture_lp_controller.touch_only = true;
gesture_click_controller.pressed.connect(on_secondary_click);
gesture_lp_controller.pressed.connect(on_secondary_click);
}
public Status (API.Status status) {
@ -195,6 +201,7 @@ public class Tooth.Widgets.Status : ListBoxRow {
protected virtual void on_secondary_click () {
gesture_click_controller.set_state(EventSequenceState.CLAIMED);
gesture_lp_controller.set_state(EventSequenceState.CLAIMED);
context_menu.popup();
}