Avoid some errors using insensitive buttons

This commit is contained in:
Elias Projahn 2025-03-29 17:53:04 +01:00
parent a371e356f7
commit 43b07c73dc
11 changed files with 88 additions and 49 deletions

View file

@ -72,6 +72,10 @@ template $MusicusAlbumEditor: Adw.NavigationPage {
title: _("_Create album");
use-underline: true;
activated => $save() swapped;
styles [
"suggested-action",
]
}
}
}

View file

@ -42,6 +42,10 @@ template $MusicusEnsembleEditor: Adw.NavigationPage {
title: _("_Create ensemble");
use-underline: true;
activated => $save() swapped;
styles [
"suggested-action",
]
}
}
}

View file

@ -42,6 +42,10 @@ template $MusicusInstrumentEditor: Adw.NavigationPage {
title: _("_Create instrument");
use-underline: true;
activated => $save() swapped;
styles [
"suggested-action",
]
}
}
}

View file

@ -42,6 +42,10 @@ template $MusicusPersonEditor: Adw.NavigationPage {
title: _("_Create person");
use-underline: true;
activated => $save() swapped;
styles [
"suggested-action",
]
}
}
}

View file

@ -264,6 +264,10 @@ template $MusicusProgramEditor: Adw.NavigationPage {
title: _("_Save program");
use-underline: true;
activated => $save() swapped;
styles [
"suggested-action",
]
}
}
}

View file

@ -131,7 +131,12 @@ template $MusicusRecordingEditor: Adw.NavigationPage {
Adw.ButtonRow save_row {
title: _("_Create recording");
use-underline: true;
sensitive: false;
activated => $save() swapped;
styles [
"suggested-action",
]
}
}
}

View file

@ -42,6 +42,10 @@ template $MusicusRoleEditor: Adw.NavigationPage {
title: _("_Create role");
use-underline: true;
activated => $save() swapped;
styles [
"suggested-action",
]
}
}
}

View file

@ -89,7 +89,12 @@ template $MusicusTracksEditor: Adw.NavigationPage {
Adw.ButtonRow save_row {
title: _("_Import tracks");
use-underline: true;
sensitive: false;
activated => $save() swapped;
styles [
"suggested-action",
]
}
}
}

View file

@ -126,6 +126,10 @@ template $MusicusWorkEditor: Adw.NavigationPage {
title: _("_Create work");
use-underline: true;
activated => $save() swapped;
styles [
"suggested-action",
]
}
}
}

View file

@ -250,6 +250,7 @@ impl RecordingEditor {
.composers_string()
.unwrap_or_else(|| gettext("No composers")),
);
self.imp().save_row.set_sensitive(true);
self.imp().work.replace(Some(work));
}
@ -344,39 +345,40 @@ impl RecordingEditor {
#[template_callback]
fn save(&self) {
let library = self.imp().library.get().unwrap();
if let Some(work) = &*self.imp().work.borrow() {
let library = self.imp().library.get().unwrap();
// TODO: No work selected?
let work = self.imp().work.borrow().as_ref().unwrap().clone();
let year = self.imp().year_row.value() as i32;
let work = work.to_owned();
let year = self.imp().year_row.value() as i32;
let performers = self
.imp()
.performer_rows
.borrow()
.iter()
.map(|p| p.performer())
.collect::<Vec<Performer>>();
let performers = self
.imp()
.performer_rows
.borrow()
.iter()
.map(|p| p.performer())
.collect::<Vec<Performer>>();
let ensembles = self
.imp()
.ensemble_rows
.borrow()
.iter()
.map(|e| e.ensemble())
.collect::<Vec<EnsemblePerformer>>();
let ensembles = self
.imp()
.ensemble_rows
.borrow()
.iter()
.map(|e| e.ensemble())
.collect::<Vec<EnsemblePerformer>>();
if let Some(recording_id) = self.imp().recording_id.get() {
library
.update_recording(recording_id, work, Some(year), performers, ensembles)
.unwrap();
} else {
let recording = library
.create_recording(work, Some(year), performers, ensembles)
.unwrap();
self.emit_by_name::<()>("created", &[&recording]);
if let Some(recording_id) = self.imp().recording_id.get() {
library
.update_recording(recording_id, work, Some(year), performers, ensembles)
.unwrap();
} else {
let recording = library
.create_recording(work, Some(year), performers, ensembles)
.unwrap();
self.emit_by_name::<()>("created", &[&recording]);
}
self.imp().navigation.get().unwrap().pop();
}
self.imp().navigation.get().unwrap().pop();
}
}

View file

@ -227,6 +227,7 @@ impl TracksEditor {
self.imp().tracks_label.set_sensitive(true);
self.imp().track_list.set_sensitive(true);
self.imp().save_row.set_sensitive(true);
self.imp().recording.replace(Some(recording));
}
@ -304,23 +305,23 @@ impl TracksEditor {
#[template_callback]
fn save(&self) {
for track in self.imp().removed_tracks.borrow_mut().drain(..) {
self.library().delete_track(&track).unwrap();
}
if let Some(recording) = &*self.imp().recording.borrow() {
for track in self.imp().removed_tracks.borrow_mut().drain(..) {
self.library().delete_track(&track).unwrap();
}
for (index, track_row) in self.imp().track_rows.borrow_mut().drain(..).enumerate() {
let track_data = track_row.track_data();
for (index, track_row) in self.imp().track_rows.borrow_mut().drain(..).enumerate() {
let track_data = track_row.track_data();
match track_data.location {
TrackLocation::Undefined => {
log::error!("Failed to save track: Undefined track location.");
}
TrackLocation::Library(track) => self
.library()
.update_track(&track.track_id, index as i32, track_data.parts)
.unwrap(),
TrackLocation::System(path) => {
if let Some(recording) = &*self.imp().recording.borrow() {
match track_data.location {
TrackLocation::Undefined => {
log::error!("Failed to save track: Undefined track location.");
}
TrackLocation::Library(track) => self
.library()
.update_track(&track.track_id, index as i32, track_data.parts)
.unwrap(),
TrackLocation::System(path) => {
self.library()
.import_track(
&path,
@ -329,15 +330,13 @@ impl TracksEditor {
track_data.parts,
)
.unwrap();
} else {
log::error!("Failed to save track: No recording set.");
}
}
self.imp().track_list.remove(&track_row);
}
self.imp().track_list.remove(&track_row);
self.navigation().pop();
}
self.navigation().pop();
}
}