mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-02-05 16:04:15 +00:00
delegate action registration to widget
This commit is contained in:
parent
532ed65ed8
commit
157227cbfe
@ -9,7 +9,7 @@ use window::Window;
|
||||
use adw::ApplicationWindow;
|
||||
use gtk::{
|
||||
gio::{Cancellable, File, SimpleAction},
|
||||
prelude::{ActionMapExt, GtkWindowExt},
|
||||
prelude::GtkWindowExt,
|
||||
FileLauncher,
|
||||
};
|
||||
use sqlite::Transaction;
|
||||
@ -57,21 +57,23 @@ impl Browser {
|
||||
));
|
||||
|
||||
// Init widget
|
||||
let widget = Arc::new(Widget::new(window.gobject()));
|
||||
|
||||
// Assign actions
|
||||
widget.gobject().add_action(&action_debug);
|
||||
widget.gobject().add_action(&action_profile);
|
||||
widget.gobject().add_action(&action_quit);
|
||||
widget.gobject().add_action(&action_update);
|
||||
widget.gobject().add_action(&action_page_new);
|
||||
widget.gobject().add_action(&action_page_close);
|
||||
widget.gobject().add_action(&action_page_close_all);
|
||||
widget.gobject().add_action(&action_page_home);
|
||||
widget.gobject().add_action(&action_page_history_back);
|
||||
widget.gobject().add_action(&action_page_history_forward);
|
||||
widget.gobject().add_action(&action_page_reload);
|
||||
widget.gobject().add_action(&action_page_pin);
|
||||
let widget = Arc::new(Widget::new(
|
||||
window.gobject(),
|
||||
&[
|
||||
action_debug.clone(),
|
||||
action_profile.clone(),
|
||||
action_quit.clone(),
|
||||
action_update.clone(),
|
||||
action_page_new.clone(),
|
||||
action_page_close.clone(),
|
||||
action_page_close_all.clone(),
|
||||
action_page_home.clone(),
|
||||
action_page_history_back.clone(),
|
||||
action_page_history_forward.clone(),
|
||||
action_page_reload.clone(),
|
||||
action_page_pin.clone(),
|
||||
],
|
||||
));
|
||||
|
||||
// Init events
|
||||
action_debug.connect_activate({
|
||||
|
@ -3,7 +3,10 @@ mod database;
|
||||
use database::Database;
|
||||
|
||||
use adw::ApplicationWindow;
|
||||
use gtk::{prelude::GtkWindowExt, Box};
|
||||
use gtk::{
|
||||
gio::SimpleAction,
|
||||
prelude::{ActionMapExt, GtkWindowExt, IsA},
|
||||
};
|
||||
use sqlite::Transaction;
|
||||
|
||||
// Default options
|
||||
@ -17,7 +20,7 @@ pub struct Widget {
|
||||
|
||||
impl Widget {
|
||||
// Construct
|
||||
pub fn new(content: &Box) -> Self {
|
||||
pub fn new(content: &impl IsA<gtk::Widget>, actions: &[SimpleAction]) -> Self {
|
||||
// Init GTK
|
||||
let gobject = ApplicationWindow::builder()
|
||||
.content(content)
|
||||
@ -26,6 +29,11 @@ impl Widget {
|
||||
.maximized(MAXIMIZED)
|
||||
.build();
|
||||
|
||||
// Register actions
|
||||
for action in actions {
|
||||
gobject.add_action(action);
|
||||
}
|
||||
|
||||
// Return new struct
|
||||
Self { gobject }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user