January 2018
Beginner to intermediate
454 pages
10h 8m
English
We need to add a method to the Playlist struct to remove the selected item:
pub fn remove_selection(&self) { let selection = self.treeview.get_selection(); if let Some((_, iter)) = selection.get_selected() { self.model.remove(&iter); } }
This first starts by getting the selection and, if there was one, we remove it from the model. We can now add an event handler for the remove button in the App::connect_toolbar_events() method:
let playlist = self.playlist.clone(); self.toolbar.remove_button.connect_clicked(move |_| { playlist.remove_selection(); });
There's nothing new in this code; we simply clone the reference-counted playlist and call a method on it when the button is clicked.
Read now
Unlock full access