mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-09-11 14:32:00 +00:00
reorganize reload action, add middle click handler
This commit is contained in:
parent
3ee6a03c30
commit
8b4d184ad7
@ -59,6 +59,7 @@ impl Item {
|
|||||||
let action = Rc::new(Action::new());
|
let action = Rc::new(Action::new());
|
||||||
|
|
||||||
tab_action.simple_action_group.add_action(&action.home);
|
tab_action.simple_action_group.add_action(&action.home);
|
||||||
|
tab_action.simple_action_group.add_action(&action.reload);
|
||||||
|
|
||||||
tab_action
|
tab_action
|
||||||
.simple_action_group
|
.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
|
// Handle immediately on request
|
||||||
if let Some(text) = request {
|
if let Some(text) = request {
|
||||||
page.navigation.request.widget.entry.set_text(text);
|
page.navigation.request.widget.entry.set_text(text);
|
||||||
@ -159,6 +168,10 @@ impl Item {
|
|||||||
home.to_string() != self.page.navigation.request.widget.entry.text()
|
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
|
// Update child components
|
||||||
self.page.update();
|
self.page.update();
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,14 @@ mod history;
|
|||||||
mod home;
|
mod home;
|
||||||
mod ident;
|
mod ident;
|
||||||
mod load;
|
mod load;
|
||||||
|
mod reload;
|
||||||
|
|
||||||
use gtk::gio::SimpleAction;
|
use gtk::gio::SimpleAction;
|
||||||
use history::History;
|
use history::History;
|
||||||
use home::Home;
|
use home::Home;
|
||||||
use ident::Ident;
|
use ident::Ident;
|
||||||
use load::Load;
|
use load::Load;
|
||||||
|
use reload::Reload;
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
@ -17,6 +19,7 @@ pub struct Action {
|
|||||||
pub home: SimpleAction,
|
pub home: SimpleAction,
|
||||||
pub ident: Rc<Ident>,
|
pub ident: Rc<Ident>,
|
||||||
pub load: Rc<Load>,
|
pub load: Rc<Load>,
|
||||||
|
pub reload: SimpleAction,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Action {
|
impl Default for Action {
|
||||||
@ -33,6 +36,7 @@ impl Action {
|
|||||||
let ident = Rc::new(Ident::new());
|
let ident = Rc::new(Ident::new());
|
||||||
let load = Rc::new(Load::new());
|
let load = Rc::new(Load::new());
|
||||||
let home = SimpleAction::home();
|
let home = SimpleAction::home();
|
||||||
|
let reload = SimpleAction::reload();
|
||||||
|
|
||||||
let history = Rc::new(History::build({
|
let history = Rc::new(History::build({
|
||||||
let load = load.clone();
|
let load = load.clone();
|
||||||
@ -41,6 +45,7 @@ impl Action {
|
|||||||
|
|
||||||
Self {
|
Self {
|
||||||
history,
|
history,
|
||||||
|
reload,
|
||||||
home,
|
home,
|
||||||
ident,
|
ident,
|
||||||
load,
|
load,
|
||||||
|
13
src/app/browser/window/tab/item/action/reload.rs
Normal file
13
src/app/browser/window/tab/item/action/reload.rs
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
@ -8,7 +8,7 @@ mod widget;
|
|||||||
|
|
||||||
use super::{BrowserAction, ItemAction, Profile, TabAction, WindowAction};
|
use super::{BrowserAction, ItemAction, Profile, TabAction, WindowAction};
|
||||||
use bookmark::Bookmark;
|
use bookmark::Bookmark;
|
||||||
use gtk::{prelude::WidgetExt, Box, Button};
|
use gtk::{Box, Button};
|
||||||
use history::History;
|
use history::History;
|
||||||
use home::Home;
|
use home::Home;
|
||||||
use reload::Reload;
|
use reload::Reload;
|
||||||
@ -39,8 +39,8 @@ impl Navigation {
|
|||||||
// init children components
|
// init children components
|
||||||
|
|
||||||
let history = Box::history((window_action, tab_action, item_action));
|
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 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 home = Button::home((window_action, tab_action, item_action), &request);
|
||||||
let bookmark = Button::bookmark(window_action);
|
let bookmark = Button::bookmark(window_action);
|
||||||
|
|
||||||
@ -73,13 +73,8 @@ impl Navigation {
|
|||||||
// update children components
|
// update children components
|
||||||
self.bookmark
|
self.bookmark
|
||||||
.update(self.profile.bookmark.get(&request).is_ok());
|
.update(self.profile.bookmark.get(&request).is_ok());
|
||||||
self.reload.set_sensitive(!request.is_empty());
|
self.request
|
||||||
self.request.update(
|
.update(self.profile.identity.get(&request).is_some());
|
||||||
self.profile
|
|
||||||
.identity
|
|
||||||
.get(&self.request.strip_prefix())
|
|
||||||
.is_some(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clean(
|
pub fn clean(
|
||||||
|
@ -1,21 +1,55 @@
|
|||||||
use super::WindowAction;
|
use super::{ItemAction, Request, TabAction, WindowAction};
|
||||||
use gtk::{prelude::ActionExt, Button};
|
use crate::app::browser::window::action::Position;
|
||||||
|
use gtk::{
|
||||||
|
gdk::BUTTON_MIDDLE,
|
||||||
|
prelude::{ActionExt, WidgetExt},
|
||||||
|
Button, GestureClick,
|
||||||
|
};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
pub trait Reload {
|
pub trait Reload {
|
||||||
fn reload(action: &Rc<WindowAction>) -> Self;
|
fn reload(
|
||||||
|
action: (&Rc<WindowAction>, &Rc<TabAction>, &Rc<ItemAction>),
|
||||||
|
request: &Rc<Request>,
|
||||||
|
) -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Reload for Button {
|
impl Reload for Button {
|
||||||
fn reload(action: &Rc<WindowAction>) -> Self {
|
fn reload(
|
||||||
Button::builder()
|
(window_action, tab_action, item_action): (
|
||||||
.action_name(format!(
|
&Rc<WindowAction>,
|
||||||
"{}.{}",
|
&Rc<TabAction>,
|
||||||
action.id,
|
&Rc<ItemAction>,
|
||||||
action.reload.simple_action.name()
|
),
|
||||||
)) // @TODO
|
request: &Rc<Request>,
|
||||||
|
) -> Self {
|
||||||
|
let button = Button::builder()
|
||||||
|
.action_name(format!("{}.{}", tab_action.id, item_action.reload.name()))
|
||||||
.icon_name("view-refresh-symbolic")
|
.icon_name("view-refresh-symbolic")
|
||||||
.tooltip_text("Reload")
|
.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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user