|
| 1 | +use crate::workbench; |
| 2 | +use gtk::gio; |
| 3 | +use gtk::prelude::*; |
| 4 | + |
| 5 | +pub fn main() { |
| 6 | + let demo: adw::StatusPage = workbench::builder().object("demo").unwrap(); |
| 7 | + let demo_group = gio::SimpleActionGroup::new(); |
| 8 | + demo.insert_action_group("demo", Some(&demo_group)); |
| 9 | + |
| 10 | + // Action with no state or parameters |
| 11 | + let simple_action = gio::SimpleAction::new("simple", None); |
| 12 | + |
| 13 | + simple_action.connect_activate(|action, _| { |
| 14 | + println!("{} action activated", action.name()); |
| 15 | + }); |
| 16 | + demo_group.add_action(&simple_action); |
| 17 | + |
| 18 | + // Action with parameter |
| 19 | + let bookmarks_action = |
| 20 | + gio::SimpleAction::new("open-bookmarks", Some(&str::static_variant_type())); |
| 21 | + bookmarks_action.connect_activate(|action, parameter| { |
| 22 | + println!("{} activated with {}", action.name(), parameter.unwrap()); |
| 23 | + }); |
| 24 | + demo_group.add_action(&bookmarks_action); |
| 25 | + |
| 26 | + // Action with state |
| 27 | + let toggle_action = gio::SimpleAction::new_stateful("toggle", None, &false.to_variant()); |
| 28 | + toggle_action.connect_notify(Some("state"), |action, _| { |
| 29 | + println!("{} set to {}", action.name(), action.state().unwrap()); |
| 30 | + }); |
| 31 | + demo_group.add_action(&toggle_action); |
| 32 | + |
| 33 | + // Action with state and parameter |
| 34 | + let scale_action = gio::SimpleAction::new_stateful( |
| 35 | + "scale", |
| 36 | + Some(&str::static_variant_type()), |
| 37 | + &"100%".to_variant(), |
| 38 | + ); |
| 39 | + scale_action.connect_notify(Some("state"), |action, _| { |
| 40 | + println!("{} set to {}", action.name(), action.state().unwrap()); |
| 41 | + }); |
| 42 | + demo_group.add_action(&scale_action); |
| 43 | + |
| 44 | + // Property action |
| 45 | + let text: gtk::Label = workbench::builder().object("text").unwrap(); |
| 46 | + let alignment_action = gio::PropertyAction::new("text-align", &text, "halign"); |
| 47 | + demo_group.add_action(&alignment_action); |
| 48 | +} |
0 commit comments