From 6684b09ae27d1ff69a5d2a44f6c292452eb5d4ef Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 11 Oct 2024 02:32:43 +0300 Subject: [PATCH] create separated mod for page widget --- src/app/browser/window/tab/item/page.rs | 37 +++++++-------- .../browser/window/tab/item/page/content.rs | 2 +- .../window/tab/item/page/navigation.rs | 2 +- .../browser/window/tab/item/page/widget.rs | 45 +++++++++++++++++++ 4 files changed, 62 insertions(+), 24 deletions(-) create mode 100644 src/app/browser/window/tab/item/page/widget.rs diff --git a/src/app/browser/window/tab/item/page.rs b/src/app/browser/window/tab/item/page.rs index b38c20c3..fb9d3567 100644 --- a/src/app/browser/window/tab/item/page.rs +++ b/src/app/browser/window/tab/item/page.rs @@ -1,10 +1,12 @@ mod content; mod meta; mod navigation; +mod widget; use content::Content; use meta::{Meta, Mime, Status}; use navigation::Navigation; +use widget::Widget; use gtk::{ gio::{ @@ -21,8 +23,6 @@ use gtk::{ use std::{cell::RefCell, path::Path, sync::Arc}; pub struct Page { - // GTK - gobject: Box, // Actions action_page_open: Arc, action_tab_page_navigation_reload: Arc, @@ -32,6 +32,8 @@ pub struct Page { content: Arc, // Extras meta: Arc>, + // GTK + widget: Arc, } impl Page { @@ -45,16 +47,12 @@ impl Page { action_tab_page_navigation_reload: Arc, action_update: Arc, ) -> Arc { - // Init actions + // Init local actions let action_page_open = Arc::new(SimpleAction::new( - "open", + "open", // @TODO Some(&String::static_variant_type()), )); - // Init action group - let action_group = SimpleActionGroup::new(); - action_group.add_action(action_page_open.as_ref()); - // Init components let content = Arc::new(Content::new(action_page_open.clone())); let navigation = Arc::new(Navigation::new( @@ -65,17 +63,12 @@ impl Page { action_tab_page_navigation_reload.clone(), action_update.clone(), )); - - // Init widget - let gobject = Box::builder() - .orientation(Orientation::Vertical) - .name(name) - .build(); - - gobject.append(navigation.widget()); - gobject.append(content.widget()); - - gobject.insert_action_group("page", Some(&action_group)); + let widget = Widget::new_arc( + action_page_open.clone(), + &name, // ID + navigation.gobject(), + content.gobject(), + ); // Init async mutable Meta object let meta = Arc::new(RefCell::new(Meta::new())); @@ -103,8 +96,6 @@ impl Page { // Return activated structure Arc::new(Self { - // GTK - gobject, // Actions action_page_open, action_tab_page_navigation_reload, @@ -114,6 +105,8 @@ impl Page { navigation, // Extras meta, + // GTK + widget, }) } @@ -484,6 +477,6 @@ impl Page { } pub fn gobject(&self) -> &Box { - &self.gobject + &self.widget.gobject() } } diff --git a/src/app/browser/window/tab/item/page/content.rs b/src/app/browser/window/tab/item/page/content.rs index 001431ad..d92a368d 100644 --- a/src/app/browser/window/tab/item/page/content.rs +++ b/src/app/browser/window/tab/item/page/content.rs @@ -62,7 +62,7 @@ impl Content { } // Getters - pub fn widget(&self) -> &Box { + pub fn gobject(&self) -> &Box { &self.widget } } diff --git a/src/app/browser/window/tab/item/page/navigation.rs b/src/app/browser/window/tab/item/page/navigation.rs index d648923a..3c0708f3 100644 --- a/src/app/browser/window/tab/item/page/navigation.rs +++ b/src/app/browser/window/tab/item/page/navigation.rs @@ -118,7 +118,7 @@ impl Navigation { } // Getters - pub fn widget(&self) -> &Box { + pub fn gobject(&self) -> &Box { &self.widget } diff --git a/src/app/browser/window/tab/item/page/widget.rs b/src/app/browser/window/tab/item/page/widget.rs new file mode 100644 index 00000000..300361b5 --- /dev/null +++ b/src/app/browser/window/tab/item/page/widget.rs @@ -0,0 +1,45 @@ +use gtk::{ + gio::{SimpleAction, SimpleActionGroup}, + prelude::{ActionMapExt, BoxExt, WidgetExt}, + Box, Orientation, +}; +use std::sync::Arc; + +pub struct Widget { + gobject: Box, +} + +impl Widget { + // Construct + pub fn new_arc( + // Actions + action_page_open: Arc, + // Options + name: &str, + // Components + navigation: &Box, + content: &Box, + ) -> Arc { + // Init additional action group + let action_group = SimpleActionGroup::new(); + action_group.add_action(action_page_open.as_ref()); + + // Init self + let gobject = Box::builder() + .orientation(Orientation::Vertical) + .name(name) + .build(); + + gobject.append(navigation); + gobject.append(content); + + gobject.insert_action_group("page", Some(&action_group)); + + Arc::new(Self { gobject }) + } + + // Getters + pub fn gobject(&self) -> &Box { + &self.gobject + } +}