examples: update video player to use install_action
@@ -52,20 +52,32 @@ mod imp {
fn class_init(klass: &mut Self::Class) {
Self::bind_template(klass);
+ klass.install_action(
+ "win.open",
+ None,
+ move |win, _action_name, _action_target| {
+ let self_ = imp::VideoPlayerWindow::from_instance(&win);
+ self_.dialog.set_transient_for(Some(win));
+ self_
+ .dialog
+ .connect_response(clone!(@weak win => move |d, response| {
+ if response == gtk::ResponseType::Accept {
+ win.set_video(d.get_file().unwrap());
}
+ d.destroy();
+ }));
- fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
- obj.init_template();
- }
+ self_.dialog.show();
+ },
+ );
}
- impl ObjectImpl for VideoPlayerWindow {
- fn constructed(&self, obj: &Self::Type) {
- obj.init_actions();
- self.parent_constructed(obj);
+ fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
+ obj.init_template();
}
}
+ impl ObjectImpl for VideoPlayerWindow {}
impl WidgetImpl for VideoPlayerWindow {}
impl WindowImpl for VideoPlayerWindow {}
impl ApplicationWindowImpl for VideoPlayerWindow {}
@@ -81,24 +93,6 @@ impl VideoPlayerWindow {
glib::Object::new(&[("application", app)]).expect("Failed to create VideoPlayerWindow")
}
- fn init_actions(&self) {
- let open = gio::SimpleAction::new("open", None);
-
- open.connect_activate(clone!(@weak self as win => move |_, _| {
- let self_ = imp::VideoPlayerWindow::from_instance(&win);
- self_.dialog.set_transient_for(Some(&win));
- self_.dialog.connect_response(clone!(@weak win => move |d, response| {
- if response == gtk::ResponseType::Accept {
- win.set_video(d.get_file().unwrap());
- }
- d.destroy();
- }));
-
- self_.dialog.show();
- }));
- self.add_action(&open);
- }
-
fn set_video(&self, video: gio::File) {
let self_ = imp::VideoPlayerWindow::from_instance(self);
self_.video.get().set_file(Some(&video));
