From 67bcf90390e3c5c76586cb31e5fd624ee27b595b Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 4 Mar 2025 08:15:33 +0200 Subject: [PATCH] connect back/forward navigation buttons --- src/app/browser.rs | 2 +- src/app/browser/widget.rs | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/app/browser.rs b/src/app/browser.rs index 843d51df..84c0468c 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -36,7 +36,7 @@ impl Browser { // Init widget let widget = Rc::new(Widget::new( - &window.g_box, + &window, &[ // action groups ( diff --git a/src/app/browser/widget.rs b/src/app/browser/widget.rs index ca137905..9c77a4d9 100644 --- a/src/app/browser/widget.rs +++ b/src/app/browser/widget.rs @@ -1,12 +1,14 @@ mod database; +use super::Window; use adw::ApplicationWindow; use gtk::{ gio::SimpleActionGroup, glib::GString, - prelude::{GtkWindowExt, IsA, WidgetExt}, + prelude::{GtkWindowExt, WidgetExt}, }; use sqlite::Transaction; +use std::rc::Rc; // Default options const DEFAULT_HEIGHT: i32 = 480; @@ -19,13 +21,10 @@ pub struct Widget { impl Widget { // Construct - pub fn new( - content: &impl IsA, - action_groups: &[(&GString, SimpleActionGroup)], - ) -> Self { + pub fn new(window: &Rc, action_groups: &[(&GString, SimpleActionGroup)]) -> Self { // Init GTK let application_window = ApplicationWindow::builder() - .content(content) + .content(&window.g_box) .default_height(DEFAULT_HEIGHT) .default_width(DEFAULT_WIDTH) .maximized(MAXIMIZED) @@ -36,6 +35,21 @@ impl Widget { application_window.insert_action_group(name, Some(group)); } + // Connect back/forward navigation buttons @TODO use constant + application_window.add_controller({ + use gtk::prelude::GestureSingleExt; + let button_controller = gtk::GestureClick::builder().button(0).build(); + button_controller.connect_pressed({ + let window = window.clone(); + move |this, _, _, _| match this.current_button() { + 8 => window.tab.history_back(None), + 9 => window.tab.history_forward(None), + _ => {} + } + }); + button_controller + }); + // Return new struct Self { application_window } }