mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45: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
|
|
@ -11,10 +11,7 @@ pub use item::Item;
|
|||
use menu::Menu;
|
||||
use widget::Widget;
|
||||
|
||||
use crate::app::browser::{
|
||||
window::action::{Action as WindowAction, Position},
|
||||
Action as BrowserAction,
|
||||
};
|
||||
use super::{Action as WindowAction, BrowserAction, Position};
|
||||
use crate::Profile;
|
||||
use gtk::{
|
||||
glib::{DateTime, GString, Propagation},
|
||||
|
|
|
|||
|
|
@ -5,17 +5,14 @@ mod identity;
|
|||
pub mod page;
|
||||
mod widget;
|
||||
|
||||
use crate::app::browser::{
|
||||
window::action::{Action as WindowAction, Position},
|
||||
Action as BrowserAction,
|
||||
};
|
||||
use super::{Action as TabAction, BrowserAction, Position, WindowAction};
|
||||
use crate::Profile;
|
||||
use action::Action;
|
||||
use adw::TabView;
|
||||
use client::Client;
|
||||
use gtk::{
|
||||
glib::{uuid_string_random, GString},
|
||||
prelude::{ActionExt, ActionMapExt, Cast, EditableExt},
|
||||
prelude::{ActionMapExt, Cast, EditableExt},
|
||||
};
|
||||
use page::Page;
|
||||
use sqlite::Transaction;
|
||||
|
|
@ -44,7 +41,7 @@ impl Item {
|
|||
(browser_action, window_action, tab_action): (
|
||||
&Rc<BrowserAction>,
|
||||
&Rc<WindowAction>,
|
||||
&Rc<super::Action>,
|
||||
&Rc<TabAction>,
|
||||
),
|
||||
(position, request, is_pinned, is_selected, is_attention, is_load): (
|
||||
Position,
|
||||
|
|
@ -73,11 +70,7 @@ impl Item {
|
|||
let page = Rc::new(Page::build(
|
||||
&id,
|
||||
profile,
|
||||
(browser_action, window_action, &action),
|
||||
(
|
||||
&format!("{}.{}", &tab_action.id, action.history.back.name()),
|
||||
&format!("{}.{}", &tab_action.id, action.history.forward.name()),
|
||||
),
|
||||
(browser_action, window_action, tab_action, &action),
|
||||
));
|
||||
|
||||
let widget = Rc::new(Widget::build(
|
||||
|
|
|
|||
|
|
@ -69,11 +69,11 @@ impl History {
|
|||
self.forward.set_enabled(self.forward(false).is_some());
|
||||
}
|
||||
|
||||
pub fn back(&self, follow_to_index: bool) -> Option<GString> {
|
||||
self.memory.back(follow_to_index)
|
||||
pub fn back(&self, is_follow_to_index: bool) -> Option<GString> {
|
||||
self.memory.back(is_follow_to_index)
|
||||
}
|
||||
|
||||
pub fn forward(&self, follow_to_index: bool) -> Option<GString> {
|
||||
self.memory.next(follow_to_index)
|
||||
pub fn forward(&self, is_follow_to_index: bool) -> Option<GString> {
|
||||
self.memory.next(is_follow_to_index)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use navigation::Navigation;
|
|||
use search::Search;
|
||||
use widget::Widget;
|
||||
|
||||
use super::{Action as ItemAction, BrowserAction, Profile, WindowAction};
|
||||
use super::{Action as ItemAction, BrowserAction, Profile, TabAction, WindowAction};
|
||||
|
||||
use gtk::{glib::GString, prelude::EditableExt};
|
||||
use sqlite::Transaction;
|
||||
|
|
@ -40,12 +40,12 @@ impl Page {
|
|||
pub fn build(
|
||||
id: &Rc<GString>,
|
||||
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 components
|
||||
let content = Rc::new(Content::build((window_action, item_action)));
|
||||
|
|
@ -54,8 +54,7 @@ impl Page {
|
|||
|
||||
let navigation = Rc::new(Navigation::build(
|
||||
profile,
|
||||
(browser_action, window_action, item_action),
|
||||
(back_action_name, forward_action_name),
|
||||
(browser_action, window_action, tab_action, item_action),
|
||||
));
|
||||
|
||||
let input = Rc::new(Input::new());
|
||||
|
|
|
|||
|
|
@ -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