editor: Redesign translation section

This commit is contained in:
Elias Projahn 2024-05-31 13:57:14 +02:00
parent 55b344605b
commit 7d3ab7e56b
8 changed files with 80 additions and 45 deletions

View file

@ -9,7 +9,19 @@ template $MusicusPersonEditor : Adw.NavigationPage {
Adw.HeaderBar header_bar {} Adw.HeaderBar header_bar {}
Adw.Clamp { Adw.Clamp {
$MusicusTranslationSection name_section {} Gtk.Label {
label: _("Name");
xalign: 0;
margin-top: 24;
styles [
"heading"
]
}
$MusicusTranslationEditor name_editor {
margin-start: 12;
}
} }
} }
} }

View file

@ -0,0 +1,29 @@
using Gtk 4.0;
using Adw 1;
template $MusicusTranslationEditor: Adw.Bin {
Gtk.ListBox list_box {
selection-mode: none;
styles [
"boxed-list"
]
Adw.EntryRow entry_row {
title: _("Name");
}
Adw.ActionRow {
title: _("Add translation");
activatable: true;
activated => $add_translation() swapped;
[prefix]
Gtk.Box select_person_box {
Gtk.Image {
icon-name: "list-add-symbolic";
}
}
}
}
}

View file

@ -1,19 +0,0 @@
using Gtk 4.0;
using Adw 1;
template $MusicusTranslationSection : Adw.PreferencesGroup {
title: _("Name");
header-suffix: Gtk.Button add_button {
styles ["flat"]
clicked => $add_translation() swapped;
Adw.ButtonContent {
icon-name: "list-add-symbolic";
label: _("Translate");
}
};
Adw.EntryRow entry_row {
title: _("Name");
}
}

View file

@ -16,7 +16,19 @@ template $MusicusWorkEditor: Adw.NavigationPage {
margin-start: 12; margin-start: 12;
margin-end: 12; margin-end: 12;
$MusicusTranslationSection name_section {} Gtk.Label {
label: _("Name");
xalign: 0;
margin-top: 24;
styles [
"heading"
]
}
$MusicusTranslationEditor name_editor {
margin-top: 12;
}
Gtk.Label { Gtk.Label {
label: _("Composers"); label: _("Composers");

View file

@ -4,6 +4,6 @@ pub mod person_editor;
pub mod person_selector_popover; pub mod person_selector_popover;
pub mod role_selector_popover; pub mod role_selector_popover;
pub mod translation_entry; pub mod translation_entry;
pub mod translation_section; pub mod translation_editor;
pub mod work_editor; pub mod work_editor;
pub mod work_editor_composer_row; pub mod work_editor_composer_row;

View file

@ -1,7 +1,7 @@
use adw::{prelude::*, subclass::prelude::*}; use adw::{prelude::*, subclass::prelude::*};
use gtk::glib; use gtk::glib;
use crate::editor::translation_section::MusicusTranslationSection; use crate::editor::translation_editor::MusicusTranslationEditor;
mod imp { mod imp {
use super::*; use super::*;
@ -17,7 +17,7 @@ mod imp {
type ParentType = adw::NavigationPage; type ParentType = adw::NavigationPage;
fn class_init(klass: &mut Self::Class) { fn class_init(klass: &mut Self::Class) {
MusicusTranslationSection::static_type(); MusicusTranslationEditor::static_type();
klass.bind_template(); klass.bind_template();
klass.bind_template_instance_callbacks(); klass.bind_template_instance_callbacks();
} }

View file

@ -12,8 +12,10 @@ mod imp {
use super::*; use super::*;
#[derive(Debug, Default, gtk::CompositeTemplate)] #[derive(Debug, Default, gtk::CompositeTemplate)]
#[template(file = "data/ui/translation_section.blp")] #[template(file = "data/ui/translation_editor.blp")]
pub struct MusicusTranslationSection { pub struct MusicusTranslationEditor {
#[template_child]
pub list_box: TemplateChild<gtk::ListBox>,
#[template_child] #[template_child]
pub entry_row: TemplateChild<adw::EntryRow>, pub entry_row: TemplateChild<adw::EntryRow>,
@ -21,10 +23,10 @@ mod imp {
} }
#[glib::object_subclass] #[glib::object_subclass]
impl ObjectSubclass for MusicusTranslationSection { impl ObjectSubclass for MusicusTranslationEditor {
const NAME: &'static str = "MusicusTranslationSection"; const NAME: &'static str = "MusicusTranslationEditor";
type Type = super::MusicusTranslationSection; type Type = super::MusicusTranslationEditor;
type ParentType = adw::PreferencesGroup; type ParentType = adw::Bin;
fn class_init(klass: &mut Self::Class) { fn class_init(klass: &mut Self::Class) {
klass.bind_template(); klass.bind_template();
@ -36,23 +38,23 @@ mod imp {
} }
} }
impl ObjectImpl for MusicusTranslationSection { impl ObjectImpl for MusicusTranslationEditor {
fn constructed(&self) { fn constructed(&self) {
self.parent_constructed(); self.parent_constructed();
} }
} }
impl WidgetImpl for MusicusTranslationSection {} impl WidgetImpl for MusicusTranslationEditor {}
impl PreferencesGroupImpl for MusicusTranslationSection {} impl BinImpl for MusicusTranslationEditor {}
} }
glib::wrapper! { glib::wrapper! {
pub struct MusicusTranslationSection(ObjectSubclass<imp::MusicusTranslationSection>) pub struct MusicusTranslationEditor(ObjectSubclass<imp::MusicusTranslationEditor>)
@extends gtk::Widget, adw::PreferencesGroup; @extends gtk::Widget, adw::PreferencesGroup;
} }
#[gtk::template_callbacks] #[gtk::template_callbacks]
impl MusicusTranslationSection { impl MusicusTranslationEditor {
pub fn new(translation: TranslatedString) -> Self { pub fn new(translation: TranslatedString) -> Self {
let obj: Self = glib::Object::new(); let obj: Self = glib::Object::new();
let mut translation = translation.0; let mut translation = translation.0;
@ -69,7 +71,7 @@ impl MusicusTranslationSection {
} }
#[template_callback] #[template_callback]
fn add_translation(&self, _: &gtk::Button) { fn add_translation(&self, _: &adw::ActionRow) {
self.add_entry(&util::LANG, &self.imp().entry_row.text()); self.add_entry(&util::LANG, &self.imp().entry_row.text());
} }
@ -90,14 +92,13 @@ impl MusicusTranslationSection {
let obj = self.clone(); let obj = self.clone();
entry.connect_remove(move |entry| { entry.connect_remove(move |entry| {
let mut entries = obj.imp().translation_entries.borrow_mut(); obj.imp().translation_entries.borrow_mut().retain(|e| e != entry);
if let Some(index) = entries.iter().position(|e| e == entry) { obj.imp().list_box.remove(entry);
entries.remove(index);
}
obj.remove(entry);
}); });
self.add(&entry); 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); self.imp().translation_entries.borrow_mut().push(entry);
} }
} }

View file

@ -3,7 +3,7 @@ use crate::{
editor::{ editor::{
instrument_selector_popover::MusicusInstrumentSelectorPopover, instrument_selector_popover::MusicusInstrumentSelectorPopover,
person_selector_popover::MusicusPersonSelectorPopover, person_selector_popover::MusicusPersonSelectorPopover,
translation_section::MusicusTranslationSection, translation_editor::MusicusTranslationEditor,
work_editor_composer_row::MusicusWorkEditorComposerRow, work_editor_composer_row::MusicusWorkEditorComposerRow,
}, },
library::MusicusLibrary, library::MusicusLibrary,
@ -50,7 +50,7 @@ mod imp {
type ParentType = adw::NavigationPage; type ParentType = adw::NavigationPage;
fn class_init(klass: &mut Self::Class) { fn class_init(klass: &mut Self::Class) {
MusicusTranslationSection::static_type(); MusicusTranslationEditor::static_type();
klass.bind_template(); klass.bind_template();
klass.bind_template_instance_callbacks(); klass.bind_template_instance_callbacks();
} }