use tuple for actions

This commit is contained in:
yggverse 2024-11-11 15:14:32 +02:00
parent 0cf4206ebc
commit 8917d14908
4 changed files with 8 additions and 25 deletions

View File

@ -85,8 +85,7 @@ impl Content {
let text = Text::gemini(
data,
base,
self.window_action.clone(),
self.tab_action.clone(),
(self.window_action.clone(), self.tab_action.clone()),
);
self.gobject.append(text.gobject());
text

View File

@ -20,14 +20,9 @@ pub struct Text {
impl Text {
// Construct
pub fn gemini(
gemtext: &str,
base: &Uri,
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
) -> Self {
pub fn gemini(gemtext: &str, base: &Uri, actions: (Rc<WindowAction>, Rc<TabAction>)) -> Self {
// Init components
let gemini = Gemini::new(gemtext, base, window_action, tab_action);
let gemini = Gemini::new(gemtext, base, actions);
// Init meta
let meta = Meta {

View File

@ -16,14 +16,9 @@ pub struct Gemini {
impl Gemini {
// Construct
pub fn new(
gemtext: &str,
base: &Uri,
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
) -> Self {
pub fn new(gemtext: &str, base: &Uri, actions: (Rc<WindowAction>, Rc<TabAction>)) -> Self {
// Init components
let reader = Rc::new(Reader::new(gemtext, base, window_action, tab_action));
let reader = Rc::new(Reader::new(gemtext, base, actions));
let widget = Rc::new(Widget::new(reader.gobject()));
// Result

View File

@ -30,12 +30,7 @@ pub struct Reader {
impl Reader {
// Construct
pub fn new(
gemtext: &str,
base: &Uri,
window_action: Rc<WindowAction>,
tab_action: Rc<TabAction>,
) -> Self {
pub fn new(gemtext: &str, base: &Uri, actions: (Rc<WindowAction>, Rc<TabAction>)) -> Self {
// Init default values
let mut title = None;
@ -232,7 +227,6 @@ impl Reader {
// Init events
primary_button_controller.connect_released({
let tab_action = tab_action.clone();
let gobject = widget.gobject().clone();
let _links_ = links.clone(); // is copy
move |_, _, window_x, window_y| {
@ -251,7 +245,7 @@ impl Reader {
return match uri.scheme().as_str() {
"gemini" => {
// Open new page in browser
tab_action.load().activate(Some(&uri.to_str()));
actions.1.load().activate(Some(&uri.to_str()));
}
// Scheme not supported, delegate
_ => UriLauncher::new(&uri.to_str()).launch(
@ -288,7 +282,7 @@ impl Reader {
return match uri.scheme().as_str() {
"gemini" => {
// Open new page in browser
window_action.append().activate_stateful_once(
actions.0.append().activate_stateful_once(
None,
Some(uri.to_string()),
false,