mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
implement middle click controller for history navigation buttons
This commit is contained in:
parent
b9b91fb628
commit
2b472eb618
8 changed files with 115 additions and 44 deletions
|
|
@ -6,7 +6,7 @@ mod reload;
|
|||
mod request;
|
||||
mod widget;
|
||||
|
||||
use super::{BrowserAction, ItemAction, Profile, WindowAction};
|
||||
use super::{BrowserAction, ItemAction, Profile, TabAction, WindowAction};
|
||||
use bookmark::Bookmark;
|
||||
use gtk::{prelude::WidgetExt, Box, Button};
|
||||
use history::History;
|
||||
|
|
@ -29,17 +29,17 @@ pub struct Navigation {
|
|||
impl Navigation {
|
||||
pub fn build(
|
||||
profile: &Rc<Profile>,
|
||||
(browser_action, window_action, item_action): (
|
||||
(browser_action, window_action, tab_action, item_action): (
|
||||
&Rc<BrowserAction>,
|
||||
&Rc<WindowAction>,
|
||||
&Rc<TabAction>,
|
||||
&Rc<ItemAction>,
|
||||
),
|
||||
(back_action_name, forward_action_name): (&str, &str),
|
||||
) -> Self {
|
||||
// init children components
|
||||
|
||||
let home = Button::home(window_action);
|
||||
let history = Box::history(back_action_name, forward_action_name);
|
||||
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 bookmark = Button::bookmark(window_action);
|
||||
|
|
|
|||
|
|
@ -4,14 +4,16 @@ pub mod forward;
|
|||
pub use back::Back;
|
||||
pub use forward::Forward;
|
||||
|
||||
use super::{ItemAction, TabAction, WindowAction};
|
||||
use gtk::{prelude::BoxExt, Box, Button, Orientation};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub trait History {
|
||||
fn history(back_action_name: &str, forward_action_name: &str) -> Self;
|
||||
fn history(action: (&Rc<WindowAction>, &Rc<TabAction>, &Rc<ItemAction>)) -> Self;
|
||||
}
|
||||
|
||||
impl History for Box {
|
||||
fn history(back_action_name: &str, forward_action_name: &str) -> Self {
|
||||
fn history(action: (&Rc<WindowAction>, &Rc<TabAction>, &Rc<ItemAction>)) -> Self {
|
||||
let g_box = Box::builder()
|
||||
.orientation(Orientation::Horizontal)
|
||||
.css_classes([
|
||||
|
|
@ -19,8 +21,8 @@ impl History for Box {
|
|||
])
|
||||
.build();
|
||||
|
||||
g_box.append(&Button::back(back_action_name));
|
||||
g_box.append(&Button::forward(forward_action_name));
|
||||
g_box.append(&Button::back(action));
|
||||
g_box.append(&Button::forward(action));
|
||||
g_box
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,55 @@
|
|||
use gtk::Button;
|
||||
use super::{ItemAction, 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 Back {
|
||||
fn back(action_name: &str) -> Self;
|
||||
fn back(action: (&Rc<WindowAction>, &Rc<TabAction>, &Rc<ItemAction>)) -> Self;
|
||||
}
|
||||
|
||||
impl Back for Button {
|
||||
fn back(action_name: &str) -> Self {
|
||||
Button::builder()
|
||||
.action_name(action_name)
|
||||
fn back(
|
||||
(window_action, tab_action, item_action): (
|
||||
&Rc<WindowAction>,
|
||||
&Rc<TabAction>,
|
||||
&Rc<ItemAction>,
|
||||
),
|
||||
) -> Self {
|
||||
// Init main widget
|
||||
let button = Button::builder()
|
||||
.action_name(format!(
|
||||
"{}.{}",
|
||||
tab_action.id,
|
||||
item_action.history.back.name()
|
||||
))
|
||||
.icon_name("go-previous-symbolic")
|
||||
.tooltip_text("Back")
|
||||
.build()
|
||||
.build();
|
||||
|
||||
// Ability to open previous history record in the new tab (without change current page state)
|
||||
let new_tab_controller = GestureClick::builder().button(BUTTON_MIDDLE).build();
|
||||
|
||||
new_tab_controller.connect_pressed({
|
||||
let item_action = item_action.clone();
|
||||
let window_action = window_action.clone();
|
||||
move |_, _, _, _| {
|
||||
if let Some(request) = item_action.history.back(false) {
|
||||
window_action.append.activate_stateful_once(
|
||||
Position::After,
|
||||
Some(request.to_string()),
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
button.add_controller(new_tab_controller);
|
||||
button
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,55 @@
|
|||
use gtk::Button;
|
||||
use super::{ItemAction, 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 Forward {
|
||||
fn forward(action_name: &str) -> Self;
|
||||
fn forward(action: (&Rc<WindowAction>, &Rc<TabAction>, &Rc<ItemAction>)) -> Self;
|
||||
}
|
||||
|
||||
impl Forward for Button {
|
||||
fn forward(action_name: &str) -> Self {
|
||||
Button::builder()
|
||||
.action_name(action_name)
|
||||
fn forward(
|
||||
(window_action, tab_action, item_action): (
|
||||
&Rc<WindowAction>,
|
||||
&Rc<TabAction>,
|
||||
&Rc<ItemAction>,
|
||||
),
|
||||
) -> Self {
|
||||
// Init main widget
|
||||
let button = Button::builder()
|
||||
.action_name(format!(
|
||||
"{}.{}",
|
||||
tab_action.id,
|
||||
item_action.history.forward.name()
|
||||
))
|
||||
.icon_name("go-next-symbolic")
|
||||
.tooltip_text("Forward")
|
||||
.build()
|
||||
.build();
|
||||
|
||||
// Ability to open next history record in the new tab (without change current page state)
|
||||
let new_tab_controller = GestureClick::builder().button(BUTTON_MIDDLE).build();
|
||||
|
||||
new_tab_controller.connect_pressed({
|
||||
let item_action = item_action.clone();
|
||||
let window_action = window_action.clone();
|
||||
move |_, _, _, _| {
|
||||
if let Some(request) = item_action.history.forward(false) {
|
||||
window_action.append.activate_stateful_once(
|
||||
Position::After,
|
||||
Some(request.to_string()),
|
||||
false,
|
||||
true,
|
||||
false,
|
||||
true,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
button.add_controller(new_tab_controller);
|
||||
button
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue