如何将操作按钮添加到FileChooserDialog?

时间:2018-01-04 09:56:56

标签: rust gtk-rs

当我尝试显示文件选择器对话框时,它缺少操作按钮:

let dialog = FileChooserDialog::new(Some("Open File"), Some(&window), FileChooserAction::Open);
dialog.run();

enter image description here

我从另一个项目中找到了另一种方式:

let dialog = FileChooserDialog::new_with_buttons::<ApplicationWindow>(
    Some("Open File"),
    Some(&window),
    FileChooserAction::Open,
    &[
        ("_Cancel", ResponseType::Cancel),
        ("_Open", ResponseType::Accept),
    ],
);

错误消息是:

no function or associated item named `new_with_buttons` found for type `gtk::FileChooserDialog` in the current scope

1 个答案:

答案 0 :(得分:0)

我想您需要在创建对话框之后和显示之前使用add_button添加按钮:

let dialog = FileChooserDialog::new(Some("Open File"), Some(&window), FileChooserAction::Open);
dialog.add_button("_Cancel", ResponseType::Cancel);
dialog.add_button("_Open", ResponseType::Accept);
dialog.run();