diff --git a/src/app/browser.rs b/src/app/browser.rs index 9445bd21..ecc58175 100644 --- a/src/app/browser.rs +++ b/src/app/browser.rs @@ -10,6 +10,7 @@ use window::Window; use gtk::{ gio::{AppInfo, AppLaunchContext, SimpleAction}, + glib::GString, prelude::{ActionMapExt, GtkWindowExt}, ApplicationWindow, }; @@ -121,8 +122,21 @@ impl Browser { let header = header.clone(); let window = window.clone(); move |_, _| { + // Update window first window.update(); - header.update(window.tab_page_title(), window.tab_page_description()); + + // Update header + let title = match window.tab_page_title() { + Some(value) => value, + None => GString::new(), // @TODO + }; + + let subtitle = match window.tab_page_description() { + Some(value) => value, + None => GString::new(), // @TODO + }; + + header.update(Some(title.as_str()), Some(subtitle.as_str())); } }); diff --git a/src/app/browser/header.rs b/src/app/browser/header.rs index 952f1d22..cb9f2ae8 100644 --- a/src/app/browser/header.rs +++ b/src/app/browser/header.rs @@ -1,17 +1,17 @@ -mod subject; +mod title; mod tray; mod widget; -use subject::Subject; +use title::Title; use tray::Tray; use widget::Widget; use adw::HeaderBar; -use gtk::{gio::SimpleAction, glib::GString}; +use gtk::gio::SimpleAction; use std::sync::Arc; pub struct Header { - subject: Arc, + title: Arc, // tray: Arc<Subject>, widget: Arc<Widget>, } @@ -46,18 +46,18 @@ impl Header { action_tab_pin, ); - let subject = Arc::new(Subject::new()); + let title = Arc::new(Title::new()); // Init widget - let widget = Arc::new(Widget::new(tray.gobject(), Some(subject.gobject()))); + let widget = Arc::new(Widget::new(tray.gobject(), Some(title.gobject()))); // Return new struct - Self { subject, widget } + Self { title, widget } } // Actions - pub fn update(&self, title: Option<GString>, description: Option<GString>) { - self.subject.update(title, description); + pub fn update(&self, title: Option<&str>, description: Option<&str>) { + self.title.update(title, description); } // Getters diff --git a/src/app/browser/header/subject.rs b/src/app/browser/header/subject.rs deleted file mode 100644 index f9ac9547..00000000 --- a/src/app/browser/header/subject.rs +++ /dev/null @@ -1,46 +0,0 @@ -mod description; -mod title; - -use description::Description; -use title::Title; - -use gtk::{glib::GString, prelude::BoxExt, Align, Box, Orientation}; - -pub struct Subject { - gobject: Box, - title: Title, - description: Description, -} - -impl Subject { - // Construct - pub fn new() -> Self { - let title = Title::new(); - let description = Description::new(); - - let gobject = Box::builder() - .orientation(Orientation::Vertical) - .valign(Align::Center) - .build(); - - gobject.append(title.gobject()); - gobject.append(description.gobject()); - - Self { - gobject, - title, - description, - } - } - - // Actions - pub fn update(&self, title: Option<GString>, description: Option<GString>) { - self.title.update(title); - self.description.update(description); - } - - // Getters - pub fn gobject(&self) -> &Box { - &self.gobject - } -} diff --git a/src/app/browser/header/subject/description.rs b/src/app/browser/header/subject/description.rs deleted file mode 100644 index f41cf58b..00000000 --- a/src/app/browser/header/subject/description.rs +++ /dev/null @@ -1,35 +0,0 @@ -use gtk::glib::GString; -use gtk::prelude::WidgetExt; -use gtk::{pango::EllipsizeMode, Label}; - -pub struct Description { - gobject: Label, -} - -impl Description { - // Construct - pub fn new() -> Self { - let gobject = Label::builder() - .css_classes(["subtitle"]) - .single_line_mode(true) - .ellipsize(EllipsizeMode::End) - .visible(false) - .build(); - - Self { gobject } - } - - // Actions - pub fn update(&self, text: Option<GString>) { - match text { - Some(value) => self.gobject.set_text(&value), - None => self.gobject.set_text(""), // @TODO - }; - self.gobject.set_visible(!self.gobject.text().is_empty()); - } - - // Getters - pub fn gobject(&self) -> &Label { - &self.gobject - } -} diff --git a/src/app/browser/header/subject/title.rs b/src/app/browser/header/subject/title.rs deleted file mode 100644 index 01ce8edf..00000000 --- a/src/app/browser/header/subject/title.rs +++ /dev/null @@ -1,41 +0,0 @@ -use gtk::{glib::GString, pango::EllipsizeMode, Label}; - -const DEFAULT_TEXT: &str = "Yoda"; // @TODO - -pub struct Title { - gobject: Label, -} - -impl Title { - // Construct - pub fn new() -> Self { - let gobject = gtk::Label::builder() - .css_classes(["title"]) - .single_line_mode(true) - .ellipsize(EllipsizeMode::End) - .label(DEFAULT_TEXT) - .build(); - - Self { gobject } - } - - // Actions - pub fn update(&self, text: Option<GString>) { - let mut name = Vec::new(); - - if let Some(value) = text { - if !value.is_empty() { - name.push(value); - } - } - - name.push(GString::from(DEFAULT_TEXT)); - - self.gobject.set_text(&name.join(" - ")); - } - - // Getters - pub fn gobject(&self) -> &Label { - &self.gobject - } -} diff --git a/src/app/browser/header/title.rs b/src/app/browser/header/title.rs new file mode 100644 index 00000000..8f185d7a --- /dev/null +++ b/src/app/browser/header/title.rs @@ -0,0 +1,44 @@ +use adw::WindowTitle; + +const DEFAULT_TITLE: &str = "Yoda"; // @TODO +const DEFAULT_SUBTITLE: &str = ""; + +pub struct Title { + gobject: WindowTitle, +} + +impl Title { + // Construct + pub fn new() -> Self { + Self { + gobject: WindowTitle::new(DEFAULT_TITLE, DEFAULT_SUBTITLE), + } + } + + // Actions + pub fn update(&self, title: Option<&str>, subtitle: Option<&str>) { + // Update title + let mut name = Vec::new(); + + if let Some(value) = title { + if !value.is_empty() { + name.push(value); + } + } + + name.push(DEFAULT_TITLE); + + self.gobject.set_title(&name.join(" - ")); + + // Update subtitle + self.gobject.set_subtitle(&match subtitle { + Some(value) => value, + None => "", // @TODO + }); + } + + // Getters + pub fn gobject(&self) -> &WindowTitle { + &self.gobject + } +} diff --git a/src/app/browser/header/widget.rs b/src/app/browser/header/widget.rs index 7459e3bd..4e9d2af5 100644 --- a/src/app/browser/header/widget.rs +++ b/src/app/browser/header/widget.rs @@ -1,4 +1,4 @@ -use adw::HeaderBar; +use adw::{HeaderBar, WindowTitle}; use gtk::Box; pub struct Widget { @@ -7,7 +7,7 @@ pub struct Widget { impl Widget { // Construct - pub fn new(pack_start: &Box, title_widget: Option<&Box>) -> Self { + pub fn new(pack_start: &Box, title_widget: Option<&WindowTitle>) -> Self { let gobject = HeaderBar::builder().build(); gobject.pack_start(pack_start);