Browse Source

create new tag for new link

master
yggverse 2 months ago
parent
commit
15decfa19a
  1. 22
      src/app/browser/window/tab/item/page/content/text/gemini/reader.rs
  2. 15
      src/app/browser/window/tab/item/page/content/text/gemini/reader/tag.rs
  3. 24
      src/app/browser/window/tab/item/page/content/text/gemini/reader/tag/link.rs

22
src/app/browser/window/tab/item/page/content/text/gemini/reader.rs

@ -12,6 +12,7 @@ use parser::{
use tag::Tag; use tag::Tag;
use widget::Widget; use widget::Widget;
use adw::StyleManager;
use gtk::{ use gtk::{
gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY}, gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY},
gio::{AppInfo, AppLaunchContext, SimpleAction}, gio::{AppInfo, AppLaunchContext, SimpleAction},
@ -39,7 +40,7 @@ impl Reader {
let mut title = None; let mut title = None;
// Init HashMap storage for event controllers // Init HashMap storage for event controllers
let mut links: HashMap<&TextTag, Uri> = HashMap::new(); let mut links: HashMap<TextTag, Uri> = HashMap::new();
// Init multiline code builder features // Init multiline code builder features
let mut multiline = None; let mut multiline = None;
@ -133,9 +134,6 @@ impl Reader {
// Is link // Is link
if let Some(link) = Link::from(line, Some(base), Some(&TimeZone::local())) { if let Some(link) = Link::from(line, Some(base), Some(&TimeZone::local())) {
// Append tag to HashMap storage
// links.insert(tag.link(), link.uri.clone()); @TODO
// Create vector for alt values // Create vector for alt values
let mut alt = Vec::new(); let mut alt = Vec::new();
@ -160,10 +158,24 @@ impl Reader {
None => link.uri.to_string(), None => link.uri.to_string(),
}); });
// Create new tag for new link
let a = TextTag::builder()
.foreground_rgba(&StyleManager::default().accent_color_rgba()) // @TODO
.sentence(true)
.wrap_mode(WrapMode::Word)
.build();
if !tag.add(&a) {
panic!() // @TODO handle
}
// Append alt vector values to buffer // Append alt vector values to buffer
buffer.insert_with_tags(&mut buffer.end_iter(), &alt.join(" "), &[&tag.link()]); buffer.insert_with_tags(&mut buffer.end_iter(), &alt.join(" "), &[&a]);
buffer.insert(&mut buffer.end_iter(), "\n"); buffer.insert(&mut buffer.end_iter(), "\n");
// Append tag to HashMap storage
links.insert(a, link.uri.clone());
// Skip other actions for this line // Skip other actions for this line
continue; continue;
} }

15
src/app/browser/window/tab/item/page/content/text/gemini/reader/tag.rs

@ -2,7 +2,6 @@ mod code;
mod h1; mod h1;
mod h2; mod h2;
mod h3; mod h3;
mod link;
mod list; mod list;
mod quote; mod quote;
mod title; mod title;
@ -11,7 +10,6 @@ use code::Code;
use h1::H1; use h1::H1;
use h2::H2; use h2::H2;
use h3::H3; use h3::H3;
use link::Link;
use list::List; use list::List;
use quote::Quote; use quote::Quote;
use title::Title; use title::Title;
@ -25,7 +23,6 @@ pub struct Tag {
h1: H1, h1: H1,
h2: H2, h2: H2,
h3: H3, h3: H3,
link: Link,
list: List, list: List,
quote: Quote, quote: Quote,
title: Title, title: Title,
@ -39,7 +36,6 @@ impl Tag {
let h1 = H1::new(); let h1 = H1::new();
let h2 = H2::new(); let h2 = H2::new();
let h3 = H3::new(); let h3 = H3::new();
let link = Link::new();
let list = List::new(); let list = List::new();
let quote = Quote::new(); let quote = Quote::new();
let title = Title::new(); let title = Title::new();
@ -52,7 +48,6 @@ impl Tag {
gobject.add(h2.gobject()); gobject.add(h2.gobject());
gobject.add(h3.gobject()); gobject.add(h3.gobject());
gobject.add(title.gobject()); gobject.add(title.gobject());
gobject.add(link.gobject());
gobject.add(list.gobject()); gobject.add(list.gobject());
gobject.add(quote.gobject()); gobject.add(quote.gobject());
@ -63,13 +58,17 @@ impl Tag {
h1, h1,
h2, h2,
h3, h3,
link,
list, list,
quote, quote,
title, title,
} }
} }
// Actions
pub fn add(&self, tag: &TextTag) -> bool {
self.gobject.add(tag)
}
// Getters // Getters
pub fn gobject(&self) -> &TextTagTable { pub fn gobject(&self) -> &TextTagTable {
&self.gobject &self.gobject
@ -91,10 +90,6 @@ impl Tag {
&self.h3.gobject() &self.h3.gobject()
} }
pub fn link(&self) -> &TextTag {
&self.link.gobject()
}
pub fn list(&self) -> &TextTag { pub fn list(&self) -> &TextTag {
&self.list.gobject() &self.list.gobject()
} }

24
src/app/browser/window/tab/item/page/content/text/gemini/reader/tag/link.rs

@ -1,24 +0,0 @@
use adw::StyleManager;
use gtk::{TextTag, WrapMode};
pub struct Link {
tag: TextTag,
}
impl Link {
// Construct
pub fn new() -> Self {
Self {
tag: TextTag::builder()
.foreground_rgba(&StyleManager::default().accent_color_rgba()) // @TODO
.sentence(true)
.wrap_mode(WrapMode::Word)
.build(),
}
}
// Getters
pub fn gobject(&self) -> &TextTag {
&self.tag
}
}
Loading…
Cancel
Save