-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement middle click controller for history navigation buttons
- Loading branch information
yggverse
committed
Jan 26, 2025
1 parent
b9b91fb
commit 2b472eb
Showing
8 changed files
with
115 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 46 additions & 6 deletions
52
src/app/browser/window/tab/item/page/navigation/history/back.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
52 changes: 46 additions & 6 deletions
52
src/app/browser/window/tab/item/page/navigation/history/forward.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |