January 2018
Beginner to intermediate
454 pages
10h 8m
English
There's another function we'll need before we can handle the click event of the open button. We need a function that'll show a file dialog to allow the user to select a file:
use std::path::PathBuf; use gtk::{FileChooserAction, FileChooserDialog, FileFilter}; fn show_open_dialog(parent: &ApplicationWindow) -> Option<PathBuf> { let mut file = None; let dialog = FileChooserDialog::new(Some("Select an MP3 audio file"), Some(parent), FileChooserAction::Open); let filter = FileFilter::new(); filter.add_mime_type("audio/mp3"); filter.set_name("MP3 audio file"); dialog.add_filter(&filter); dialog.add_button("Cancel", RESPONSE_CANCEL); dialog.add_button("Accept", RESPONSE_ACCEPT); let result = dialog.run(); if result ...