Browse Source

use action object

master
yggverse 2 months ago
parent
commit
ae2bb93ea7
  1. 2
      src/browser/main/tab/page.rs
  2. 21
      src/browser/main/tab/page/content.rs
  3. 7
      src/browser/main/tab/page/content/text.rs
  4. 7
      src/browser/main/tab/page/content/text/gemini.rs
  5. 21
      src/browser/main/tab/page/content/text/gemini/reader.rs

2
src/browser/main/tab/page.rs

@ -52,7 +52,7 @@ impl Page { @@ -52,7 +52,7 @@ impl Page {
action_group.add_action(action_open.as_ref());
// Init components
let content = Arc::new(Content::new());
let content = Arc::new(Content::new(action_open.clone()));
let navigation = Arc::new(Navigation::new(
navigation_request_text,
action_tab_page_reload.clone(),

21
src/browser/main/tab/page/content.rs

@ -4,14 +4,17 @@ mod text; @@ -4,14 +4,17 @@ mod text;
use text::Text;
use gtk::{
gio::SimpleAction,
glib::{GString, Uri},
prelude::{BoxExt, WidgetExt},
Box, Orientation,
};
use std::sync::Arc;
pub enum Mime {
TextGemini,
TextPlain,
// TextPlain,
}
pub struct ResetResult {
@ -19,14 +22,18 @@ pub struct ResetResult { @@ -19,14 +22,18 @@ pub struct ResetResult {
}
pub struct Content {
// GTK
widget: Box,
// Actions
action_open: Arc<SimpleAction>,
}
impl Content {
// Construct
pub fn new() -> Self {
pub fn new(action_open: Arc<SimpleAction>) -> Self {
Self {
widget: Box::builder().orientation(Orientation::Vertical).build(),
action_open,
}
}
@ -40,17 +47,17 @@ impl Content { @@ -40,17 +47,17 @@ impl Content {
// Re-compose
match mime {
Mime::TextGemini => {
let child = Text::gemini(data, base);
let child = Text::gemini(data, base, self.action_open.clone());
self.widget.append(child.widget());
ResetResult {
title: child.meta_title().clone(),
}
}
Mime::TextPlain => {
todo!()
}
} /* @TODO
Mime::TextPlain => {
todo!()
} */
}
}

7
src/browser/main/tab/page/content/text.rs

@ -3,10 +3,13 @@ mod gemini; @@ -3,10 +3,13 @@ mod gemini;
use gemini::Gemini;
use gtk::{
gio::SimpleAction,
glib::{GString, Uri},
ScrolledWindow,
};
use std::sync::Arc;
pub struct Meta {
title: Option<GString>,
}
@ -18,9 +21,9 @@ pub struct Text { @@ -18,9 +21,9 @@ pub struct Text {
impl Text {
// Construct
pub fn gemini(gemtext: &str, base: &Uri) -> Self {
pub fn gemini(gemtext: &str, base: &Uri, action_open: Arc<SimpleAction>) -> Self {
// Init components
let gemini = Gemini::new(gemtext, base);
let gemini = Gemini::new(gemtext, base, action_open);
// Init meta
let meta = Meta {

7
src/browser/main/tab/page/content/text/gemini.rs

@ -3,10 +3,13 @@ mod reader; @@ -3,10 +3,13 @@ mod reader;
use reader::Reader;
use gtk::{
gio::SimpleAction,
glib::{GString, Uri},
Viewport,
};
use std::sync::Arc;
pub struct Gemini {
reader: Reader,
widget: Viewport,
@ -14,9 +17,9 @@ pub struct Gemini { @@ -14,9 +17,9 @@ pub struct Gemini {
impl Gemini {
// Construct
pub fn new(gemtext: &str, base: &Uri) -> Self {
pub fn new(gemtext: &str, base: &Uri, action_open: Arc<SimpleAction>) -> Self {
// Init components
let reader = Reader::new(gemtext, base);
let reader = Reader::new(gemtext, base, action_open);
// Init widget
let widget = Viewport::builder().scroll_to_focus(false).build();

21
src/browser/main/tab/page/content/text/gemini/reader.rs

@ -5,20 +5,23 @@ use parser::link::Link; @@ -5,20 +5,23 @@ use parser::link::Link;
use parser::plain::Plain;
use gtk::{
gio::SimpleAction,
glib::{GString, Propagation, Uri, UriFlags},
prelude::{StyleContextExt, ToVariant, WidgetExt},
prelude::{ActionExt, StyleContextExt, ToVariant, WidgetExt},
Align, CssProvider, Label, STYLE_PROVIDER_PRIORITY_APPLICATION,
};
use std::sync::Arc;
pub struct Reader {
title: Option<GString>,
css: CssProvider,
// css: CssProvider,
widget: Label,
}
impl Reader {
// Construct
pub fn new(gemtext: &str, base: &Uri) -> Self {
pub fn new(gemtext: &str, base: &Uri, action_open: Arc<SimpleAction>) -> Self {
// Init title
let mut title = None;
@ -82,15 +85,13 @@ impl Reader { @@ -82,15 +85,13 @@ impl Reader {
.add_provider(&css, STYLE_PROVIDER_PRIORITY_APPLICATION);
// Connect actions
widget.connect_activate_link(|label, href| {
widget.connect_activate_link(move |_, href| {
// Detect requested protocol
if let Ok(uri) = Uri::parse(&href, UriFlags::NONE) {
return match uri.scheme().as_str() {
"gemini" => {
// Open new page
label
.activate_action("page.open", Some(&uri.to_str().to_variant()))
.expect("Action `page.open` not found");
action_open.activate(Some(&uri.to_str().to_variant()));
// Prevent link open in external application
Propagation::Stop
@ -105,7 +106,11 @@ impl Reader { @@ -105,7 +106,11 @@ impl Reader {
});
// Result
Self { title, css, widget }
Self {
title,
// css,
widget,
}
}
// Getters

Loading…
Cancel
Save