FileChooserNative failure dialog doesn't seem to have a transient parent

I am getting a warning

Gtk-Message: 19:25:34.564: GtkDialog mapped without a transient parent. This is discouraged.

when a “The folder contents could not be displayed” dialog gets created.

I don’t think this is my fault, because I am setting the transient for the FileChooserNative.

  ...
  #[template_callback]
  fn button_clicked(&self, button : gtk::Button) {
    let root = {
      button.root()
        .expect("must have root")
        .dynamic_cast::<gtk::Window>()
        .expect("root must be a Window")
    };
    let dialog = {
      gtk::FileChooserNative::builder()
        .title("File Chooser")
        .transient_for(&root)
        .action(gtk::FileChooserAction::Open)
        .accept_label("_Open")
        .cancel_label("_Cancel")
        .modal(true)
        .build()
    };

    let cwd = gio::File::for_path(".");
    let _ = dialog.set_current_folder(Some(&cwd));
    dialog.show();
  }
  ...

Full code here:

Am I doing something wrong? How do I make the warning go away?

Hi, I hope this helps you. Try using a Gtk.FileDialog (this is the best to use since Gtk 4.10) instead and set its parent transient first preferably.

Here is its documentation:

I would if it were available to me, but I’m on Debian 12 / bookwork, where the gtk-4 version is 4.8.3.

Can you try removing the following line from your code please ? :

dynamic_cast::gtk::Window()

And is “&root” a gtk window ?

Removing the dynamic_cast causes the code to fail compilation, as .root() returns a Root, but set_transient expects a Window. However, the dynamic_cast is fine, because if the object returned by .root() is not convertible to a Window, the return value will be None, and cause the second expect to panic.

Once cast, root is a Window, as it does in fact return the ApplicationWindow which contains the button (I checked), and an ApplicationWindow is also a Window.

I think the issue is probably internal to GTK. As the way dialogs work has completely changed in the meanwhile, and it’s a very minor issue, I will just ignore it.

Ok, I see your reply. Good Luck with your project !

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.