Return medium from medium editor

This commit is contained in:
Elias Projahn 2021-03-28 17:34:43 +02:00
parent c0de0acca9
commit 545bacabab
3 changed files with 10 additions and 23 deletions

View file

@ -29,22 +29,7 @@
</child>
<child type="end">
<object class="GtkButton" id="done_button">
<property name="sensitive">False</property>
<child>
<object class="GtkStack" id="done_stack">
<property name="transition-type">crossfade</property>
<child>
<object class="GtkSpinner" id="spinner">
<property name="spinning">True</property>
</object>
</child>
<child>
<object class="GtkImage" id="done">
<property name="icon-name">object-select-symbolic</property>
</object>
</child>
</object>
</child>
<property name="icon-name">object-select-symbolic</property>
<style>
<class name="suggested-action"/>
</style>

View file

@ -145,7 +145,9 @@ impl Screen<Arc<ImportSession>, ()> for ImportScreen {
add_button.connect_clicked(clone!(@weak this => move |_| {
spawn!(@clone this, async move {
push!(this.handle, MediumEditor, Arc::clone(&this.session)).await;
if let Some(medium) = push!(this.handle, MediumEditor, Arc::clone(&this.session)).await {
this.select_medium(medium);
}
});
}));

View file

@ -15,7 +15,7 @@ use std::sync::Arc;
/// A dialog for editing metadata while importing music into the music library.
pub struct MediumEditor {
handle: NavigationHandle<()>,
handle: NavigationHandle<Medium>,
session: Arc<ImportSession>,
widget: gtk::Stack,
done_button: gtk::Button,
@ -27,9 +27,9 @@ pub struct MediumEditor {
track_sets: RefCell<Vec<TrackSetData>>,
}
impl Screen<Arc<ImportSession>, ()> for MediumEditor {
impl Screen<Arc<ImportSession>, Medium> for MediumEditor {
/// Create a new medium editor.
fn new(session: Arc<ImportSession>, handle: NavigationHandle<()>) -> Rc<Self> {
fn new(session: Arc<ImportSession>, handle: NavigationHandle<Medium>) -> Rc<Self> {
// Create UI
let builder = gtk::Builder::from_resource("/de/johrpan/musicus/ui/medium_editor.ui");
@ -72,7 +72,7 @@ impl Screen<Arc<ImportSession>, ()> for MediumEditor {
this.widget.set_visible_child_name("loading");
spawn!(@clone this, async move {
match this.save().await {
Ok(_) => this.handle.pop(Some(())),
Ok(medium) => this.handle.pop(Some(medium)),
Err(err) => {
this.status_page.set_description(Some(&err.to_string()));
this.widget.set_visible_child_name("error");
@ -135,7 +135,7 @@ impl Screen<Arc<ImportSession>, ()> for MediumEditor {
impl MediumEditor {
/// Save the medium and possibly upload it to the server.
async fn save(&self) -> Result<()> {
async fn save(&self) -> Result<Medium> {
let name = self.name_entry.get_text().to_string();
// Create a new directory in the music library path for the imported medium.
@ -199,7 +199,7 @@ impl MediumEditor {
self.handle.backend.library_changed();
Ok(())
Ok(medium)
}
}