mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-13 06:01:21 +00:00
create separated mod for page widget
This commit is contained in:
parent
a1aaebdb7e
commit
6684b09ae2
@ -1,10 +1,12 @@
|
|||||||
mod content;
|
mod content;
|
||||||
mod meta;
|
mod meta;
|
||||||
mod navigation;
|
mod navigation;
|
||||||
|
mod widget;
|
||||||
|
|
||||||
use content::Content;
|
use content::Content;
|
||||||
use meta::{Meta, Mime, Status};
|
use meta::{Meta, Mime, Status};
|
||||||
use navigation::Navigation;
|
use navigation::Navigation;
|
||||||
|
use widget::Widget;
|
||||||
|
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::{
|
gio::{
|
||||||
@ -21,8 +23,6 @@ use gtk::{
|
|||||||
use std::{cell::RefCell, path::Path, sync::Arc};
|
use std::{cell::RefCell, path::Path, sync::Arc};
|
||||||
|
|
||||||
pub struct Page {
|
pub struct Page {
|
||||||
// GTK
|
|
||||||
gobject: Box,
|
|
||||||
// Actions
|
// Actions
|
||||||
action_page_open: Arc<SimpleAction>,
|
action_page_open: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||||
@ -32,6 +32,8 @@ pub struct Page {
|
|||||||
content: Arc<Content>,
|
content: Arc<Content>,
|
||||||
// Extras
|
// Extras
|
||||||
meta: Arc<RefCell<Meta>>,
|
meta: Arc<RefCell<Meta>>,
|
||||||
|
// GTK
|
||||||
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Page {
|
impl Page {
|
||||||
@ -45,16 +47,12 @@ impl Page {
|
|||||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||||
action_update: Arc<SimpleAction>,
|
action_update: Arc<SimpleAction>,
|
||||||
) -> Arc<Self> {
|
) -> Arc<Self> {
|
||||||
// Init actions
|
// Init local actions
|
||||||
let action_page_open = Arc::new(SimpleAction::new(
|
let action_page_open = Arc::new(SimpleAction::new(
|
||||||
"open",
|
"open", // @TODO
|
||||||
Some(&String::static_variant_type()),
|
Some(&String::static_variant_type()),
|
||||||
));
|
));
|
||||||
|
|
||||||
// Init action group
|
|
||||||
let action_group = SimpleActionGroup::new();
|
|
||||||
action_group.add_action(action_page_open.as_ref());
|
|
||||||
|
|
||||||
// Init components
|
// Init components
|
||||||
let content = Arc::new(Content::new(action_page_open.clone()));
|
let content = Arc::new(Content::new(action_page_open.clone()));
|
||||||
let navigation = Arc::new(Navigation::new(
|
let navigation = Arc::new(Navigation::new(
|
||||||
@ -65,17 +63,12 @@ impl Page {
|
|||||||
action_tab_page_navigation_reload.clone(),
|
action_tab_page_navigation_reload.clone(),
|
||||||
action_update.clone(),
|
action_update.clone(),
|
||||||
));
|
));
|
||||||
|
let widget = Widget::new_arc(
|
||||||
// Init widget
|
action_page_open.clone(),
|
||||||
let gobject = Box::builder()
|
&name, // ID
|
||||||
.orientation(Orientation::Vertical)
|
navigation.gobject(),
|
||||||
.name(name)
|
content.gobject(),
|
||||||
.build();
|
);
|
||||||
|
|
||||||
gobject.append(navigation.widget());
|
|
||||||
gobject.append(content.widget());
|
|
||||||
|
|
||||||
gobject.insert_action_group("page", Some(&action_group));
|
|
||||||
|
|
||||||
// Init async mutable Meta object
|
// Init async mutable Meta object
|
||||||
let meta = Arc::new(RefCell::new(Meta::new()));
|
let meta = Arc::new(RefCell::new(Meta::new()));
|
||||||
@ -103,8 +96,6 @@ impl Page {
|
|||||||
|
|
||||||
// Return activated structure
|
// Return activated structure
|
||||||
Arc::new(Self {
|
Arc::new(Self {
|
||||||
// GTK
|
|
||||||
gobject,
|
|
||||||
// Actions
|
// Actions
|
||||||
action_page_open,
|
action_page_open,
|
||||||
action_tab_page_navigation_reload,
|
action_tab_page_navigation_reload,
|
||||||
@ -114,6 +105,8 @@ impl Page {
|
|||||||
navigation,
|
navigation,
|
||||||
// Extras
|
// Extras
|
||||||
meta,
|
meta,
|
||||||
|
// GTK
|
||||||
|
widget,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -484,6 +477,6 @@ impl Page {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn gobject(&self) -> &Box {
|
pub fn gobject(&self) -> &Box {
|
||||||
&self.gobject
|
&self.widget.gobject()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ impl Content {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn widget(&self) -> &Box {
|
pub fn gobject(&self) -> &Box {
|
||||||
&self.widget
|
&self.widget
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ impl Navigation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn widget(&self) -> &Box {
|
pub fn gobject(&self) -> &Box {
|
||||||
&self.widget
|
&self.widget
|
||||||
}
|
}
|
||||||
|
|
||||||
|
45
src/app/browser/window/tab/item/page/widget.rs
Normal file
45
src/app/browser/window/tab/item/page/widget.rs
Normal file
@ -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<SimpleAction>,
|
||||||
|
// Options
|
||||||
|
name: &str,
|
||||||
|
// Components
|
||||||
|
navigation: &Box,
|
||||||
|
content: &Box,
|
||||||
|
) -> Arc<Self> {
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user