Add work and recording editor

This commit is contained in:
Elias Projahn 2025-01-15 11:23:04 +01:00
parent 36b2f1097e
commit 364557d959
30 changed files with 3308 additions and 418 deletions

View file

@ -1,7 +1,10 @@
use gtk::{glib, subclass::prelude::*};
use gtk::{gio, glib, prelude::*, subclass::prelude::*};
use std::cell::OnceCell;
use crate::db::models::Recording;
use crate::{
db::models::Recording, editor::recording_editor::MusicusRecordingEditor,
library::MusicusLibrary,
};
mod imp {
use super::*;
@ -16,6 +19,8 @@ mod imp {
#[template_child]
pub performances_label: TemplateChild<gtk::Label>,
pub navigation: OnceCell<adw::NavigationView>,
pub library: OnceCell<MusicusLibrary>,
pub recording: OnceCell<Recording>,
}
@ -34,7 +39,31 @@ mod imp {
}
}
impl ObjectImpl for MusicusRecordingTile {}
impl ObjectImpl for MusicusRecordingTile {
fn constructed(&self) {
self.parent_constructed();
let obj = self.obj().to_owned();
let edit_action = gio::ActionEntry::builder("edit")
.activate(move |_, _, _| {
obj.imp()
.navigation
.get()
.unwrap()
.push(&MusicusRecordingEditor::new(
obj.imp().navigation.get().unwrap(),
obj.imp().library.get().unwrap(),
Some(&obj.imp().recording.get().unwrap()),
));
})
.build();
let actions = gio::SimpleActionGroup::new();
actions.add_action_entries([edit_action]);
self.obj().insert_action_group("recording", Some(&actions));
}
}
impl WidgetImpl for MusicusRecordingTile {}
impl FlowBoxChildImpl for MusicusRecordingTile {}
}
@ -45,15 +74,23 @@ glib::wrapper! {
}
impl MusicusRecordingTile {
pub fn new(recording: &Recording) -> Self {
pub fn new(
navigation: &adw::NavigationView,
library: &MusicusLibrary,
recording: &Recording,
) -> Self {
let obj: Self = glib::Object::new();
let imp = obj.imp();
imp.work_label.set_label(&recording.work.name.get());
imp.composer_label.set_label(&recording.work.composers_string());
imp.performances_label.set_label(&recording.performers_string());
imp.composer_label
.set_label(&recording.work.composers_string());
imp.performances_label
.set_label(&recording.performers_string());
imp.recording.set(recording.clone()).unwrap();
imp.navigation.set(navigation.to_owned()).unwrap();
imp.library.set(library.to_owned()).unwrap();
imp.recording.set(recording.to_owned()).unwrap();
obj
}