move tab open action to separated mod

This commit is contained in:
yggverse 2024-11-10 07:57:22 +02:00
parent 9ff32a3419
commit 38f945105c
13 changed files with 252 additions and 75 deletions

View file

@ -13,6 +13,7 @@ use navigation::Navigation;
use widget::Widget;
use crate::app::browser::action::Action as BrowserAction;
use crate::app::browser::window::tab::action::Action as TabAction;
use gtk::{
gdk_pixbuf::Pixbuf,
gio::{
@ -24,8 +25,7 @@ use gtk::{
RegexMatchFlags, Uri, UriFlags, UriHideFlags,
},
prelude::{
ActionExt, CancellableExt, IOStreamExt, OutputStreamExt, SocketClientExt,
StaticVariantType, ToVariant,
ActionExt, CancellableExt, IOStreamExt, OutputStreamExt, SocketClientExt, StaticVariantType,
},
Box,
};
@ -37,8 +37,8 @@ pub struct Page {
cancellable: RefCell<Cancellable>,
// Actions
browser_action: Rc<BrowserAction>,
tab_action: Rc<TabAction>,
action_page_load: SimpleAction,
action_page_open: SimpleAction,
// Components
navigation: Rc<Navigation>,
content: Rc<Content>,
@ -56,7 +56,7 @@ impl Page {
pub fn new_rc(
id: GString,
browser_action: Rc<BrowserAction>,
action_tab_open: SimpleAction,
tab_action: Rc<TabAction>,
action_page_home: SimpleAction,
action_page_history_back: SimpleAction,
action_page_history_forward: SimpleAction,
@ -68,7 +68,7 @@ impl Page {
SimpleAction::new(&uuid_string_random(), Some(&String::static_variant_type()));
// Init components
let content = Content::new_rc(action_tab_open.clone(), action_page_open.clone());
let content = Content::new_rc(tab_action.clone(), action_page_open.clone());
let navigation = Navigation::new_rc(
browser_action.clone(),
@ -97,8 +97,8 @@ impl Page {
id,
// Actions
browser_action,
tab_action,
action_page_load: action_page_load.clone(),
action_page_open: action_page_open.clone(),
// Components
content,
navigation,
@ -142,7 +142,7 @@ impl Page {
pub fn home(&self) {
if let Some(url) = self.navigation.home_url() {
// Update with history record
self.action_page_open.activate(Some(&url.to_variant()));
self.tab_action.open().activate(Some(&url));
}
}
@ -444,7 +444,7 @@ impl Page {
let cancellable = self.cancellable.borrow().clone();
let update = self.browser_action.update().clone();
let action_page_load = self.action_page_load.clone();
let action_page_open = self.action_page_open.clone();
let tab_action = self.tab_action.clone();
let content = self.content.clone();
let id = self.id.clone();
let input = self.input.clone();
@ -519,14 +519,14 @@ impl Page {
match response.status() {
gemini::client::response::meta::Status::SensitiveInput =>
input.set_new_sensitive(
action_page_open,
tab_action,
uri,
Some(description),
Some(1024),
),
_ =>
input.set_new_response(
action_page_open,
tab_action,
uri,
Some(description),
Some(1024),

View file

@ -6,6 +6,7 @@ use image::Image;
use status::Status;
use text::Text;
use crate::app::browser::window::tab::action::Action as TabAction;
use gtk::{
gdk_pixbuf::Pixbuf,
gio::SimpleAction,
@ -19,7 +20,7 @@ pub struct Content {
// GTK
gobject: Box,
// Actions
action_tab_open: SimpleAction,
tab_action: Rc<TabAction>,
action_page_open: SimpleAction,
}
@ -27,10 +28,10 @@ impl Content {
// Construct
/// Create new container for different components
pub fn new_rc(action_tab_open: SimpleAction, action_page_open: SimpleAction) -> Rc<Self> {
pub fn new_rc(tab_action: Rc<TabAction>, action_page_open: SimpleAction) -> Rc<Self> {
Rc::new(Self {
gobject: Box::builder().orientation(Orientation::Vertical).build(),
action_tab_open,
tab_action,
action_page_open,
})
}
@ -87,7 +88,7 @@ impl Content {
let text = Text::gemini(
data,
base,
self.action_tab_open.clone(),
self.tab_action.clone(),
self.action_page_open.clone(),
);
self.gobject.append(text.gobject());

View file

@ -2,11 +2,13 @@ mod gemini;
use gemini::Gemini;
use crate::app::browser::window::tab::action::Action as TabAction;
use gtk::{
gio::SimpleAction,
glib::{GString, Uri},
ScrolledWindow,
};
use std::rc::Rc;
pub struct Meta {
title: Option<GString>,
@ -22,11 +24,11 @@ impl Text {
pub fn gemini(
gemtext: &str,
base: &Uri,
action_page_new: SimpleAction,
tab_action: Rc<TabAction>,
action_page_open: SimpleAction,
) -> Self {
// Init components
let gemini = Gemini::new(gemtext, base, action_page_new, action_page_open);
let gemini = Gemini::new(gemtext, base, tab_action, action_page_open);
// Init meta
let meta = Meta {

View file

@ -4,13 +4,12 @@ mod widget;
use reader::Reader;
use widget::Widget;
use crate::app::browser::window::tab::action::Action as TabAction;
use adw::ClampScrollable;
use gtk::{
gio::SimpleAction,
glib::{GString, Uri},
};
use adw::ClampScrollable;
use std::rc::Rc;
pub struct Gemini {
@ -23,11 +22,11 @@ impl Gemini {
pub fn new(
gemtext: &str,
base: &Uri,
action_tab_open: SimpleAction,
tab_action: Rc<TabAction>,
action_page_open: SimpleAction,
) -> Self {
// Init components
let reader = Reader::new_rc(gemtext, base, action_tab_open, action_page_open);
let reader = Reader::new_rc(gemtext, base, tab_action, action_page_open);
let widget = Widget::new_rc(reader.gobject());

View file

@ -4,6 +4,7 @@ mod widget;
use tag::Tag;
use widget::Widget;
use crate::app::browser::window::tab::action::Action as TabAction;
use adw::StyleManager;
use gemtext::line::{
code::Code,
@ -20,7 +21,6 @@ use gtk::{
EventControllerMotion, GestureClick, TextBuffer, TextTag, TextView, TextWindowType,
UriLauncher, Window, WrapMode,
};
use std::{collections::HashMap, rc::Rc};
pub struct Reader {
@ -33,7 +33,7 @@ impl Reader {
pub fn new_rc(
gemtext: &str,
base: &Uri,
action_tab_open: SimpleAction,
tab_action: Rc<TabAction>,
action_page_open: SimpleAction,
) -> Rc<Self> {
// Init default values
@ -289,7 +289,7 @@ impl Reader {
return match uri.scheme().as_str() {
"gemini" => {
// Open new page in browser
action_tab_open.activate(Some(&uri.to_string().to_variant()));
tab_action.open().activate(Some(&uri.to_string()));
}
// Scheme not supported, delegate
_ => UriLauncher::new(&uri.to_str()).launch(

View file

@ -2,12 +2,13 @@ mod response;
mod sensitive;
mod widget;
use gtk::{gio::SimpleAction, glib::Uri};
use response::Response;
use sensitive::Sensitive;
use widget::Widget;
use crate::app::browser::window::tab::action::Action as TabAction;
use adw::Clamp;
use gtk::glib::Uri;
use std::rc::Rc;
pub struct Input {
@ -32,25 +33,25 @@ impl Input {
// Setters
pub fn set_new_response(
&self,
action_page_open: SimpleAction,
tab_action: Rc<TabAction>,
base: Uri,
title: Option<&str>,
size_limit: Option<usize>,
) {
self.widget.update(Some(
Response::new_rc(action_page_open, base, title, size_limit).gobject(),
Response::new_rc(tab_action, base, title, size_limit).gobject(),
));
}
pub fn set_new_sensitive(
&self,
action_page_open: SimpleAction,
tab_action: Rc<TabAction>,
base: Uri,
title: Option<&str>,
max_length: Option<i32>,
) {
self.widget.update(Some(
Sensitive::new_rc(action_page_open, base, title, max_length).gobject(),
Sensitive::new_rc(tab_action, base, title, max_length).gobject(),
));
}

View file

@ -8,10 +8,11 @@ use form::Form;
use title::Title;
use widget::Widget;
use crate::app::browser::window::tab::action::Action as TabAction;
use gtk::{
gio::SimpleAction,
glib::{uuid_string_random, Uri, UriHideFlags},
prelude::{ActionExt, ToVariant, WidgetExt},
prelude::WidgetExt,
Box,
};
use std::rc::Rc;
@ -24,7 +25,7 @@ pub struct Response {
impl Response {
// Construct
pub fn new_rc(
action_page_open: SimpleAction,
tab_action: Rc<TabAction>,
base: Uri,
title: Option<&str>,
size_limit: Option<usize>,
@ -58,14 +59,11 @@ impl Response {
action_send.connect_activate({
let form = form.clone();
move |_, _| {
action_page_open.activate(Some(
&format!(
"{}?{}",
base.to_string_partial(UriHideFlags::QUERY),
Uri::escape_string(form.text().as_str(), None, false),
)
.to_variant(),
));
tab_action.open().activate(Some(&format!(
"{}?{}",
base.to_string_partial(UriHideFlags::QUERY),
Uri::escape_string(form.text().as_str(), None, false),
)));
}
});

View file

@ -4,10 +4,11 @@ mod widget;
use form::Form;
use widget::Widget;
use crate::app::browser::window::tab::action::Action as TabAction;
use gtk::{
gio::SimpleAction,
glib::{uuid_string_random, Uri, UriHideFlags},
prelude::{ActionExt, ToVariant, WidgetExt},
prelude::WidgetExt,
Box,
};
use std::rc::Rc;
@ -20,7 +21,7 @@ pub struct Sensitive {
impl Sensitive {
// Construct
pub fn new_rc(
action_page_open: SimpleAction,
tab_action: Rc<TabAction>,
base: Uri,
title: Option<&str>,
max_length: Option<i32>,
@ -43,14 +44,11 @@ impl Sensitive {
action_send.connect_activate({
let form = form.clone();
move |_, _| {
action_page_open.activate(Some(
&format!(
"{}?{}",
base.to_string_partial(UriHideFlags::QUERY),
Uri::escape_string(form.text().as_str(), None, false),
)
.to_variant(),
));
tab_action.open().activate(Some(&format!(
"{}?{}",
base.to_string_partial(UriHideFlags::QUERY),
Uri::escape_string(form.text().as_str(), None, false),
)));
}
});