Skip to content

Commit

Permalink
FilePane: use GLib.Menu (#86)
Browse files Browse the repository at this point in the history
  • Loading branch information
danirabbit authored Sep 23, 2024
1 parent e1af3ca commit 47f0a5b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 27 deletions.
50 changes: 41 additions & 9 deletions src/Frontend/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ class Taxi.MainWindow : Hdy.ApplicationWindow {
}

construct {
var navigate_action = new SimpleAction ("navigate", VariantType.STRING);
navigate_action.activate.connect (action_navigate);

var open_action = new SimpleAction ("open", VariantType.STRING);
open_action.activate.connect (action_open);

var delete_action = new SimpleAction ("delete", VariantType.STRING);
delete_action.activate.connect (action_delete);

add_action (navigate_action);
add_action (open_action);
add_action (delete_action);

connect_box = new ConnectBox ();
connect_box.valign = Gtk.Align.CENTER;

Expand Down Expand Up @@ -108,15 +121,13 @@ class Taxi.MainWindow : Hdy.ApplicationWindow {
local_pane.navigate.connect (on_local_navigate);
local_pane.file_dragged.connect (on_local_file_dragged);
local_pane.transfer.connect (on_remote_file_dragged);
local_pane.@delete.connect (on_local_file_delete);
local_access.directory_changed.connect (() => update_pane (Location.LOCAL));

remote_pane = new FilePane ();
remote_pane.open.connect (on_remote_open);
remote_pane.navigate.connect (on_remote_navigate);
remote_pane.file_dragged.connect (on_remote_file_dragged);
remote_pane.transfer.connect (on_local_file_dragged);
remote_pane.@delete.connect (on_remote_file_delete);

outer_box = new Gtk.Grid ();
outer_box.add (local_pane);
Expand Down Expand Up @@ -257,17 +268,38 @@ class Taxi.MainWindow : Hdy.ApplicationWindow {
file_dragged (uri, Location.LOCAL, local_access);
}

private void on_local_file_delete (GLib.Uri uri) {
file_delete (uri, Location.LOCAL);
private void navigate (GLib.Uri uri, IFileAccess file_access, Location pane) {
file_access.goto_dir (uri);
update_pane (pane);
}

private void action_navigate (GLib.SimpleAction action, GLib.Variant? variant) {
var uri = GLib.Uri.parse (variant.get_string (), PARSE_RELAXED);
if (uri.get_scheme () == "file") {
local_access.goto_dir (uri);
update_pane (LOCAL);
} else {
remote_access.goto_dir (uri);
update_pane (REMOTE);
}
}

private void on_remote_file_delete (GLib.Uri uri) {
file_delete (uri, Location.REMOTE);
private void action_open (GLib.SimpleAction action, GLib.Variant? variant) {
var uri = GLib.Uri.parse (variant.get_string (), PARSE_RELAXED);
if (uri.get_scheme () == "file") {
local_access.open_file (uri);
} else {
remote_access.open_file (uri);
}
}

private void navigate (GLib.Uri uri, IFileAccess file_access, Location pane) {
file_access.goto_dir (uri);
update_pane (pane);
private void action_delete (GLib.SimpleAction action, GLib.Variant? variant) {
var uri = GLib.Uri.parse (variant.get_string (), PARSE_RELAXED);
if (uri.get_scheme () == "file") {
file_delete (uri, Location.LOCAL);
} else {
file_delete (uri, Location.REMOTE);
}
}

private void file_dragged (
Expand Down
52 changes: 34 additions & 18 deletions src/Frontend/Widgets/FilePane.vala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ namespace Taxi {
public signal void file_dragged (string uri);
public signal void transfer (string uri);
public signal void navigate (GLib.Uri uri);
public signal void @delete (GLib.Uri uri);
public signal void rename (GLib.Uri uri);
public signal void open (GLib.Uri uri);
public signal void edit (GLib.Uri uri);
Expand Down Expand Up @@ -247,32 +246,49 @@ namespace Taxi {
PARSE_RELAXED
);

var menu_model = new GLib.Menu ();

var type = event_box.get_data<FileType> ("type");
var menu = new Gtk.Menu ();
if (type == FileType.DIRECTORY) {
menu.add (new_menu_item (_("Open"), u => navigate (u), uri));
menu_model.append (
_("Open"),
Action.print_detailed_name (
"win.navigate",
new Variant.string (uri.to_string ())
)
);
} else {
menu.add (new_menu_item (_("Open"), u => open (u), uri));
menu_model.append (
_("Open"),
Action.print_detailed_name (
"win.open",
new Variant.string (uri.to_string ())
)
);

//menu.add (new_menu_item ("Edit", u => edit (u), uri));
}
menu.add (new Gtk.SeparatorMenuItem ());
menu.add (new_menu_item (_("Delete"), u => @delete (u), uri));

var delete_section = new GLib.Menu ();
delete_section.append (
_("Delete"),
Action.print_detailed_name (
"win.delete",
new Variant.string (uri.to_string ())
)
);

menu_model.append_section (null, delete_section);

//add_menu_item ("Rename", menu, u => rename (u), uri);
menu.show_all ();
menu.attach_to_widget (event_box, null);

var menu = new Gtk.Menu.from_model (menu_model) {
attach_widget = event_box
};
menu.popup_at_pointer (null);
menu.deactivate.connect (() => list_box.select_row (null));
return true;
}

private Gtk.MenuItem new_menu_item (
string label,
ActivateFunc activate_fn,
GLib.Uri uri
) {
var menu_item = new Gtk.MenuItem.with_label (label);
menu_item.activate.connect (() => activate_fn (uri));
return menu_item;
return true;
}

public void update_pathbar (GLib.Uri uri) {
Expand Down

0 comments on commit 47f0a5b

Please sign in to comment.