Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add shortcuts for forwards/backwards #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ public class Docs : Gtk.Application {
set_accels_for_action ("app.find", {"<Control>F"});

search_action.activate.connect (window.toggle_search);

var forwards_action = new SimpleAction ("forwards", null);
add_action (forwards_action);
set_accels_for_action ("app.forwards", {"<Control>D"});
forwards_action.activate.connect (window.forwards);

var backwards_action = new SimpleAction ("backwards", null);
add_action (backwards_action);
set_accels_for_action ("app.backwards", {"<Control>A"});
backwards_action.activate.connect (window.backwards);
Comment on lines +58 to +66
Copy link

@chances chances Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Browsers commonly use Alt+Left and Alt+Right for backward/forward navigation.

Consider changing this to match.

}

public static int main (string[] args) {
Expand Down
34 changes: 22 additions & 12 deletions src/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
public class MainWindow : Gtk.Window {
Gtk.Stack stack;
Gtk.SearchBar search_bar;
View vala;
View dev;
public MainWindow (Gtk.Application application) {
Object (application: application,
icon_name: "com.github.mdh34.quickdocs",
Expand Down Expand Up @@ -60,7 +62,7 @@ public class MainWindow : Gtk.Window {
stack_switcher.set_stack (stack);
header.set_custom_title (stack_switcher);

var vala = new View ();
vala = new View ();

var online = check_online ();
if (online) {
Expand All @@ -83,7 +85,7 @@ public class MainWindow : Gtk.Window {
stack.add_titled (pane, "vala", "Valadoc");
}

var dev = new View ();
dev = new View ();
dev.set_cookies ();
dev.appcache_init (online);
dev.load_uri (Docs.settings.get_string ("last-dev"));
Expand All @@ -92,20 +94,12 @@ public class MainWindow : Gtk.Window {

var back = new Gtk.Button.from_icon_name ("go-previous-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
back.clicked.connect (() => {
if (stack.get_visible_child_name () == "vala") {
vala.go_back ();
} else if (stack.get_visible_child_name () == "dev") {
dev.go_back ();
}
backwards();
});

var forward = new Gtk.Button.from_icon_name ("go-next-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
forward.clicked.connect (() => {
if (stack.get_visible_child_name () == "vala") {
vala.go_forward ();
} else if (stack.get_visible_child_name () == "dev") {
dev.go_forward ();
}
forwards();
});

var current_icons = Gtk.IconTheme.get_default ();
Expand Down Expand Up @@ -203,6 +197,22 @@ public class MainWindow : Gtk.Window {
}
}

public void forwards () {
if (stack.get_visible_child_name () == "vala") {
vala.go_forward ();
} else if (stack.get_visible_child_name () == "dev") {
dev.go_forward ();
}
}

public void backwards () {
if (stack.get_visible_child_name () == "vala") {
vala.go_back ();
} else if (stack.get_visible_child_name () == "dev") {
dev.go_back ();
}
}

private View? get_current_view () {
var v = stack.get_visible_child ();
return (v is View)
Expand Down