diff --git a/src/app/browser/window/tab/item.rs b/src/app/browser/window/tab/item.rs index 5189cf13..a834fac6 100644 --- a/src/app/browser/window/tab/item.rs +++ b/src/app/browser/window/tab/item.rs @@ -59,6 +59,7 @@ impl Item { let action = Rc::new(Action::new()); tab_action.simple_action_group.add_action(&action.home); + tab_action.simple_action_group.add_action(&action.reload); tab_action .simple_action_group @@ -133,6 +134,14 @@ impl Item { } }); + action.reload.connect_activate({ + let page = page.clone(); + let client = client.clone(); + move |_, _| { + client.handle(&page.navigation.request.widget.entry.text(), false); + } + }); + // Handle immediately on request if let Some(text) = request { page.navigation.request.widget.entry.set_text(text); @@ -159,6 +168,10 @@ impl Item { home.to_string() != self.page.navigation.request.widget.entry.text() })); + self.action + .reload + .set_enabled(!self.page.navigation.request.widget.entry.text().is_empty()); + // Update child components self.page.update(); } diff --git a/src/app/browser/window/tab/item/action.rs b/src/app/browser/window/tab/item/action.rs index 2e604f50..70f1f34c 100644 --- a/src/app/browser/window/tab/item/action.rs +++ b/src/app/browser/window/tab/item/action.rs @@ -2,12 +2,14 @@ mod history; mod home; mod ident; mod load; +mod reload; use gtk::gio::SimpleAction; use history::History; use home::Home; use ident::Ident; use load::Load; +use reload::Reload; use std::rc::Rc; @@ -17,6 +19,7 @@ pub struct Action { pub home: SimpleAction, pub ident: Rc, pub load: Rc, + pub reload: SimpleAction, } impl Default for Action { @@ -33,6 +36,7 @@ impl Action { let ident = Rc::new(Ident::new()); let load = Rc::new(Load::new()); let home = SimpleAction::home(); + let reload = SimpleAction::reload(); let history = Rc::new(History::build({ let load = load.clone(); @@ -41,6 +45,7 @@ impl Action { Self { history, + reload, home, ident, load, diff --git a/src/app/browser/window/tab/item/action/reload.rs b/src/app/browser/window/tab/item/action/reload.rs new file mode 100644 index 00000000..85491bbf --- /dev/null +++ b/src/app/browser/window/tab/item/action/reload.rs @@ -0,0 +1,13 @@ +use gtk::{gio::SimpleAction, glib::uuid_string_random}; + +pub trait Reload { + fn reload() -> Self; +} + +impl Reload for SimpleAction { + fn reload() -> Self { + let reload = SimpleAction::new(&uuid_string_random(), None); + reload.set_enabled(false); + reload + } +} diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index b461c9df..f1e7da80 100644 --- a/src/app/browser/window/tab/item/page/navigation.rs +++ b/src/app/browser/window/tab/item/page/navigation.rs @@ -8,7 +8,7 @@ mod widget; use super::{BrowserAction, ItemAction, Profile, TabAction, WindowAction}; use bookmark::Bookmark; -use gtk::{prelude::WidgetExt, Box, Button}; +use gtk::{Box, Button}; use history::History; use home::Home; use reload::Reload; @@ -39,8 +39,8 @@ impl Navigation { // init children components let history = Box::history((window_action, tab_action, item_action)); - let reload = Button::reload(window_action); let request = Rc::new(Request::build((browser_action, item_action))); + let reload = Button::reload((window_action, tab_action, item_action), &request); let home = Button::home((window_action, tab_action, item_action), &request); let bookmark = Button::bookmark(window_action); @@ -73,13 +73,8 @@ impl Navigation { // update children components self.bookmark .update(self.profile.bookmark.get(&request).is_ok()); - self.reload.set_sensitive(!request.is_empty()); - self.request.update( - self.profile - .identity - .get(&self.request.strip_prefix()) - .is_some(), - ); + self.request + .update(self.profile.identity.get(&request).is_some()); } pub fn clean( diff --git a/src/app/browser/window/tab/item/page/navigation/reload.rs b/src/app/browser/window/tab/item/page/navigation/reload.rs index 10e32401..83e7ee32 100644 --- a/src/app/browser/window/tab/item/page/navigation/reload.rs +++ b/src/app/browser/window/tab/item/page/navigation/reload.rs @@ -1,21 +1,55 @@ -use super::WindowAction; -use gtk::{prelude::ActionExt, Button}; +use super::{ItemAction, Request, TabAction, WindowAction}; +use crate::app::browser::window::action::Position; +use gtk::{ + gdk::BUTTON_MIDDLE, + prelude::{ActionExt, WidgetExt}, + Button, GestureClick, +}; use std::rc::Rc; pub trait Reload { - fn reload(action: &Rc) -> Self; + fn reload( + action: (&Rc, &Rc, &Rc), + request: &Rc, + ) -> Self; } impl Reload for Button { - fn reload(action: &Rc) -> Self { - Button::builder() - .action_name(format!( - "{}.{}", - action.id, - action.reload.simple_action.name() - )) // @TODO + fn reload( + (window_action, tab_action, item_action): ( + &Rc, + &Rc, + &Rc, + ), + request: &Rc, + ) -> Self { + let button = Button::builder() + .action_name(format!("{}.{}", tab_action.id, item_action.reload.name())) .icon_name("view-refresh-symbolic") .tooltip_text("Reload") - .build() + .build(); + + // Navigate home in the new tab (feature) + let button_middle_controller = GestureClick::builder().button(BUTTON_MIDDLE).build(); + + button_middle_controller.connect_pressed({ + let request = request.clone(); + let window_action = window_action.clone(); + move |_, _, _, _| { + if let Some(uri) = request.home() { + window_action.append.activate_stateful_once( + Position::After, + Some(uri.to_string()), + false, + true, + false, + true, + ); + } + } + }); + + button.add_controller(button_middle_controller); + button } }