Skip to content

Commit

Permalink
move actions to mountable
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit committed Sep 3, 2024
1 parent 469e0cc commit 1ddeddf
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 50 deletions.
8 changes: 4 additions & 4 deletions libcore/PopupMenuBuilder.vala
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ public class PopupMenuBuilder : Object {
}

public void add_unmount (uint32 id) {
add_with_action_name (_("_Unmount"), "device.unmount", id);
add_with_action_name (_("_Unmount"), "mountable.unmount", id);
}

public void add_drive_property (uint32 id) {
add_with_action_name (_("Properties"), "device.properties", id);
add_with_action_name (_("Properties"), "mountable.properties", id);
}

public void add_eject_drive (uint32 id) {
// Do we need different text for USB sticks and optical drives?
add_with_action_name (_("Eject Media"), "device.eject", id);
add_with_action_name (_("Eject Media"), "mountable.eject", id);
}

public void add_safely_remove (uint32 id) {
// Do we need different text for USB sticks and optical drives?
add_with_action_name (_("Safely Remove"), "device.safely-remove", id);
add_with_action_name (_("Safely Remove"), "mountable.safely-remove", id);
}

public PopupMenuBuilder add_bookmark (MenuitemCallback cb) {
Expand Down
48 changes: 44 additions & 4 deletions src/View/Sidebar/AbstractMountableRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,46 @@ public abstract class Sidebar.AbstractMountableRow : Sidebar.BookmarkRow, Sideba
add_mountable_tooltip.begin ();

update_visibilities ();

var safely_remove_action = new SimpleAction ("safely-remove", new VariantType ("u"));
safely_remove_action.activate.connect ((param) => {
var row = SidebarItemInterface.get_item (param.get_uint32 ());
if (row != null && row is AbstractMountableRow) {
((AbstractMountableRow) row).safely_remove_drive.begin ();
}
});

var eject_action = new SimpleAction ("eject", new VariantType ("u"));
eject_action.activate.connect ((param) => {
var row = SidebarItemInterface.get_item (param.get_uint32 ());
if (row != null && row is AbstractMountableRow) {
((AbstractMountableRow) row).eject_drive.begin ();
}
});

var properties_action = new SimpleAction ("properties", new VariantType ("u"));
properties_action.activate.connect ((param) => {
var row = SidebarItemInterface.get_item (param.get_uint32 ());
if (row != null && row is AbstractMountableRow) {
((AbstractMountableRow) row).show_mount_info ();
}
});

var unmount_action = new SimpleAction ("unmount", new VariantType ("u"));
unmount_action.activate.connect ((param) => {
var row = SidebarItemInterface.get_item (param.get_uint32 ());
if (row != null && row is AbstractMountableRow) {
((AbstractMountableRow) row).unmount_mount.begin ();
}
});

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);

insert_action_group ("mountable", action_group);
}

protected void update_visibilities () {
Expand All @@ -179,7 +219,7 @@ public abstract class Sidebar.AbstractMountableRow : Sidebar.BookmarkRow, Sideba
working = item.show_spinner;
}

public async bool unmount_mount () {
protected async bool unmount_mount () {
if (working || !valid || permanent) {
return false;
}
Expand All @@ -203,7 +243,7 @@ public abstract class Sidebar.AbstractMountableRow : Sidebar.BookmarkRow, Sideba
return success;
}

public async void safely_remove_drive () {
protected async void safely_remove_drive () {
if (working || !valid || drive == null) {
return;
}
Expand All @@ -218,7 +258,7 @@ public abstract class Sidebar.AbstractMountableRow : Sidebar.BookmarkRow, Sideba
update_visibilities ();
}

public async void eject_drive () {
protected async void eject_drive () {
if (working || !valid || drive == null) {
return;
}
Expand Down Expand Up @@ -341,7 +381,7 @@ public abstract class Sidebar.AbstractMountableRow : Sidebar.BookmarkRow, Sideba

protected virtual void on_mount_removed (Mount removed_mount) {}
protected virtual void on_mount_added (Mount added_mount) {}
public virtual void show_mount_info () {}
protected virtual void show_mount_info () {}
protected virtual async bool get_filesystem_space (Cancellable? update_cancellable) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/View/Sidebar/BookmarkRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public class Sidebar.BookmarkRow : Gtk.ListBoxRow, SidebarItemInterface {
.popup_at_pointer (null);
} else {
menu_builder
.build (parent)
.build (this)
.popup_at_pointer (null);
}
}
Expand Down
40 changes: 0 additions & 40 deletions src/View/Sidebar/DeviceListBox.vala
Original file line number Diff line number Diff line change
Expand Up @@ -38,46 +38,6 @@ public class Sidebar.DeviceListBox : Gtk.Box, Sidebar.SidebarListInterface {

add (list_box);

var safely_remove_action = new SimpleAction ("safely-remove", new VariantType ("u"));
safely_remove_action.activate.connect ((param) => {
var row = SidebarItemInterface.get_item (param.get_uint32 ());
if (row != null && row is AbstractMountableRow) {
((AbstractMountableRow) row).safely_remove_drive.begin ();
}
});

var eject_action = new SimpleAction ("eject", new VariantType ("u"));
eject_action.activate.connect ((param) => {
var row = SidebarItemInterface.get_item (param.get_uint32 ());
if (row != null && row is AbstractMountableRow) {
((AbstractMountableRow) row).eject_drive.begin ();
}
});

var properties_action = new SimpleAction ("properties", new VariantType ("u"));
properties_action.activate.connect ((param) => {
var row = SidebarItemInterface.get_item (param.get_uint32 ());
if (row != null && row is AbstractMountableRow) {
((AbstractMountableRow) row).show_mount_info ();
}
});

var unmount_action = new SimpleAction ("unmount", new VariantType ("u"));
unmount_action.activate.connect ((param) => {
var row = SidebarItemInterface.get_item (param.get_uint32 ());
if (row != null && row is AbstractMountableRow) {
((AbstractMountableRow) row).unmount_mount.begin ();
}
});

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

insert_action_group ("device", device_action_group);

volume_monitor = VolumeMonitor.@get ();
volume_monitor.drive_connected.connect (bookmark_drive);
volume_monitor.mount_added.connect (bookmark_mount_without_volume);
Expand Down
2 changes: 1 addition & 1 deletion src/View/Sidebar/DriveRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public class Sidebar.DriveRow : Sidebar.AbstractMountableRow, SidebarItemInterfa
var menu_builder = new PopupMenuBuilder ();
menu_builder.add_safely_remove (id);

menu_builder.build (parent).popup_at_pointer (null);
menu_builder.build (this).popup_at_pointer (null);
}
}
}

0 comments on commit 1ddeddf

Please sign in to comment.