Initialize work and recording editors

This commit is contained in:
Elias Projahn 2020-12-17 21:23:16 +01:00
parent 3339945380
commit e2d36a88b8
5 changed files with 43 additions and 4 deletions

1
musicus/.gitignore vendored
View file

@ -1,4 +1,5 @@
/.flatpak-builder /.flatpak-builder
/.vscode
/build /build
/builddir /builddir
/flatpak /flatpak

View file

@ -1,3 +1,4 @@
use super::generate_id;
use super::schema::{ensembles, performances, persons, recordings}; use super::schema::{ensembles, performances, persons, recordings};
use super::{Database, Ensemble, Instrument, Person, Work}; use super::{Database, Ensemble, Instrument, Person, Work};
use anyhow::{anyhow, Error, Result}; use anyhow::{anyhow, Error, Result};
@ -93,6 +94,16 @@ pub struct Recording {
} }
impl Recording { impl Recording {
/// Initialize a new recording with a work.
pub fn new(work: Work) -> Self {
Self {
id: generate_id(),
work,
comment: String::new(),
performances: Vec::new(),
}
}
/// Get a string representation of the performances in this recording. /// Get a string representation of the performances in this recording.
// TODO: Maybe replace with impl Display? // TODO: Maybe replace with impl Display?
pub fn get_performers(&self) -> String { pub fn get_performers(&self) -> String {

View file

@ -1,3 +1,4 @@
use super::generate_id;
use super::schema::{instrumentations, work_parts, work_sections, works}; use super::schema::{instrumentations, work_parts, work_sections, works};
use super::{Database, Instrument, Person}; use super::{Database, Instrument, Person};
use anyhow::{anyhow, Error, Result}; use anyhow::{anyhow, Error, Result};
@ -83,6 +84,18 @@ pub struct Work {
} }
impl Work { impl Work {
/// Initialize a new work with a composer.
pub fn new(composer: Person) -> Self {
Self {
id: generate_id(),
title: String::new(),
composer,
instruments: Vec::new(),
parts: Vec::new(),
sections: Vec::new(),
}
}
/// Get a string including the composer and title of the work. /// Get a string including the composer and title of the work.
// TODO: Replace with impl Display. // TODO: Replace with impl Display.
pub fn get_title(&self) -> String { pub fn get_title(&self) -> String {

View file

@ -47,9 +47,16 @@ impl RecordingSelector {
this.selector.set_add_cb(clone!(@strong this => move || { this.selector.set_add_cb(clone!(@strong this => move || {
let navigator = this.navigator.borrow().clone(); let navigator = this.navigator.borrow().clone();
if let Some(navigator) = navigator { if let Some(navigator) = navigator {
let editor = RecordingEditor::new(this.backend.clone(), None); let recording = Recording::new(this.work.clone());
let editor = RecordingEditor::new(this.backend.clone(), Some(recording));
editor editor
.set_selected_cb(clone!(@strong this => move |recording| this.select(&recording))); .set_selected_cb(clone!(@strong this, @strong navigator => move |recording| {
navigator.clone().pop();
this.select(&recording);
}));
navigator.push(editor); navigator.push(editor);
} }
})); }));

View file

@ -47,9 +47,16 @@ impl WorkSelector {
this.selector.set_add_cb(clone!(@strong this => move || { this.selector.set_add_cb(clone!(@strong this => move || {
let navigator = this.navigator.borrow().clone(); let navigator = this.navigator.borrow().clone();
if let Some(navigator) = navigator { if let Some(navigator) = navigator {
let editor = WorkEditor::new(this.backend.clone(), None); let work = Work::new(this.person.clone());
let editor = WorkEditor::new(this.backend.clone(), Some(work));
editor editor
.set_saved_cb(clone!(@strong this => move |work| this.select(&work))); .set_saved_cb(clone!(@strong this, @strong navigator => move |work| {
navigator.clone().pop();
this.select(&work);
}));
navigator.push(editor); navigator.push(editor);
} }
})); }));