From 15decfa19a106ed6de70d2d6f8afd3e2634f0a64 Mon Sep 17 00:00:00 2001 From: yggverse Date: Tue, 15 Oct 2024 06:30:31 +0300 Subject: [PATCH] create new tag for new link --- .../item/page/content/text/gemini/reader.rs | 22 +++++++++++++---- .../page/content/text/gemini/reader/tag.rs | 15 ++++-------- .../content/text/gemini/reader/tag/link.rs | 24 ------------------- 3 files changed, 22 insertions(+), 39 deletions(-) delete mode 100644 src/app/browser/window/tab/item/page/content/text/gemini/reader/tag/link.rs diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs b/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs index 0ff51fe4..671759ac 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini/reader.rs @@ -12,6 +12,7 @@ use parser::{ use tag::Tag; use widget::Widget; +use adw::StyleManager; use gtk::{ gdk::{BUTTON_MIDDLE, BUTTON_PRIMARY}, gio::{AppInfo, AppLaunchContext, SimpleAction}, @@ -39,7 +40,7 @@ impl Reader { let mut title = None; // Init HashMap storage for event controllers - let mut links: HashMap<&TextTag, Uri> = HashMap::new(); + let mut links: HashMap = HashMap::new(); // Init multiline code builder features let mut multiline = None; @@ -133,9 +134,6 @@ impl Reader { // Is link 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 let mut alt = Vec::new(); @@ -160,10 +158,24 @@ impl Reader { 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 - 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"); + // Append tag to HashMap storage + links.insert(a, link.uri.clone()); + // Skip other actions for this line continue; } diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/tag.rs b/src/app/browser/window/tab/item/page/content/text/gemini/reader/tag.rs index a97dd4db..ef0ac5aa 100644 --- a/src/app/browser/window/tab/item/page/content/text/gemini/reader/tag.rs +++ b/src/app/browser/window/tab/item/page/content/text/gemini/reader/tag.rs @@ -2,7 +2,6 @@ mod code; mod h1; mod h2; mod h3; -mod link; mod list; mod quote; mod title; @@ -11,7 +10,6 @@ use code::Code; use h1::H1; use h2::H2; use h3::H3; -use link::Link; use list::List; use quote::Quote; use title::Title; @@ -25,7 +23,6 @@ pub struct Tag { h1: H1, h2: H2, h3: H3, - link: Link, list: List, quote: Quote, title: Title, @@ -39,7 +36,6 @@ impl Tag { let h1 = H1::new(); let h2 = H2::new(); let h3 = H3::new(); - let link = Link::new(); let list = List::new(); let quote = Quote::new(); let title = Title::new(); @@ -52,7 +48,6 @@ impl Tag { gobject.add(h2.gobject()); gobject.add(h3.gobject()); gobject.add(title.gobject()); - gobject.add(link.gobject()); gobject.add(list.gobject()); gobject.add(quote.gobject()); @@ -63,13 +58,17 @@ impl Tag { h1, h2, h3, - link, list, quote, title, } } + // Actions + pub fn add(&self, tag: &TextTag) -> bool { + self.gobject.add(tag) + } + // Getters pub fn gobject(&self) -> &TextTagTable { &self.gobject @@ -91,10 +90,6 @@ impl Tag { &self.h3.gobject() } - pub fn link(&self) -> &TextTag { - &self.link.gobject() - } - pub fn list(&self) -> &TextTag { &self.list.gobject() } diff --git a/src/app/browser/window/tab/item/page/content/text/gemini/reader/tag/link.rs b/src/app/browser/window/tab/item/page/content/text/gemini/reader/tag/link.rs deleted file mode 100644 index 587a63ad..00000000 --- a/src/app/browser/window/tab/item/page/content/text/gemini/reader/tag/link.rs +++ /dev/null @@ -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 - } -}