So, I trying to add a new dialog and attach some actions to the dialog object, but it crashes the application with this error:
thread 'main' panicked at C:\Users\OSA413\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\glib-0.21.0\src\object.rs:122:23:
assertion failed: self.is::<T>()
This error is not very informative but my guess is that there should be another type used for such things (I mean to be able to attach actions to the window). Does AdwDialog support attaching actions? If not, how should I call custom logic from a dialog (or something seemingly as a dialog window)?
Here’s the code of the dialog for reference:
use adw::{prelude::AdwDialogExt, subclass::prelude::*};
use gtk::{gio::{self, prelude::ActionMapExtManual}, glib};
mod imp {
use super::*;
#[derive(Debug, Default, gtk::CompositeTemplate)]
#[template(resource = "/proj/proj/window_settings.ui")]
pub struct SettingsWindow {
}
#[glib::object_subclass]
impl ObjectSubclass for SettingsWindow {
const NAME: &'static str = "Settings";
type Type = super::SettingsWindow;
type ParentType = adw::Dialog;
fn class_init(klass: &mut Self::Class) {
klass.bind_template();
}
fn instance_init(obj: &glib::subclass::InitializingObject<Self>) {
obj.init_template();
}
}
impl ObjectImpl for SettingsWindow {
fn constructed(&self) {
self.parent_constructed();
self.obj().setup_actions();
}
}
impl WidgetImpl for SettingsWindow {}
impl AdwDialogImpl for SettingsWindow {}
}
glib::wrapper! {
pub struct SettingsWindow(ObjectSubclass<imp::SettingsWindow>)
@extends gtk::Widget, adw::Dialog,
@implements
gio::ActionGroup,
gio::ActionMap,
gtk::ConstraintTarget,
gtk::Buildable,
gtk::Accessible,
gtk::ShortcutManager,
gtk::Root,
gtk::Native;
}
impl SettingsWindow {
pub fn new() -> Self {
glib::Object::builder().build()
}
fn setup_actions(&self) {
let close_action = gio::ActionEntry::builder("close")
.activate(move |app: &Self, _, _| {app.close();})
.build();
self.add_action_entries([
close_action
]); //It crashes here
}
}