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 adw::ApplicationWindow;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::{Cancellable, File, SimpleAction},
|
gio::{Cancellable, File, SimpleAction},
|
||||||
prelude::{ActionMapExt, GtkWindowExt},
|
prelude::GtkWindowExt,
|
||||||
FileLauncher,
|
FileLauncher,
|
||||||
};
|
};
|
||||||
use sqlite::Transaction;
|
use sqlite::Transaction;
|
||||||
@ -57,21 +57,23 @@ impl Browser {
|
|||||||
));
|
));
|
||||||
|
|
||||||
// Init widget
|
// Init widget
|
||||||
let widget = Arc::new(Widget::new(window.gobject()));
|
let widget = Arc::new(Widget::new(
|
||||||
|
window.gobject(),
|
||||||
// Assign actions
|
&[
|
||||||
widget.gobject().add_action(&action_debug);
|
action_debug.clone(),
|
||||||
widget.gobject().add_action(&action_profile);
|
action_profile.clone(),
|
||||||
widget.gobject().add_action(&action_quit);
|
action_quit.clone(),
|
||||||
widget.gobject().add_action(&action_update);
|
action_update.clone(),
|
||||||
widget.gobject().add_action(&action_page_new);
|
action_page_new.clone(),
|
||||||
widget.gobject().add_action(&action_page_close);
|
action_page_close.clone(),
|
||||||
widget.gobject().add_action(&action_page_close_all);
|
action_page_close_all.clone(),
|
||||||
widget.gobject().add_action(&action_page_home);
|
action_page_home.clone(),
|
||||||
widget.gobject().add_action(&action_page_history_back);
|
action_page_history_back.clone(),
|
||||||
widget.gobject().add_action(&action_page_history_forward);
|
action_page_history_forward.clone(),
|
||||||
widget.gobject().add_action(&action_page_reload);
|
action_page_reload.clone(),
|
||||||
widget.gobject().add_action(&action_page_pin);
|
action_page_pin.clone(),
|
||||||
|
],
|
||||||
|
));
|
||||||
|
|
||||||
// Init events
|
// Init events
|
||||||
action_debug.connect_activate({
|
action_debug.connect_activate({
|
||||||
|
@ -3,7 +3,10 @@ mod database;
|
|||||||
use database::Database;
|
use database::Database;
|
||||||
|
|
||||||
use adw::ApplicationWindow;
|
use adw::ApplicationWindow;
|
||||||
use gtk::{prelude::GtkWindowExt, Box};
|
use gtk::{
|
||||||
|
gio::SimpleAction,
|
||||||
|
prelude::{ActionMapExt, GtkWindowExt, IsA},
|
||||||
|
};
|
||||||
use sqlite::Transaction;
|
use sqlite::Transaction;
|
||||||
|
|
||||||
// Default options
|
// Default options
|
||||||
@ -17,7 +20,7 @@ pub struct Widget {
|
|||||||
|
|
||||||
impl Widget {
|
impl Widget {
|
||||||
// Construct
|
// Construct
|
||||||
pub fn new(content: &Box) -> Self {
|
pub fn new(content: &impl IsA<gtk::Widget>, actions: &[SimpleAction]) -> Self {
|
||||||
// Init GTK
|
// Init GTK
|
||||||
let gobject = ApplicationWindow::builder()
|
let gobject = ApplicationWindow::builder()
|
||||||
.content(content)
|
.content(content)
|
||||||
@ -26,6 +29,11 @@ impl Widget {
|
|||||||
.maximized(MAXIMIZED)
|
.maximized(MAXIMIZED)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
// Register actions
|
||||||
|
for action in actions {
|
||||||
|
gobject.add_action(action);
|
||||||
|
}
|
||||||
|
|
||||||
// Return new struct
|
// Return new struct
|
||||||
Self { gobject }
|
Self { gobject }
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user