Skip to content

Commit

Permalink
BookmarkRow: add action group (#2472)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Sep 5, 2024
1 parent 5217ff1 commit 702869f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 35 deletions.
24 changes: 0 additions & 24 deletions libcore/PopupMenuBuilder.vala
Original file line number Diff line number Diff line change
Expand Up @@ -48,35 +48,11 @@ public class PopupMenuBuilder : Object {
return menu;
}

public PopupMenuBuilder add_open (MenuitemCallback cb) {
return add_item (new Gtk.MenuItem.with_mnemonic (_("Open")), cb);
}

public PopupMenuBuilder add_open_tab (MenuitemCallback cb) {
return add_item (new Gtk.MenuItem.with_mnemonic (_("Open in New _Tab")), cb);
}

public PopupMenuBuilder add_open_window (MenuitemCallback cb) {
return add_item (new Gtk.MenuItem.with_mnemonic (_("Open in New _Window")), cb);
}

public PopupMenuBuilder add_remove (MenuitemCallback cb) {
return add_item (new Gtk.MenuItem.with_label (_("Remove")), cb);
}

public PopupMenuBuilder add_rename (MenuitemCallback cb) {
return add_item (new Gtk.MenuItem.with_label (_("Rename")), cb);
}

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

public PopupMenuBuilder add_bookmark (MenuitemCallback cb) {
return add_item (new Gtk.MenuItem.with_mnemonic (_("Add to Bookmarks")), cb);
}

public PopupMenuBuilder add_empty_all_trash (MenuitemCallback cb) {
var volume_monitor = VolumeMonitor.@get ();
int mounts_with_trash = 0;
Expand Down
43 changes: 32 additions & 11 deletions src/View/Sidebar/BookmarkRow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,30 @@ public class Sidebar.BookmarkRow : Gtk.ListBoxRow, SidebarItemInterface {

set_up_drag ();
set_up_drop ();

var open_action = new SimpleAction ("open", null);
open_action.activate.connect (() => activated ());

var open_tab_action = new SimpleAction ("open-tab", null);
open_tab_action.activate.connect (() => activated (NEW_TAB));

var open_window_action = new SimpleAction ("open-window", null);
open_window_action.activate.connect (() => activated (NEW_WINDOW));

var rename_action = new SimpleAction ("rename", null);
rename_action.activate.connect (rename);

var remove_action = new SimpleAction ("remove", null);
remove_action.activate.connect (() => list.remove_item_by_id (id));

var action_group = new SimpleActionGroup ();
action_group.add_action (open_action);
action_group.add_action (open_tab_action);
action_group.add_action (open_window_action);
action_group.add_action (rename_action);
action_group.add_action (remove_action);

insert_action_group ("bookmark", action_group);
}

protected override void update_plugin_data (Files.SidebarPluginItem item) {
Expand Down Expand Up @@ -282,11 +306,11 @@ public class Sidebar.BookmarkRow : Gtk.ListBoxRow, SidebarItemInterface {
}

protected virtual void popup_context_menu () {
var menu_builder = new PopupMenuBuilder ()
.add_open (() => {activated ();})
.add_separator ()
.add_open_tab (() => {activated (Files.OpenFlag.NEW_TAB);})
.add_open_window (() => {activated (Files.OpenFlag.NEW_WINDOW);});
var menu_builder = new PopupMenuBuilder ();
menu_builder.add_with_action_name (_("Open"), "bookmark.open");
menu_builder.add_separator ();
menu_builder.add_with_action_name (_("Open in New _Tab"), "bookmark.open-tab");
menu_builder.add_with_action_name (_("Open in New _Window"), "bookmark.open-window");

add_extra_menu_items (menu_builder);

Expand All @@ -304,15 +328,12 @@ public class Sidebar.BookmarkRow : Gtk.ListBoxRow, SidebarItemInterface {
protected override void add_extra_menu_items (PopupMenuBuilder menu_builder) {
/* Rows under "Bookmarks" can be removed or renamed */
if (!permanent) {
menu_builder
.add_separator ()
.add_remove (() => {list.remove_item_by_id (id);});
menu_builder.add_separator ();
menu_builder.add_with_action_name (_("Remove"), "bookmark.remove");
}

if (!pinned) {
menu_builder.add_rename (() => {
rename ();
});
menu_builder.add_with_action_name (_("Rename"), "bookmark.rename");
}

if (Uri.parse_scheme (uri) == "trash") {
Expand Down

0 comments on commit 702869f

Please sign in to comment.