add few macros

parent 7292a05e
#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
#[macro_export]
macro_rules! get_widget {
($builder:expr, $wtype:ty, $name:ident) => {
let $name: $wtype = $builder.get_object(stringify!($name)).expect(&format!("Could not find widget \"{}\"", stringify!($name)));
};
}
#[macro_export]
macro_rules! spawn {
($future:expr) => {
let ctx = glib::MainContext::default();
ctx.spawn_local($future);
};
}
#[macro_export]
macro_rules! send {
($sender:expr, $action:expr) => {
if let Err(err) = $sender.send($action) {
error!("Failed to send \"{}\" action due to {}", stringify!($action), err);
}
};
}
#[macro_export]
macro_rules! action {
($actions_group:expr, $name:expr, $callback:expr) => {
let simple_action = gio::SimpleAction::new($name, None);
simple_action.connect_activate($callback);
$actions_group.add_action(&simple_action);
};
}
#[macro_export]
macro_rules! stateful_action {
($actions_group:expr, $name:expr, $value:expr, $callback:expr) => {
let simple_action = gio::SimpleAction::new_stateful($name, None, &$value.to_variant());
simple_action.connect_activate($callback);
$actions_group.add_action(&simple_action);
};
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment