Skip to content

Commit

Permalink
Add focus sidebar action to window (#2353)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremypw authored Oct 8, 2024
1 parent 37ead8a commit 2f0273b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions libcore/Interfaces/SidebarInterface.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,5 @@ public interface Files.SidebarInterface : Gtk.Widget {
public abstract void sync_uri (string uri);
public abstract void reload ();
public abstract void on_free_space_change ();
public abstract void focus ();
}
9 changes: 9 additions & 0 deletions libcore/Interfaces/SidebarListInterface.vala
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,13 @@ public interface Sidebar.SidebarListInterface : Object {
public virtual bool is_drop_target () {
return false;
}

public void focus () {
var focus_row = list_box.get_selected_row ();
if (focus_row == null) {
focus_row = list_box.get_row_at_index (0);
}

focus_row.grab_focus ();
}
}
4 changes: 4 additions & 0 deletions src/View/Sidebar/SidebarWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ public class Sidebar.SidebarWindow : Gtk.Box, Files.SidebarInterface {
device_listbox.refresh_info ();
}

public void focus () {
bookmark_listbox.focus ();
}

private class SidebarExpander : Gtk.ToggleButton {
public string expander_label { get; construct; }
private static Gtk.CssProvider expander_provider;
Expand Down
8 changes: 7 additions & 1 deletion src/View/Window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public class Files.View.Window : Hdy.ApplicationWindow {
{"folders-before-files", null, null, "true", change_state_folders_before_files},
{"restore-tabs-on-startup", null, null, "true", change_state_restore_tabs_on_startup},
{"forward", action_forward, "i"},
{"back", action_back, "i"}
{"back", action_back, "i"},
{"focus-sidebar", action_focus_sidebar}
};

public uint window_number { get; construct; }
Expand Down Expand Up @@ -165,6 +166,7 @@ public class Files.View.Window : Hdy.ApplicationWindow {
marlin_app.set_accels_for_action ("win.info::HELP", {"F1"});
marlin_app.set_accels_for_action ("win.tab::TAB", {"<Shift><Ctrl>K"});
marlin_app.set_accels_for_action ("win.tab::WINDOW", {"<Ctrl><Alt>N"});
marlin_app.set_accels_for_action ("win.focus-sidebar", {"<Ctrl>Left"});
}

build_window ();
Expand Down Expand Up @@ -1049,6 +1051,10 @@ public class Files.View.Window : Hdy.ApplicationWindow {
});
}

private void action_focus_sidebar () {
sidebar.focus ();
}

private void before_undo_redo () {
doing_undo_redo = true;
update_undo_actions ();
Expand Down

0 comments on commit 2f0273b

Please sign in to comment.