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"); title: _("_Create album");
use-underline: true; use-underline: true;
activated => $save() swapped; activated => $save() swapped;
styles [
"suggested-action",
]
} }
} }
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -250,6 +250,7 @@ impl RecordingEditor {
.composers_string() .composers_string()
.unwrap_or_else(|| gettext("No composers")), .unwrap_or_else(|| gettext("No composers")),
); );
self.imp().save_row.set_sensitive(true);
self.imp().work.replace(Some(work)); self.imp().work.replace(Some(work));
} }
@ -344,39 +345,40 @@ impl RecordingEditor {
#[template_callback] #[template_callback]
fn save(&self) { 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 = work.to_owned();
let work = self.imp().work.borrow().as_ref().unwrap().clone(); let year = self.imp().year_row.value() as i32;
let year = self.imp().year_row.value() as i32;
let performers = self let performers = self
.imp() .imp()
.performer_rows .performer_rows
.borrow() .borrow()
.iter() .iter()
.map(|p| p.performer()) .map(|p| p.performer())
.collect::<Vec<Performer>>(); .collect::<Vec<Performer>>();
let ensembles = self let ensembles = self
.imp() .imp()
.ensemble_rows .ensemble_rows
.borrow() .borrow()
.iter() .iter()
.map(|e| e.ensemble()) .map(|e| e.ensemble())
.collect::<Vec<EnsemblePerformer>>(); .collect::<Vec<EnsemblePerformer>>();
if let Some(recording_id) = self.imp().recording_id.get() { if let Some(recording_id) = self.imp().recording_id.get() {
library library
.update_recording(recording_id, work, Some(year), performers, ensembles) .update_recording(recording_id, work, Some(year), performers, ensembles)
.unwrap(); .unwrap();
} else { } else {
let recording = library let recording = library
.create_recording(work, Some(year), performers, ensembles) .create_recording(work, Some(year), performers, ensembles)
.unwrap(); .unwrap();
self.emit_by_name::<()>("created", &[&recording]); 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().tracks_label.set_sensitive(true);
self.imp().track_list.set_sensitive(true); self.imp().track_list.set_sensitive(true);
self.imp().save_row.set_sensitive(true);
self.imp().recording.replace(Some(recording)); self.imp().recording.replace(Some(recording));
} }
@ -304,23 +305,23 @@ impl TracksEditor {
#[template_callback] #[template_callback]
fn save(&self) { fn save(&self) {
for track in self.imp().removed_tracks.borrow_mut().drain(..) { if let Some(recording) = &*self.imp().recording.borrow() {
self.library().delete_track(&track).unwrap(); 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() { for (index, track_row) in self.imp().track_rows.borrow_mut().drain(..).enumerate() {
let track_data = track_row.track_data(); let track_data = track_row.track_data();
match track_data.location { match track_data.location {
TrackLocation::Undefined => { TrackLocation::Undefined => {
log::error!("Failed to save track: Undefined track location."); log::error!("Failed to save track: Undefined track location.");
} }
TrackLocation::Library(track) => self TrackLocation::Library(track) => self
.library() .library()
.update_track(&track.track_id, index as i32, track_data.parts) .update_track(&track.track_id, index as i32, track_data.parts)
.unwrap(), .unwrap(),
TrackLocation::System(path) => { TrackLocation::System(path) => {
if let Some(recording) = &*self.imp().recording.borrow() {
self.library() self.library()
.import_track( .import_track(
&path, &path,
@ -329,15 +330,13 @@ impl TracksEditor {
track_data.parts, track_data.parts,
) )
.unwrap(); .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();
} }
} }