diff --git a/src/Widgets/WallpaperContainer.vala b/src/Widgets/WallpaperContainer.vala index ee7d6192c..1c333aa92 100644 --- a/src/Widgets/WallpaperContainer.vala +++ b/src/Widgets/WallpaperContainer.vala @@ -25,7 +25,6 @@ public class PantheonShell.WallpaperContainer : Gtk.FlowBoxChild { private const int THUMB_HEIGHT = 100; private Gtk.Grid card_box; - private Gtk.Menu context_menu; private Gtk.Revealer check_revealer; private Granite.AsyncImage image; @@ -35,6 +34,8 @@ public class PantheonShell.WallpaperContainer : Gtk.FlowBoxChild { public Gdk.Pixbuf thumb { get; set; } public uint64 creation_date = 0; + private Gtk.GestureMultiPress secondary_click_gesture; + private int scale; public bool checked { @@ -109,38 +110,49 @@ public class PantheonShell.WallpaperContainer : Gtk.FlowBoxChild { overlay.add (card_box); overlay.add_overlay (check_revealer); - var event_box = new Gtk.EventBox (); - event_box.add (overlay); - halign = Gtk.Align.CENTER; valign = Gtk.Align.CENTER; margin = 6; - add (event_box); + + child = overlay; if (uri != null) { - var move_to_trash = new Gtk.MenuItem.with_label (_("Remove")); - move_to_trash.activate.connect (() => trash ()); + var remove_wallpaper_action = new SimpleAction ("trash", null); + remove_wallpaper_action.activate.connect (() => trash ()); + + var action_group = new SimpleActionGroup (); + action_group.add_action (remove_wallpaper_action); + + insert_action_group ("wallpaper", action_group); var file = File.new_for_uri (uri); try { var info = file.query_info ("*", FileQueryInfoFlags.NONE); creation_date = info.get_attribute_uint64 (GLib.FileAttribute.TIME_CREATED); - move_to_trash.sensitive = info.get_attribute_boolean (GLib.FileAttribute.ACCESS_CAN_DELETE); + remove_wallpaper_action.set_enabled (info.get_attribute_boolean (GLib.FileAttribute.ACCESS_CAN_DELETE)); } catch (Error e) { critical (e.message); } - context_menu = new Gtk.Menu (); - context_menu.append (move_to_trash); + var menu_model = new Menu (); + menu_model.append (_("Remove"), "wallpaper.trash"); + + var context_menu = new Gtk.Menu.from_model (menu_model) { + attach_widget = this + }; context_menu.show_all (); + + secondary_click_gesture = new Gtk.GestureMultiPress (overlay) { + button = Gdk.BUTTON_SECONDARY + }; + secondary_click_gesture.released.connect (() => { + context_menu.popup_at_pointer (null); + }); } activate.connect (() => { checked = true; }); - - event_box.button_press_event.connect (show_context_menu); - try { if (uri != null) { if (thumb_path != null && thumb_valid) { @@ -193,14 +205,6 @@ public class PantheonShell.WallpaperContainer : Gtk.FlowBoxChild { } } - private bool show_context_menu (Gtk.Widget sender, Gdk.EventButton evt) { - if (evt.type == Gdk.EventType.BUTTON_PRESS && evt.button == 3) { - context_menu.popup_at_pointer (null); - return Gdk.EVENT_STOP; - } - return Gdk.EVENT_PROPAGATE; - } - private async void update_thumb () { if (thumb_path == null) { return;