-
-
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.
reorganize reload action, add middle click handler
- Loading branch information
yggverse
committed
Jan 26, 2025
1 parent
3ee6a03
commit 8b4d184
Showing
5 changed files
with
80 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
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
56 changes: 45 additions & 11 deletions
56
src/app/browser/window/tab/item/page/navigation/reload.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,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 Reload { | ||
fn reload(action: &Rc<WindowAction>) -> Self; | ||
fn reload( | ||
action: (&Rc<WindowAction>, &Rc<TabAction>, &Rc<ItemAction>), | ||
request: &Rc<Request>, | ||
) -> Self; | ||
} | ||
|
||
impl Reload for Button { | ||
fn reload(action: &Rc<WindowAction>) -> Self { | ||
Button::builder() | ||
.action_name(format!( | ||
"{}.{}", | ||
action.id, | ||
action.reload.simple_action.name() | ||
)) // @TODO | ||
fn reload( | ||
(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.reload.name())) | ||
.icon_name("view-refresh-symbolic") | ||
.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 | ||
} | ||
} |