Hook up track set editor

This commit is contained in:
Elias Projahn 2021-01-13 19:56:27 +01:00
parent dbae0ad81b
commit 035142d193
2 changed files with 59 additions and 4 deletions

View file

@ -1,11 +1,12 @@
use super::disc_source::DiscSource; use super::disc_source::DiscSource;
use super::track_set_editor::TrackSetEditor; use super::track_set_editor::{TrackSetData, TrackSetEditor};
use crate::backend::Backend; use crate::backend::Backend;
use crate::widgets::{Navigator, NavigatorScreen}; use crate::widgets::{Navigator, NavigatorScreen};
use crate::widgets::new_list::List; use crate::widgets::new_list::List;
use glib::clone; use glib::clone;
use gtk::prelude::*; use gtk::prelude::*;
use gtk_macros::get_widget; use gtk_macros::get_widget;
use libhandy::prelude::*;
use std::cell::RefCell; use std::cell::RefCell;
use std::rc::Rc; use std::rc::Rc;
@ -14,6 +15,8 @@ pub struct MediumEditor {
backend: Rc<Backend>, backend: Rc<Backend>,
source: Rc<DiscSource>, source: Rc<DiscSource>,
widget: gtk::Box, widget: gtk::Box,
track_set_list: List,
track_sets: RefCell<Vec<TrackSetData>>,
navigator: RefCell<Option<Rc<Navigator>>>, navigator: RefCell<Option<Rc<Navigator>>>,
} }
@ -36,6 +39,8 @@ impl MediumEditor {
backend, backend,
source: Rc::new(source), source: Rc::new(source),
widget, widget,
track_set_list: list,
track_sets: RefCell::new(Vec::new()),
navigator: RefCell::new(None), navigator: RefCell::new(None),
}); });
@ -52,10 +57,48 @@ impl MediumEditor {
let navigator = this.navigator.borrow().clone(); let navigator = this.navigator.borrow().clone();
if let Some(navigator) = navigator { if let Some(navigator) = navigator {
let editor = TrackSetEditor::new(this.backend.clone(), Rc::clone(&this.source)); let editor = TrackSetEditor::new(this.backend.clone(), Rc::clone(&this.source));
editor.set_done_cb(clone!(@strong this => move |track_set| {
let length = {
let mut track_sets = this.track_sets.borrow_mut();
track_sets.push(track_set);
track_sets.len()
};
this.track_set_list.update(length);
}));
navigator.push(editor); navigator.push(editor);
} }
})); }));
this.track_set_list.set_make_widget(clone!(@strong this => move |index| {
let track_set = &this.track_sets.borrow()[index];
let title = track_set.recording.work.get_title();
let subtitle = track_set.recording.get_performers();
let edit_image = gtk::Image::from_icon_name(Some("document-edit-symbolic"), gtk::IconSize::Button);
let edit_button = gtk::Button::new();
edit_button.set_relief(gtk::ReliefStyle::None);
edit_button.set_valign(gtk::Align::Center);
edit_button.add(&edit_image);
let row = libhandy::ActionRow::new();
row.set_activatable(true);
row.set_title(Some(&title));
row.set_subtitle(Some(&subtitle));
row.add(&edit_button);
row.set_activatable_widget(Some(&edit_button));
row.show_all();
edit_button.connect_clicked(clone!(@strong this => move |_| {
}));
row.upcast()
}));
this this
} }
} }

View file

@ -42,7 +42,7 @@ pub struct TrackSetEditor {
track_list: List, track_list: List,
recording: RefCell<Option<Recording>>, recording: RefCell<Option<Recording>>,
tracks: RefCell<Vec<TrackData>>, tracks: RefCell<Vec<TrackData>>,
done_cb: RefCell<Option<Box<dyn Fn(TrackSet)>>>, done_cb: RefCell<Option<Box<dyn Fn(TrackSetData)>>>,
navigator: RefCell<Option<Rc<Navigator>>>, navigator: RefCell<Option<Rc<Navigator>>>,
} }
@ -87,7 +87,19 @@ impl TrackSetEditor {
})); }));
this.save_button.connect_clicked(clone!(@strong this => move |_| { this.save_button.connect_clicked(clone!(@strong this => move |_| {
if let Some(cb) = &*this.done_cb.borrow() {} if let Some(cb) = &*this.done_cb.borrow() {
let data = TrackSetData {
recording: this.recording.borrow().clone().unwrap(),
tracks: this.tracks.borrow().clone(),
};
cb(data);
}
let navigator = this.navigator.borrow().clone();
if let Some(navigator) = navigator {
navigator.pop();
}
})); }));
select_recording_button.connect_clicked(clone!(@strong this => move |_| { select_recording_button.connect_clicked(clone!(@strong this => move |_| {
@ -215,7 +227,7 @@ impl TrackSetEditor {
} }
/// Set the closure to be called when the user has created the track set. /// Set the closure to be called when the user has created the track set.
pub fn set_done_cb<F: Fn(TrackSet) + 'static>(&self, cb: F) { pub fn set_done_cb<F: Fn(TrackSetData) + 'static>(&self, cb: F) {
self.done_cb.replace(Some(Box::new(cb))); self.done_cb.replace(Some(Box::new(cb)));
} }