mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Add home page header and hook up editors
This commit is contained in:
parent
38613c0063
commit
f49f23a501
10 changed files with 236 additions and 55 deletions
|
|
@ -1,14 +1,17 @@
|
|||
use adw::{prelude::*, subclass::prelude::*};
|
||||
use gtk::glib;
|
||||
|
||||
use crate::editor::translation_editor::MusicusTranslationEditor;
|
||||
use crate::{db::models::Person, editor::translation_editor::MusicusTranslationEditor};
|
||||
|
||||
mod imp {
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Default, gtk::CompositeTemplate)]
|
||||
#[template(file = "data/ui/person_editor.blp")]
|
||||
pub struct MusicusPersonEditor {}
|
||||
pub struct MusicusPersonEditor {
|
||||
#[template_child]
|
||||
pub name_editor: TemplateChild<MusicusTranslationEditor>,
|
||||
}
|
||||
|
||||
#[glib::object_subclass]
|
||||
impl ObjectSubclass for MusicusPersonEditor {
|
||||
|
|
@ -39,7 +42,13 @@ glib::wrapper! {
|
|||
|
||||
#[gtk::template_callbacks]
|
||||
impl MusicusPersonEditor {
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new()
|
||||
pub fn new(person: Option<&Person>) -> Self {
|
||||
let obj: Self = glib::Object::new();
|
||||
|
||||
if let Some(person) = person {
|
||||
obj.imp().name_editor.set_translation(&person.name);
|
||||
}
|
||||
|
||||
obj
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,19 +55,20 @@ glib::wrapper! {
|
|||
|
||||
#[gtk::template_callbacks]
|
||||
impl MusicusTranslationEditor {
|
||||
pub fn new(translation: TranslatedString) -> Self {
|
||||
let obj: Self = glib::Object::new();
|
||||
let mut translation = translation.0;
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new()
|
||||
}
|
||||
|
||||
obj.imp()
|
||||
pub fn set_translation(&self, translation: &TranslatedString) {
|
||||
let mut translation = translation.0.clone();
|
||||
|
||||
self.imp()
|
||||
.entry_row
|
||||
.set_text(&translation.remove("generic").unwrap_or_default());
|
||||
|
||||
for (lang, translation) in translation {
|
||||
obj.add_entry(&lang, &translation);
|
||||
self.add_entry(&lang, &translation);
|
||||
}
|
||||
|
||||
obj
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
|
|
@ -92,11 +93,17 @@ impl MusicusTranslationEditor {
|
|||
|
||||
let obj = self.clone();
|
||||
entry.connect_remove(move |entry| {
|
||||
obj.imp().translation_entries.borrow_mut().retain(|e| e != entry);
|
||||
obj.imp()
|
||||
.translation_entries
|
||||
.borrow_mut()
|
||||
.retain(|e| e != entry);
|
||||
obj.imp().list_box.remove(entry);
|
||||
});
|
||||
|
||||
self.imp().list_box.insert(&entry, self.imp().translation_entries.borrow().len() as i32 + 1);
|
||||
self.imp().list_box.insert(
|
||||
&entry,
|
||||
self.imp().translation_entries.borrow().len() as i32 + 1,
|
||||
);
|
||||
entry.grab_focus();
|
||||
|
||||
self.imp().translation_entries.borrow_mut().push(entry);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
db::{
|
||||
self,
|
||||
models::{Composer, Instrument, Person, WorkPart},
|
||||
models::{Composer, Instrument, Person, Work, WorkPart},
|
||||
},
|
||||
editor::{
|
||||
instrument_selector_popover::MusicusInstrumentSelectorPopover,
|
||||
|
|
@ -25,6 +25,9 @@ mod imp {
|
|||
#[properties(wrapper_type = super::MusicusWorkEditor)]
|
||||
#[template(file = "data/ui/work_editor.blp")]
|
||||
pub struct MusicusWorkEditor {
|
||||
#[property(get, construct_only)]
|
||||
pub navigation: OnceCell<adw::NavigationView>,
|
||||
|
||||
#[property(get, construct_only)]
|
||||
pub library: OnceCell<MusicusLibrary>,
|
||||
|
||||
|
|
@ -38,6 +41,8 @@ mod imp {
|
|||
pub persons_popover: OnceCell<MusicusPersonSelectorPopover>,
|
||||
pub instruments_popover: OnceCell<MusicusInstrumentSelectorPopover>,
|
||||
|
||||
#[template_child]
|
||||
pub name_editor: TemplateChild<MusicusTranslationEditor>,
|
||||
#[template_child]
|
||||
pub composer_list: TemplateChild<gtk::ListBox>,
|
||||
#[template_child]
|
||||
|
|
@ -146,8 +151,21 @@ glib::wrapper! {
|
|||
|
||||
#[gtk::template_callbacks]
|
||||
impl MusicusWorkEditor {
|
||||
pub fn new(library: &MusicusLibrary) -> Self {
|
||||
glib::Object::builder().property("library", library).build()
|
||||
pub fn new(
|
||||
navigation: &adw::NavigationView,
|
||||
library: &MusicusLibrary,
|
||||
work: Option<&Work>,
|
||||
) -> Self {
|
||||
let obj: Self = glib::Object::builder()
|
||||
.property("navigation", navigation)
|
||||
.property("library", library)
|
||||
.build();
|
||||
|
||||
if let Some(_work) = work {
|
||||
// TODO: Initialize work data.
|
||||
}
|
||||
|
||||
obj
|
||||
}
|
||||
|
||||
#[template_callback]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue