mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
reorganize home action, add middle click handler
This commit is contained in:
parent
418b04c86c
commit
3ee6a03c30
5 changed files with 93 additions and 30 deletions
|
|
@ -1,8 +1,11 @@
|
|||
mod history;
|
||||
mod home;
|
||||
mod ident;
|
||||
mod load;
|
||||
|
||||
use gtk::gio::SimpleAction;
|
||||
use history::History;
|
||||
use home::Home;
|
||||
use ident::Ident;
|
||||
use load::Load;
|
||||
|
||||
|
|
@ -11,6 +14,7 @@ use std::rc::Rc;
|
|||
/// [SimpleActionGroup](https://docs.gtk.org/gio/class.SimpleActionGroup.html) wrapper for `Browser` actions
|
||||
pub struct Action {
|
||||
pub history: Rc<History>,
|
||||
pub home: SimpleAction,
|
||||
pub ident: Rc<Ident>,
|
||||
pub load: Rc<Load>,
|
||||
}
|
||||
|
|
@ -28,6 +32,7 @@ impl Action {
|
|||
pub fn new() -> Self {
|
||||
let ident = Rc::new(Ident::new());
|
||||
let load = Rc::new(Load::new());
|
||||
let home = SimpleAction::home();
|
||||
|
||||
let history = Rc::new(History::build({
|
||||
let load = load.clone();
|
||||
|
|
@ -36,6 +41,7 @@ impl Action {
|
|||
|
||||
Self {
|
||||
history,
|
||||
home,
|
||||
ident,
|
||||
load,
|
||||
}
|
||||
|
|
|
|||
13
src/app/browser/window/tab/item/action/home.rs
Normal file
13
src/app/browser/window/tab/item/action/home.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
use gtk::{gio::SimpleAction, glib::uuid_string_random};
|
||||
|
||||
pub trait Home {
|
||||
fn home() -> Self;
|
||||
}
|
||||
|
||||
impl Home for SimpleAction {
|
||||
fn home() -> Self {
|
||||
let home = SimpleAction::new(&uuid_string_random(), None);
|
||||
home.set_enabled(false);
|
||||
home
|
||||
}
|
||||
}
|
||||
|
|
@ -38,10 +38,10 @@ impl Navigation {
|
|||
) -> Self {
|
||||
// init children components
|
||||
|
||||
let home = Button::home(window_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 home = Button::home((window_action, tab_action, item_action), &request);
|
||||
let bookmark = Button::bookmark(window_action);
|
||||
|
||||
// init main widget
|
||||
|
|
@ -80,11 +80,6 @@ impl Navigation {
|
|||
.get(&self.request.strip_prefix())
|
||||
.is_some(),
|
||||
);
|
||||
self.home.set_sensitive(
|
||||
self.request
|
||||
.home()
|
||||
.is_some_and(|home| home.to_string() != request),
|
||||
);
|
||||
}
|
||||
|
||||
pub fn clean(
|
||||
|
|
|
|||
|
|
@ -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 Home {
|
||||
fn home(action: &Rc<WindowAction>) -> Self;
|
||||
fn home(
|
||||
action: (&Rc<WindowAction>, &Rc<TabAction>, &Rc<ItemAction>),
|
||||
request: &Rc<Request>,
|
||||
) -> Self;
|
||||
}
|
||||
|
||||
impl Home for Button {
|
||||
fn home(action: &Rc<WindowAction>) -> Self {
|
||||
Button::builder()
|
||||
.action_name(format!(
|
||||
"{}.{}",
|
||||
action.id,
|
||||
action.home.simple_action.name()
|
||||
)) // @TODO
|
||||
fn home(
|
||||
(window_action, tab_action, item_action): (
|
||||
&Rc<WindowAction>,
|
||||
&Rc<TabAction>,
|
||||
&Rc<ItemAction>,
|
||||
),
|
||||
request: &Rc<Request>,
|
||||
) -> Self {
|
||||
let button = Button::builder()
|
||||
.action_name(format!("{}.{}", tab_action.id, item_action.home.name()))
|
||||
.icon_name("go-home-symbolic")
|
||||
.tooltip_text("Home")
|
||||
.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…
Add table
Add a link
Reference in a new issue