init update action

This commit is contained in:
yggverse 2024-09-24 23:08:40 +03:00
parent 68a97fdc88
commit ae3cc7a7d5
14 changed files with 91 additions and 27 deletions

View File

@ -1,17 +1,19 @@
mod subject;
mod tray;
use gtk::HeaderBar;
use subject::Subject;
use tray::Tray;
use gtk::HeaderBar;
use std::sync::Arc;
pub struct Header {
widget: HeaderBar,
}
impl Header {
// Construct
pub fn new() -> Header {
pub fn new() -> Arc<Header> {
let tray = Tray::new();
let subject = Subject::new();
@ -19,7 +21,7 @@ impl Header {
widget.pack_start(tray.widget());
widget.set_title_widget(Some(subject.widget()));
Self { widget }
Arc::new(Self { widget })
}
// Getters

View File

@ -12,7 +12,7 @@ pub struct Main {
impl Main {
// Construct
pub fn new() -> Main {
pub fn new() -> Arc<Main> {
// Init components
let tab = Tab::new();
@ -22,7 +22,7 @@ impl Main {
widget.append(tab.widget());
// Init struct
Self { tab, widget }
Arc::new(Self { tab, widget })
}
// Actions
@ -42,6 +42,10 @@ impl Main {
self.tab.pin();
}
pub fn update(&self) {
self.tab.update();
}
// Getters
pub fn widget(&self) -> &Box {
&self.widget

View File

@ -40,6 +40,11 @@ impl Label {
Self { pin, title, widget }
}
// Actions
pub fn update(&self) {
// @TODO
}
// Setters
pub fn pin(&self, is_pinned: bool) {
self.pin.widget().set_visible(is_pinned);

View File

@ -120,6 +120,27 @@ impl Tab {
}
}
pub fn update(&self) {
// 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 label by widget ID
if let Some(label) = self.labels.borrow().get(id) {
label.update();
}
// Get page by widget ID
if let Some(page) = self.pages.borrow().get(id) {
page.update();
}
}
}
}
// Getters
pub fn widget(&self) -> &Notebook {
self.widget.as_ref()

View File

@ -1,17 +1,23 @@
mod content;
mod navigation;
use content::Content;
use navigation::Navigation;
use gtk::{glib::GString, prelude::BoxExt, Box, Orientation};
pub struct Page {
widget: Box,
navigation: Navigation,
content: Content,
}
impl Page {
// Construct
pub fn new(name: GString) -> Page {
// Init components
let navigation = navigation::Navigation::new();
let content = content::Content::new();
let content = Content::new();
let navigation = Navigation::new();
// Init widget
let widget = Box::builder()
@ -23,7 +29,17 @@ impl Page {
widget.append(content.widget());
// Result
Self { widget }
Self {
widget,
content,
navigation,
}
}
// Actions
pub fn update(&self) {
self.navigation.update();
// @TODO self.content.update();
}
// Getters

View File

@ -19,7 +19,7 @@ impl Base {
// Actions
pub fn update(&self) {
todo!()
// @TODO
}
// Getters

View File

@ -19,7 +19,7 @@ impl Bookmark {
// Actions
pub fn update(&self) {
todo!()
// @TODO
}
// Getters

View File

@ -19,7 +19,7 @@ impl Back {
// Actions
pub fn update(&self) {
todo!()
// @TODO
}
// Getters

View File

@ -18,7 +18,7 @@ impl Forward {
// Actions
pub fn update(&self) {
todo!()
// @TODO
}
// Getters

View File

@ -48,6 +48,9 @@ impl Navigation {
widget.append(request.widget());
widget.append(bookmark.widget());
// Connect events
// request.widget().connect_changed({ |_, _, _| {} });
// Result
Self {
widget,

View File

@ -19,7 +19,7 @@ impl Reload {
// Actions
pub fn update(&self) {
todo!()
// @TODO
}
// Getters

View File

@ -18,7 +18,7 @@ impl Request {
// Actions
pub fn update(&self) {
todo!()
// @TODO
}
// Getters

View File

@ -2,9 +2,14 @@ mod db;
mod header;
mod main;
use gtk::gio::ActionEntry;
use gtk::prelude::{ActionMapExtManual, GtkWindowExt};
use gtk::{Application, ApplicationWindow};
use header::Header;
use main::Main;
use gtk::{
gio::ActionEntry,
prelude::{ActionMapExtManual, GtkWindowExt},
Application, ApplicationWindow,
};
use std::sync::Arc;
pub struct Browser {
@ -12,8 +17,8 @@ pub struct Browser {
// db: db::Browser,
widget: ApplicationWindow,
// Components
// header: Arc<header::Header>,
// main: main::Main,
header: Arc<Header>,
main: Arc<Main>,
}
impl Browser {
@ -38,9 +43,16 @@ impl Browser {
.build();
// Init actions
let main_ref = Arc::new(main); // @TODO
widget.add_action_entries([
ActionEntry::builder("update")
.activate({
let main = main.clone();
move |this: &ApplicationWindow, _, _| {
// header.update(); @TODO
main.update();
}
})
.build(),
ActionEntry::builder("debug")
.activate(|this: &ApplicationWindow, _, _| {
this.emit_enable_debugging(true);
@ -53,7 +65,7 @@ impl Browser {
.build(),
ActionEntry::builder("tab_append")
.activate({
let main = main_ref.clone();
let main = main.clone();
move |_, _, _| {
main.tab_append();
}
@ -61,7 +73,7 @@ impl Browser {
.build(),
ActionEntry::builder("tab_close")
.activate({
let main = main_ref.clone();
let main = main.clone();
move |_, _, _| {
main.tab_close();
}
@ -69,7 +81,7 @@ impl Browser {
.build(),
ActionEntry::builder("tab_close_all")
.activate({
let main = main_ref.clone();
let main = main.clone();
move |_, _, _| {
main.tab_close_all();
}
@ -77,7 +89,7 @@ impl Browser {
.build(),
ActionEntry::builder("tab_pin")
.activate({
let main = main_ref.clone();
let main = main.clone();
move |_, _, _| {
main.tab_pin();
}
@ -89,8 +101,8 @@ impl Browser {
Self {
// db,
widget,
// header,
// main,
header,
main,
}
}

View File

@ -22,6 +22,7 @@ fn main() -> glib::ExitCode {
app.set_accels_for_action("win.tab_page_reload", &["<Primary>r"]);
app.set_accels_for_action("win.tab_page_bookmark", &["<Primary>b"]);
app.set_accels_for_action("win.debug", &["<Primary>i"]);
app.set_accels_for_action("win.update", &["<Primary>u"]);
app.set_accels_for_action("win.quit", &["<Primary>Escape"]);
// Create new window