Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions src/Views/Wallpaper.vala
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,14 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
add_wallpaper_button.clicked.connect (show_wallpaper_chooser);

drop_target.drop.connect (on_drag_data_received);

var remove_wallpaper_action = new SimpleAction ("trash", VariantType.STRING);
remove_wallpaper_action.activate.connect (mark_for_removal);

var action_group = new SimpleActionGroup ();
action_group.add_action (remove_wallpaper_action);

insert_action_group ("wallpaper", action_group);
}

private Gtk.Widget create_widget_func (Object object) {
Expand Down Expand Up @@ -413,11 +421,6 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
var wallpaper = new WallpaperContainer (uri, thumb_path, thumb_valid);
wallpaper_model.insert_sorted (wallpaper, wallpapers_sort_function);

wallpaper.trash.connect (() => {
send_undo_toast ();
mark_for_removal (wallpaper);
});

// Select the wallpaper if it is the current wallpaper
if (current_wallpaper_path.has_suffix (uri) && gnome_background_settings.get_string ("picture-options") != "none") {
this.wallpaper_view.select_child ((Gtk.FlowBoxChild) wallpaper.get_parent ());
Expand Down Expand Up @@ -488,10 +491,6 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
child = child.get_next_sibling ();
}

if (wallpaper_for_removal != null) {
confirm_removal ();
}

var toast = new Granite.Toast (_("Wallpaper Deleted"));
toast.set_default_action (_("Undo"));

Expand All @@ -505,11 +504,21 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
toast.send_notification ();
}

private void mark_for_removal (WallpaperContainer wallpaper) {
uint pos = -1;
if (wallpaper_model.find (wallpaper, out pos)) {
wallpaper_model.remove (pos);
wallpaper_for_removal = wallpaper;
private void mark_for_removal (GLib.Variant? object) {
var uri = object.get_string ();

for (var i = 0; i <= wallpaper_model.get_n_items (); i++) {
var wallpaper_container = (WallpaperContainer) wallpaper_model.get_item (i);
if (wallpaper_container.uri == uri) {
if (wallpaper_for_removal != null) {
confirm_removal ();
}
wallpaper_for_removal = wallpaper_container;
wallpaper_model.remove (i);

send_undo_toast ();
break;
}
}
}

Expand All @@ -525,7 +534,7 @@ public class PantheonShell.Wallpaper : Switchboard.SettingsPage {
}

private void undo_removal () {
wallpaper_model.append (wallpaper_for_removal);
wallpaper_model.insert_sorted (wallpaper_for_removal, wallpapers_sort_function);
wallpaper_for_removal = null;
}
}
22 changes: 11 additions & 11 deletions src/Widgets/WallpaperContainer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*/

public class PantheonShell.WallpaperContainer : Granite.Bin {
public signal void trash ();

protected const int THUMB_WIDTH = 256;
protected const int THUMB_HEIGHT = 144;
protected Gtk.Picture image;
Expand Down Expand Up @@ -84,25 +82,27 @@ public class PantheonShell.WallpaperContainer : Granite.Bin {
child = overlay;

if (uri != null) {
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 detailed_action_name = "wallpaper.trash";

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);
remove_wallpaper_action.set_enabled (info.get_attribute_boolean (GLib.FileAttribute.ACCESS_CAN_DELETE));

if (info.get_attribute_boolean (GLib.FileAttribute.ACCESS_CAN_DELETE)) {
detailed_action_name = GLib.Action.print_detailed_name (
"wallpaper.trash", new Variant.string (uri)
);
}
} catch (Error e) {
critical (e.message);
}

var menu_model = new Menu ();
menu_model.append (_("Remove"), "wallpaper.trash");
menu_model.append (
_("Remove"),
detailed_action_name
);

var context_menu = new Gtk.PopoverMenu.from_model (menu_model) {
halign = START,
Expand Down