From 035142d193919a744cf5b2f437a630288fa1a33f Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Wed, 13 Jan 2021 19:56:27 +0100 Subject: [PATCH] Hook up track set editor --- musicus/src/import/medium_editor.rs | 45 +++++++++++++++++++++++++- musicus/src/import/track_set_editor.rs | 18 +++++++++-- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/musicus/src/import/medium_editor.rs b/musicus/src/import/medium_editor.rs index 742067c..57cec91 100644 --- a/musicus/src/import/medium_editor.rs +++ b/musicus/src/import/medium_editor.rs @@ -1,11 +1,12 @@ use super::disc_source::DiscSource; -use super::track_set_editor::TrackSetEditor; +use super::track_set_editor::{TrackSetData, TrackSetEditor}; use crate::backend::Backend; use crate::widgets::{Navigator, NavigatorScreen}; use crate::widgets::new_list::List; use glib::clone; use gtk::prelude::*; use gtk_macros::get_widget; +use libhandy::prelude::*; use std::cell::RefCell; use std::rc::Rc; @@ -14,6 +15,8 @@ pub struct MediumEditor { backend: Rc, source: Rc, widget: gtk::Box, + track_set_list: List, + track_sets: RefCell>, navigator: RefCell>>, } @@ -36,6 +39,8 @@ impl MediumEditor { backend, source: Rc::new(source), widget, + track_set_list: list, + track_sets: RefCell::new(Vec::new()), navigator: RefCell::new(None), }); @@ -52,10 +57,48 @@ impl MediumEditor { let navigator = this.navigator.borrow().clone(); if let Some(navigator) = navigator { 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); } })); + 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 } } diff --git a/musicus/src/import/track_set_editor.rs b/musicus/src/import/track_set_editor.rs index a418123..6cef69b 100644 --- a/musicus/src/import/track_set_editor.rs +++ b/musicus/src/import/track_set_editor.rs @@ -42,7 +42,7 @@ pub struct TrackSetEditor { track_list: List, recording: RefCell>, tracks: RefCell>, - done_cb: RefCell>>, + done_cb: RefCell>>, navigator: RefCell>>, } @@ -87,7 +87,19 @@ impl TrackSetEditor { })); 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 |_| { @@ -215,7 +227,7 @@ impl TrackSetEditor { } /// Set the closure to be called when the user has created the track set. - pub fn set_done_cb(&self, cb: F) { + pub fn set_done_cb(&self, cb: F) { self.done_cb.replace(Some(Box::new(cb))); }