Skip to content

Commit

Permalink
feat: improve keyboard navigation further (#303)
Browse files Browse the repository at this point in the history
* feat(composer): close on ctrl+q or w

* feat(app): close on ctrl+w

* feat(app): alias ctrl+N to new post

* feat(app): alt+home to go back to home

* feat(app): page up/down for pagination
  • Loading branch information
GeopJr committed Jun 11, 2023
1 parent 0aff7c7 commit 2c87384
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/Application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ namespace Tuba {
{ "back", back_activated },
{ "refresh", refresh_activated },
{ "search", search_activated },
{ "quit", quit_activated }
{ "quit", quit_activated },
{ "back-home", back_home_activated },
{ "scroll-page-down", scroll_view_page_down },
{ "scroll-page-up", scroll_view_page_up }
};

construct {
Expand All @@ -64,11 +67,15 @@ namespace Tuba {
}

public string[] ACCEL_ABOUT = {"F1"};
public string[] ACCEL_NEW_POST = {"<Ctrl>T"};
public string[] ACCEL_NEW_POST = {"<Ctrl>T", "<Ctrl>N"};
public string[] ACCEL_BACK = {"<Alt>BackSpace", "<Alt>Left", "Escape", "<Alt>KP_Left", "Pointer_DfltBtnPrev"};
public string[] ACCEL_REFRESH = {"<Ctrl>R", "F5"};
public string[] ACCEL_SEARCH = {"<Ctrl>F"};
public string[] ACCEL_QUIT = {"<Ctrl>Q"};
public string[] ACCEL_CLOSE = {"<Ctrl>W"};
public string[] ACCEL_BACK_HOME = {"<Alt>Home"};
public string[] ACCEL_SCROLL_PAGE_DOWN = {"Page_Down"};
public string[] ACCEL_SCROLL_PAGE_UP = {"Page_Up"};

public static int main (string[] args) {
try {
Expand Down Expand Up @@ -145,6 +152,10 @@ namespace Tuba {
set_accels_for_action ("app.refresh", ACCEL_REFRESH);
set_accels_for_action ("app.search", ACCEL_SEARCH);
set_accels_for_action ("app.quit", ACCEL_QUIT);
set_accels_for_action ("window.close", ACCEL_CLOSE);
set_accels_for_action ("app.back-home", ACCEL_BACK_HOME);
set_accels_for_action ("app.scroll-page-down", ACCEL_SCROLL_PAGE_DOWN);
set_accels_for_action ("app.scroll-page-up", ACCEL_SCROLL_PAGE_UP);
add_action_entries (app_entries, this);
}

Expand Down Expand Up @@ -226,6 +237,18 @@ namespace Tuba {
refresh ();
}

void back_home_activated () {
main_window.go_back_to_start ();
}

void scroll_view_page_down () {
main_window.scroll_view_page ();
}

void scroll_view_page_up () {
main_window.scroll_view_page (true);
}

string troubleshooting = "os: %s %s\nprefix: %s\nflatpak: %s\nversion: %s (%s)\ngtk: %u.%u.%u (%d.%d.%d)\nlibadwaita: %u.%u.%u (%d.%d.%d)\nlibsoup: %u.%u.%u (%d.%d.%d)%s".printf(
GLib.Environment.get_os_info ("NAME"), GLib.Environment.get_os_info ("VERSION"),
Build.PREFIX,
Expand Down
2 changes: 2 additions & 0 deletions src/Dialogs/Composer/Dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public class Tuba.Dialogs.Compose : Adw.Window {

this.insert_action_group ("composer", action_group);
add_binding_action (Gdk.Key.Escape, 0, "composer.exit", null);
add_binding_action (Gdk.Key.W, Gdk.ModifierType.CONTROL_MASK, "composer.exit", null);
add_binding_action (Gdk.Key.Q, Gdk.ModifierType.CONTROL_MASK, "composer.exit", null);

transient_for = app.main_window;
title_switcher.stack = stack;
Expand Down
7 changes: 7 additions & 0 deletions src/Dialogs/MainWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,13 @@ public class Tuba.Dialogs.MainWindow: Adw.ApplicationWindow, Saveable {
}
}

public void scroll_view_page (bool up = false) {
var c_view = leaflet.visible_child as Views.Base;
if (c_view != null) {
c_view.scroll_page (up);
}
}

// public override bool delete_event (Gdk.EventAny event) {
// window = null;
// return app.on_window_closed ();
Expand Down
4 changes: 4 additions & 0 deletions src/Views/Base.vala
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ public class Tuba.Views.Base : Box {
scrolled.scroll_child (Gtk.ScrollType.START, false);
}

public virtual void scroll_page (bool up = false) {
scrolled.scroll_child (up ? Gtk.ScrollType.PAGE_BACKWARD : Gtk.ScrollType.PAGE_FORWARD, false);
}

public override void dispose () {
actions.dispose ();
base.dispose ();
Expand Down
6 changes: 6 additions & 0 deletions src/Views/TabbedBase.vala
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ public class Tuba.Views.TabbedBase : Views.Base {
// }
}

public override void scroll_page (bool up = false) {
var c_scrolled = stack.visible_child as Views.Base;
if (c_scrolled != null)
c_scrolled.scroll_page (up);
}

void on_view_switched () {
var view = stack.visible_child as Views.Base;
if (view.view.has_css_class("no-transition")) {
Expand Down

0 comments on commit 2c87384

Please sign in to comment.