Skip to content

Commit

Permalink
AbstractMountableRow: add empty trash action (#2471)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeremy Wootten <jeremywootten@gmail.com>
  • Loading branch information
danirabbit and jeremypw authored Sep 7, 2024
1 parent c7858fb commit 726ec5b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
21 changes: 3 additions & 18 deletions libcore/PopupMenuBuilder.vala
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
***/

public class PopupMenuBuilder : Object {
public delegate void MenuitemCallback (Gtk.MenuItem menu_item);
Gtk.MenuItem[] menu_items = {};
public uint n_items { get { return menu_items.length; }}

public Gtk.Menu build (Gtk.Widget attach_widget) {
var popupmenu = new Gtk.Menu () {
Expand Down Expand Up @@ -53,14 +51,8 @@ public class PopupMenuBuilder : Object {
add_with_action_name (_("Safely Remove"), "mountable.safely-remove");
}

public PopupMenuBuilder add_empty_mount_trash (MenuitemCallback cb) {
var menu_item = new Gtk.MenuItem.with_mnemonic (_("Permanently Delete Trash on this Mount"));
menu_item.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
return add_item (menu_item, cb);
}

public PopupMenuBuilder add_separator () {
return add_item (new Gtk.SeparatorMenuItem ());
public void add_separator () {
add_item (new Gtk.SeparatorMenuItem ());
}

public void add_with_action_name (string label, string action_name) {
Expand All @@ -73,15 +65,8 @@ public class PopupMenuBuilder : Object {
menu_items += menu_item;
}

public PopupMenuBuilder add_item (Gtk.MenuItem menu_item, MenuitemCallback? cb = null) {
if (cb != null) {
menu_item.activate.connect ((menu_item) => {
cb (menu_item);
});
}

public void add_item (Gtk.MenuItem menu_item) {
menu_item.show ();
menu_items += menu_item;
return this;
}
}
18 changes: 12 additions & 6 deletions src/View/Sidebar/AbstractMountableRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,15 @@ public abstract class Sidebar.AbstractMountableRow : Sidebar.BookmarkRow, Sideba
var unmount_action = new SimpleAction ("unmount", null);
unmount_action.activate.connect (() => unmount_mount.begin ());

var empty_trash_action = new SimpleAction ("empty-trash", null);
empty_trash_action.activate.connect (() => Files.FileOperations.empty_trash_for_mount (this, mount));

var action_group = new SimpleActionGroup ();
action_group.add_action (safely_remove_action);
action_group.add_action (eject_action);
action_group.add_action (properties_action);
action_group.add_action (unmount_action);
action_group.add_action (empty_trash_action);

insert_action_group ("mountable", action_group);
}
Expand Down Expand Up @@ -256,12 +260,14 @@ public abstract class Sidebar.AbstractMountableRow : Sidebar.BookmarkRow, Sideba

if (mount != null) {
if (Files.FileOperations.has_trash_files (mount)) {
menu_builder
.add_separator ()
.add_empty_mount_trash (() => {
Files.FileOperations.empty_trash_for_mount (this, mount);
})
;
var trash_menu_item = new Gtk.MenuItem.with_mnemonic (_("Permanently Delete Trash on this Mount"));
trash_menu_item.set_detailed_action_name (
Action.print_detailed_name ("mountable.empty-trash", null)
);
trash_menu_item.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);

menu_builder.add_separator ();
menu_builder.add_item (trash_menu_item);
}

if (mount.can_unmount ()) {
Expand Down

0 comments on commit 726ec5b

Please sign in to comment.