mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 09:35:28 +00:00
connect actions directly, use trait implementation for navigation buttons
This commit is contained in:
parent
10c73f4e3d
commit
5145a53bfa
9 changed files with 87 additions and 266 deletions
|
|
@ -1,41 +1,21 @@
|
|||
use super::WindowAction;
|
||||
use gtk::{
|
||||
prelude::{ButtonExt, WidgetExt},
|
||||
Button,
|
||||
};
|
||||
use gtk::{prelude::ActionExt, Button};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Home {
|
||||
action: Rc<WindowAction>,
|
||||
pub button: Button,
|
||||
pub trait Home {
|
||||
fn home(action: &Rc<WindowAction>) -> Self;
|
||||
}
|
||||
|
||||
impl Home {
|
||||
// Construct
|
||||
pub fn build(action: &Rc<WindowAction>) -> Self {
|
||||
// Init gobject
|
||||
let button = Button::builder()
|
||||
impl Home for Button {
|
||||
fn home(action: &Rc<WindowAction>) -> Self {
|
||||
Button::builder()
|
||||
.action_name(format!(
|
||||
"{}.{}",
|
||||
action.id,
|
||||
action.home.simple_action.name()
|
||||
)) // @TODO
|
||||
.icon_name("go-home-symbolic")
|
||||
.tooltip_text("Home")
|
||||
.sensitive(false)
|
||||
.build();
|
||||
|
||||
// Init events
|
||||
button.connect_clicked({
|
||||
let action = action.clone();
|
||||
move |_| action.home.activate()
|
||||
});
|
||||
|
||||
// Return activated `Self`
|
||||
Self {
|
||||
action: action.clone(),
|
||||
button,
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
pub fn update(&self, has_home: bool) {
|
||||
self.action.home.simple_action.set_enabled(has_home);
|
||||
self.button.set_sensitive(has_home);
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue