Browse Source

draft header update on page reload

master
yggverse 2 months ago
parent
commit
ca74a29ffa
  1. 10
      src/browser/header/mod.rs
  2. 5
      src/browser/header/subject/description/mod.rs
  3. 18
      src/browser/header/subject/mod.rs
  4. 10
      src/browser/main/mod.rs
  5. 34
      src/browser/main/tab/mod.rs
  6. 5
      src/browser/mod.rs

10
src/browser/header/mod.rs

@ -4,11 +4,12 @@ mod tray; @@ -4,11 +4,12 @@ mod tray;
use subject::Subject;
use tray::Tray;
use gtk::HeaderBar;
use gtk::{glib::GString, HeaderBar};
use std::sync::Arc;
pub struct Header {
widget: HeaderBar,
subject: Subject,
}
impl Header {
@ -21,7 +22,12 @@ impl Header { @@ -21,7 +22,12 @@ impl Header {
widget.pack_start(tray.widget());
widget.set_title_widget(Some(subject.widget()));
Arc::new(Self { widget })
Arc::new(Self { widget, subject })
}
// Actions
pub fn update(&self, title: GString, description: GString) {
self.subject.update(title, description);
}
// Getters

5
src/browser/header/subject/description/mod.rs

@ -19,8 +19,9 @@ impl Description { @@ -19,8 +19,9 @@ impl Description {
}
// Actions
pub fn update(&self) {
self.widget.set_visible(self.widget.text().is_empty());
pub fn update(&self, text: &str) {
self.widget.set_text(text);
self.widget.set_visible(!text.is_empty());
}
// Getters

18
src/browser/header/subject/mod.rs

@ -2,12 +2,14 @@ mod description; @@ -2,12 +2,14 @@ mod description;
mod title;
use description::Description;
use gtk::prelude::BoxExt;
use gtk::{Align, Box, Orientation};
use title::Title;
use gtk::{glib::GString, prelude::BoxExt, Align, Box, Orientation};
pub struct Subject {
widget: Box,
title: Title,
description: Description,
}
impl Subject {
@ -24,7 +26,17 @@ impl Subject { @@ -24,7 +26,17 @@ impl Subject {
widget.append(title.widget());
widget.append(description.widget());
Self { widget }
Self {
widget,
title,
description,
}
}
// Actions
pub fn update(&self, title: GString, description: GString) {
self.title.update(&title);
self.description.update(&description);
}
// Getters

10
src/browser/main/mod.rs

@ -2,7 +2,7 @@ mod tab; @@ -2,7 +2,7 @@ mod tab;
use tab::Tab;
use gtk::{prelude::BoxExt, Box, Orientation};
use gtk::{glib::GString, prelude::BoxExt, Box, Orientation};
use std::sync::Arc;
pub struct Main {
@ -51,6 +51,14 @@ impl Main { @@ -51,6 +51,14 @@ impl Main {
}
// Getters
pub fn tab_page_title(&self) -> GString {
self.tab.page_title()
}
pub fn tab_page_description(&self) -> GString {
self.tab.page_description()
}
pub fn widget(&self) -> &Box {
&self.widget
}

34
src/browser/main/tab/mod.rs

@ -155,6 +155,40 @@ impl Tab { @@ -155,6 +155,40 @@ impl Tab {
}
// Getters
pub fn page_title(&self) -> GString {
// Get current page
if let Some(page_number) = self.widget.current_page() {
// Get default widget to extract it name as the ID for childs
if let Some(widget) = self.widget.nth_page(Some(page_number)) {
// Get widget ID
let id = &widget.widget_name();
// Get page by widget ID
if let Some(page) = self.pages.borrow().get(id) {
return page.title();
}
}
}
GString::new() // @TODO
}
pub fn page_description(&self) -> GString {
// Get current page
if let Some(page_number) = self.widget.current_page() {
// Get default widget to extract it name as the ID for childs
if let Some(widget) = self.widget.nth_page(Some(page_number)) {
// Get widget ID
let id = &widget.widget_name();
// Get page by widget ID
if let Some(page) = self.pages.borrow().get(id) {
return page.description();
}
}
}
GString::new() // @TODO
}
pub fn widget(&self) -> &Notebook {
self.widget.as_ref()
}

5
src/browser/mod.rs

@ -46,10 +46,11 @@ impl Browser { @@ -46,10 +46,11 @@ impl Browser {
widget.add_action_entries([
ActionEntry::builder("update")
.activate({
let header = header.clone();
let main = main.clone();
move |this: &ApplicationWindow, _, _| {
// header.update(); @TODO
move |_, _, _| {
main.update();
header.update(main.tab_page_title(), main.tab_page_description());
}
})
.build(),

Loading…
Cancel
Save