0

I have a filechoosernative and a comboboxtext in my UI. Now I am trying to extract data from those two inside callbacks but they are returning me None even though they clearly have data set by the user. Why is this happening?

Excerpt from https://gitlab.com/9898287/nixwriter/-/blob/rir/src/frontend/mod.rs#L41

    fn get_selected_file(&self) -> Option<std::path::PathBuf> {
        let selected_file = self.fcn.get_filename();
        dbg!(&selected_file);
        selected_file
    }

Excerpt from https://gitlab.com/9898287/nixwriter/-/blob/rir/src/frontend/mod.rs#L35

    fn get_selected_device(&self) -> Option<udisks::DiskDevice> {
        // Combo box text only stores a Gstring (Device ID)
        // Search through the list of devices from udisks2 again
        // and find the device with matching device ID

        let selected_device = match self.lsblk_cbt.get_active_text() {
            Some(txt) => {
                dbg!(&txt);
                for disk in crate::aux::backend::get_disks() {
                    if disk.drive.id == txt {
                        return Some(disk);
                    }
                }
                dbg!("No matching device found. Must reload.");
                None
            }
            None => {
                dbg!("lsblk_cbt is returning nothing");
                None
            }
        };
        dbg!(&selected_device);
        selected_device
    }

Both return None in https://gitlab.com/9898287/nixwriter/-/blob/rir/src/frontend/mod.rs#L110

    fn set_lsblk_cbt(&mut self) {
        let cbt = self.lsblk_cbt.clone();
        for ddev in crate::aux::backend::get_disks() {
            cbt.append_text(&ddev.drive.id);
        }
        let (device_chosen, file_chosen) = (
            self.get_selected_device().is_some(),
            self.get_selected_file().is_some(),
        );
        let start = self.start.clone();
        cbt.connect_changed(move |_| {
            start.set_sensitive(device_chosen && file_chosen);
            dbg!("From set_lsblk_cbt", device_chosen, file_chosen);
        });
    }

even after the user has set a file and selected an item from ComboboxText.

noconst
  • 639
  • 4
  • 15
  • Does `self.lsblk_cbt.get_active_text()` return the correct string? Do you get any of the debug outputs printed? I.e. can you add the debug outputs to the question? – Jonas Berlin Jul 21 '20 at 10:27
  • All of those would return `None`. I fixed it by calling the methods inside the closures. – noconst Jul 21 '20 at 13:16

0 Answers0