January 2018
Beginner to intermediate
454 pages
10h 8m
English
Let's update the open() method to communicate with the playlist:
impl App { fn open(&self) { let file = show_open_dialog(&self.window); if let Some(file) = file { let ext = file.extension().map(|ext| ext.to_str().unwrap().to_string()); if let Some(ext) = ext { match ext.as_str() { "mp3" => self.playlist.emit(AddSong(file)), "m3u" => self.playlist.emit(LoadSong(file)), extension => { let dialog = MessageDialog::new(Some(&self.window), DialogFlags::empty(), MessageType::Error, ButtonsType::Ok, &format!("Cannot open file with extension . {}", extension)); dialog.run(); dialog.destroy(); }, } } } } }
So, we call the same emit() method to send a message to another widget:
self.playlist.emit(AddSong(file))
Here, we sent ...