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,10 +345,10 @@ impl RecordingEditor {
#[template_callback] #[template_callback]
fn save(&self) { fn save(&self) {
if let Some(work) = &*self.imp().work.borrow() {
let library = self.imp().library.get().unwrap(); 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
@ -379,4 +380,5 @@ impl RecordingEditor {
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,6 +305,7 @@ impl TracksEditor {
#[template_callback] #[template_callback]
fn save(&self) { fn save(&self) {
if let Some(recording) = &*self.imp().recording.borrow() {
for track in self.imp().removed_tracks.borrow_mut().drain(..) { for track in self.imp().removed_tracks.borrow_mut().drain(..) {
self.library().delete_track(&track).unwrap(); self.library().delete_track(&track).unwrap();
} }
@ -320,7 +322,6 @@ impl TracksEditor {
.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,9 +330,6 @@ impl TracksEditor {
track_data.parts, track_data.parts,
) )
.unwrap(); .unwrap();
} else {
log::error!("Failed to save track: No recording set.");
}
} }
} }
@ -340,4 +338,5 @@ impl TracksEditor {
self.navigation().pop(); self.navigation().pop();
} }
}
} }