0

我的 UI 中有一个文件选择器和一个组合框文本。现在我正在尝试从这两个内部回调中提取数据,但是即使它们清楚地具有用户设置的数据,它们也返回给我 None 。为什么会这样?

摘自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
    }

摘自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
    }

两者都在https://gitlab.com/9898287/nixwriter/-/blob/rir/src/frontend/mod.rs#L110中返回 None

    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);
        });
    }

即使在用户设置了文件并从 ComboboxText 中选择了一个项目之后。

4

0 回答 0