relocate actions

This commit is contained in:
yggverse 2024-09-23 01:57:16 +03:00
parent 48541da91d
commit b5b4b359fa
3 changed files with 42 additions and 45 deletions

View File

@ -1,31 +0,0 @@
use gtk::gio::ActionEntry;
use gtk::prelude::GtkWindowExt;
use gtk::ApplicationWindow;
pub fn debug() -> ActionEntry<ApplicationWindow> {
ActionEntry::builder("debug")
.activate(|this: &ApplicationWindow, _, _| {
this.emit_enable_debugging(true);
})
.build()
}
pub fn quit() -> ActionEntry<ApplicationWindow> {
ActionEntry::builder("quit")
.activate(|this: &ApplicationWindow, _, _| {
this.close();
})
.build()
}
/* @TODO
pub fn tab_append(main) -> ActionEntry<ApplicationWindow> {
let action_tab_append = ActionEntry::builder("tab_append")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_append();
}
})
.build();
}*/

View File

@ -1,6 +1,8 @@
mod tab;
mod widget;
use std::sync::Arc;
pub struct Main {
widget: widget::Main,
tab: tab::Tab,
@ -8,15 +10,15 @@ pub struct Main {
impl Main {
// Construct
pub fn new() -> Main {
pub fn new() -> Arc<Main> {
// Init components
let tab = tab::Tab::new();
// Init struct
Self {
Arc::new(Self {
widget: widget::Main::new(tab.widget().gtk()), // @TODO
tab,
}
})
}
// Actions

View File

@ -1,13 +1,16 @@
mod action;
mod db;
mod header;
mod main;
mod widget;
use gtk::prelude::ActionMapExtManual;
use std::sync::Arc;
use gtk::prelude::{ActionMapExtManual, GtkWindowExt};
pub struct Browser {
db: db::Browser,
header: header::Header,
main: Arc<main::Main>,
widget: widget::Browser,
}
@ -15,27 +18,50 @@ impl Browser {
// Construct new browser
pub fn new(
app: &gtk::Application,
connection: std::sync::Arc<sqlite::Connection>,
connection: std::sync::Arc<sqlite::Connection>, // @TODO glib clone macro?
default_width: i32,
default_height: i32,
) -> Browser {
// Init widget
// Init components
let db = db::Browser::new(connection);
let header = header::Header::new();
let main = main::Main::new();
let widget = widget::Browser::new(
app,
header::Header::new().widget().gtk(),
main::Main::new().widget().gtk(),
header.widget().gtk(),
main.widget().gtk(),
default_width,
default_height,
);
// Connect actions
widget
.gtk()
.add_action_entries([action::debug(), action::quit()]);
// Init actions @TODO separated module
widget.gtk().add_action_entries([
gtk::gio::ActionEntry::builder("debug")
.activate(|this: &gtk::ApplicationWindow, _, _| {
this.emit_enable_debugging(true);
})
.build(),
gtk::gio::ActionEntry::builder("quit")
.activate(|this: &gtk::ApplicationWindow, _, _| {
this.close();
})
.build(),
gtk::gio::ActionEntry::builder("tab_append")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_append();
}
})
.build(),
]);
// Return
Self {
db: db::Browser::new(connection),
db,
header,
main,
widget,
}
}