ferroui_xaml_interactions/core/
invoke_command_action.rs1use ferroui_base::{ferro_class, ferro_class_info, instantiate, BoxedValue, FerroObjectImpl, Ref, StyledElementImpl};
4use ferroui_xaml_interactivity::{InvokeCommandActionBase, StyledElementActionImpl};
5use std::rc::Rc;
6
7#[repr(C)]
9pub struct InvokeCommandAction {
10 base: InvokeCommandActionBase,
11}
12
13ferro_class!(InvokeCommandAction: InvokeCommandActionBase);
14ferro_class_info!(InvokeCommandAction { new: InvokeCommandAction::new });
15ferroui_base::ferro_impl_classes!(InvokeCommandAction: FerroObjectImpl, StyledElementImpl);
16
17impl StyledElementActionImpl for InvokeCommandAction {
18 fn execute(this: &Self, _sender: Option<&BoxedValue>, parameter: Option<&BoxedValue>) -> Option<BoxedValue> {
26 let command = this.command();
27 let Some(command) = command.filter(|_| this.is_enabled()) else {
28 return Some(Rc::new(false));
29 };
30
31 let resolved_parameter = this.resolve_parameter(parameter);
32
33 if !command.can_execute(resolved_parameter.as_ref()) {
34 return Some(Rc::new(false));
35 }
36
37 command.execute(resolved_parameter.as_ref());
38
39 Some(Rc::new(true))
40 }
41}
42
43impl InvokeCommandAction {
44 pub fn construct() -> Self {
46 Self { base: InvokeCommandActionBase::construct() }
47 }
48
49 pub fn new() -> Ref<Self> {
51 instantiate(Self::construct())
52 }
53}