mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-03-10 20:51:45 +00:00
use libadwaita for app & app window
This commit is contained in:
parent
e2ab831d57
commit
9e5a2a490c
@ -6,10 +6,10 @@ use action::Action;
|
|||||||
use browser::Browser;
|
use browser::Browser;
|
||||||
use database::Database;
|
use database::Database;
|
||||||
|
|
||||||
|
use adw::Application;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
glib::ExitCode,
|
glib::ExitCode,
|
||||||
prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt},
|
prelude::{ActionExt, ApplicationExt, ApplicationExtManual, GtkApplicationExt, GtkWindowExt},
|
||||||
Application,
|
|
||||||
};
|
};
|
||||||
use sqlite::{Connection, Transaction};
|
use sqlite::{Connection, Transaction};
|
||||||
|
|
||||||
|
@ -1,18 +1,15 @@
|
|||||||
mod database;
|
mod database;
|
||||||
mod header;
|
|
||||||
mod widget;
|
mod widget;
|
||||||
mod window;
|
mod window;
|
||||||
|
|
||||||
use database::Database;
|
use database::Database;
|
||||||
use header::Header;
|
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
use window::Window;
|
use window::Window;
|
||||||
|
|
||||||
|
use adw::ApplicationWindow;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::{AppInfo, AppLaunchContext, SimpleAction},
|
gio::{AppInfo, AppLaunchContext, SimpleAction},
|
||||||
glib::GString,
|
|
||||||
prelude::{ActionMapExt, GtkWindowExt},
|
prelude::{ActionMapExt, GtkWindowExt},
|
||||||
ApplicationWindow,
|
|
||||||
};
|
};
|
||||||
use sqlite::Transaction;
|
use sqlite::Transaction;
|
||||||
use std::{path::PathBuf, sync::Arc};
|
use std::{path::PathBuf, sync::Arc};
|
||||||
@ -43,11 +40,11 @@ impl Browser {
|
|||||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||||
action_tab_pin: Arc<SimpleAction>,
|
action_tab_pin: Arc<SimpleAction>,
|
||||||
) -> Browser {
|
) -> Browser {
|
||||||
// Init components
|
let window = Arc::new(Window::new(
|
||||||
let header = Arc::new(Header::new(
|
|
||||||
action_tool_debug.clone(),
|
action_tool_debug.clone(),
|
||||||
action_tool_profile_directory.clone(),
|
action_tool_profile_directory.clone(),
|
||||||
action_quit.clone(),
|
action_quit.clone(),
|
||||||
|
action_update.clone(),
|
||||||
action_tab_append.clone(),
|
action_tab_append.clone(),
|
||||||
action_tab_close.clone(),
|
action_tab_close.clone(),
|
||||||
action_tab_close_all.clone(),
|
action_tab_close_all.clone(),
|
||||||
@ -58,16 +55,10 @@ impl Browser {
|
|||||||
action_tab_pin.clone(),
|
action_tab_pin.clone(),
|
||||||
));
|
));
|
||||||
|
|
||||||
let window = Arc::new(Window::new(
|
//window.gobject().append(header.gobject());
|
||||||
action_tab_page_navigation_base.clone(),
|
|
||||||
action_tab_page_navigation_history_back.clone(),
|
|
||||||
action_tab_page_navigation_history_forward.clone(),
|
|
||||||
action_tab_page_navigation_reload.clone(),
|
|
||||||
action_update.clone(),
|
|
||||||
));
|
|
||||||
|
|
||||||
// Init widget
|
// Init widget
|
||||||
let widget = Arc::new(Widget::new(header.gobject(), window.gobject()));
|
let widget = Arc::new(Widget::new(window.gobject()));
|
||||||
|
|
||||||
// Assign actions
|
// Assign actions
|
||||||
widget.gobject().add_action(action_tool_debug.as_ref());
|
widget.gobject().add_action(action_tool_debug.as_ref());
|
||||||
@ -119,24 +110,9 @@ impl Browser {
|
|||||||
});
|
});
|
||||||
|
|
||||||
action_update.connect_activate({
|
action_update.connect_activate({
|
||||||
let header = header.clone();
|
|
||||||
let window = window.clone();
|
let window = window.clone();
|
||||||
move |_, _| {
|
move |_, _| {
|
||||||
// Update window first
|
|
||||||
window.update();
|
window.update();
|
||||||
|
|
||||||
// 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(title.as_str(), subtitle.as_str());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@ mod database;
|
|||||||
|
|
||||||
use database::Database;
|
use database::Database;
|
||||||
|
|
||||||
use adw::HeaderBar;
|
use adw::ApplicationWindow;
|
||||||
use gtk::{prelude::GtkWindowExt, ApplicationWindow, Box};
|
use gtk::{prelude::GtkWindowExt, Box};
|
||||||
use sqlite::Transaction;
|
use sqlite::Transaction;
|
||||||
|
|
||||||
// Default options
|
// Default options
|
||||||
@ -17,11 +17,10 @@ pub struct Widget {
|
|||||||
|
|
||||||
impl Widget {
|
impl Widget {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(titlebar: &HeaderBar, child: &Box) -> Self {
|
pub fn new(content: &Box) -> Self {
|
||||||
// Init GTK
|
// Init GTK
|
||||||
let gobject = ApplicationWindow::builder()
|
let gobject = ApplicationWindow::builder()
|
||||||
.titlebar(titlebar)
|
.content(content)
|
||||||
.child(child)
|
|
||||||
.default_height(DEFAULT_HEIGHT)
|
.default_height(DEFAULT_HEIGHT)
|
||||||
.default_width(DEFAULT_WIDTH)
|
.default_width(DEFAULT_WIDTH)
|
||||||
.maximized(MAXIMIZED)
|
.maximized(MAXIMIZED)
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
mod database;
|
mod database;
|
||||||
|
mod header;
|
||||||
mod tab;
|
mod tab;
|
||||||
mod widget;
|
mod widget;
|
||||||
|
|
||||||
use database::Database;
|
use database::Database;
|
||||||
|
use header::Header;
|
||||||
use sqlite::Transaction;
|
use sqlite::Transaction;
|
||||||
use tab::Tab;
|
use tab::Tab;
|
||||||
use widget::Widget;
|
use widget::Widget;
|
||||||
@ -12,6 +14,7 @@ use std::sync::Arc;
|
|||||||
use gtk::{gio::SimpleAction, glib::GString, Box};
|
use gtk::{gio::SimpleAction, glib::GString, Box};
|
||||||
|
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
|
header: Arc<Header>,
|
||||||
tab: Arc<Tab>,
|
tab: Arc<Tab>,
|
||||||
widget: Arc<Widget>,
|
widget: Arc<Widget>,
|
||||||
}
|
}
|
||||||
@ -20,13 +23,34 @@ impl Window {
|
|||||||
// Construct
|
// Construct
|
||||||
pub fn new(
|
pub fn new(
|
||||||
// Actions
|
// Actions
|
||||||
|
action_tool_debug: Arc<SimpleAction>,
|
||||||
|
action_tool_profile_directory: Arc<SimpleAction>,
|
||||||
|
action_quit: Arc<SimpleAction>,
|
||||||
|
action_update: Arc<SimpleAction>,
|
||||||
|
action_tab_append: Arc<SimpleAction>,
|
||||||
|
action_tab_close: Arc<SimpleAction>,
|
||||||
|
action_tab_close_all: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_base: Arc<SimpleAction>,
|
action_tab_page_navigation_base: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
action_tab_page_navigation_history_back: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
action_tab_page_navigation_history_forward: Arc<SimpleAction>,
|
||||||
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
action_tab_page_navigation_reload: Arc<SimpleAction>,
|
||||||
action_update: Arc<SimpleAction>,
|
action_tab_pin: Arc<SimpleAction>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
// Init components
|
// Init components
|
||||||
|
let header = Arc::new(Header::new(
|
||||||
|
action_tool_debug.clone(),
|
||||||
|
action_tool_profile_directory.clone(),
|
||||||
|
action_quit.clone(),
|
||||||
|
action_tab_append.clone(),
|
||||||
|
action_tab_close.clone(),
|
||||||
|
action_tab_close_all.clone(),
|
||||||
|
action_tab_page_navigation_base.clone(),
|
||||||
|
action_tab_page_navigation_history_back.clone(),
|
||||||
|
action_tab_page_navigation_history_forward.clone(),
|
||||||
|
action_tab_page_navigation_reload.clone(),
|
||||||
|
action_tab_pin.clone(),
|
||||||
|
));
|
||||||
|
|
||||||
let tab = Arc::new(Tab::new(
|
let tab = Arc::new(Tab::new(
|
||||||
action_tab_page_navigation_base,
|
action_tab_page_navigation_base,
|
||||||
action_tab_page_navigation_history_back,
|
action_tab_page_navigation_history_back,
|
||||||
@ -37,10 +61,14 @@ impl Window {
|
|||||||
tab.activate(tab.clone());
|
tab.activate(tab.clone());
|
||||||
|
|
||||||
// GTK
|
// GTK
|
||||||
let widget = Arc::new(Widget::new(tab.gobject()));
|
let widget = Arc::new(Widget::new(header.gobject(), tab.gobject()));
|
||||||
|
|
||||||
// Init struct
|
// Init struct
|
||||||
Self { tab, widget }
|
Self {
|
||||||
|
header,
|
||||||
|
tab,
|
||||||
|
widget,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
@ -77,6 +105,19 @@ impl Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(&self) {
|
pub fn update(&self) {
|
||||||
|
// Update header
|
||||||
|
let title = match self.tab.page_title() {
|
||||||
|
Some(value) => value,
|
||||||
|
None => GString::new(), // @TODO
|
||||||
|
};
|
||||||
|
|
||||||
|
let subtitle = match self.tab.page_description() {
|
||||||
|
Some(value) => value,
|
||||||
|
None => GString::new(), // @TODO
|
||||||
|
};
|
||||||
|
|
||||||
|
self.header.update(title.as_str(), subtitle.as_str());
|
||||||
|
|
||||||
self.tab.update();
|
self.tab.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,14 +172,6 @@ impl Window {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
pub fn tab_page_title(&self) -> Option<GString> {
|
|
||||||
self.tab.page_title()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn tab_page_description(&self) -> Option<GString> {
|
|
||||||
self.tab.page_description()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn gobject(&self) -> &Box {
|
pub fn gobject(&self) -> &Box {
|
||||||
&self.widget.gobject()
|
&self.widget.gobject()
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use adw::HeaderBar;
|
||||||
use gtk::{prelude::BoxExt, Box, Notebook, Orientation};
|
use gtk::{prelude::BoxExt, Box, Notebook, Orientation};
|
||||||
|
|
||||||
pub struct Widget {
|
pub struct Widget {
|
||||||
@ -6,8 +7,9 @@ pub struct Widget {
|
|||||||
|
|
||||||
impl Widget {
|
impl Widget {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(tab: &Notebook) -> Self {
|
pub fn new(header: &HeaderBar, tab: &Notebook) -> Self {
|
||||||
let gobject = Box::builder().orientation(Orientation::Vertical).build();
|
let gobject = Box::builder().orientation(Orientation::Vertical).build();
|
||||||
|
gobject.append(header);
|
||||||
gobject.append(tab);
|
gobject.append(tab);
|
||||||
|
|
||||||
Self { gobject }
|
Self { gobject }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user