diff --git a/Cargo.toml b/Cargo.toml
index a6b59eb..2111ca1 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,4 +10,5 @@ gio = "0.9.1"
glib = "0.10.2"
gtk = { version = "0.9.2", features = ["v3_24"] }
gtk-macros = "0.2.0"
+pango = "0.9.1"
rand = "0.7.3"
diff --git a/res/resources.xml b/res/resources.xml
index 64d125c..a1c7a1c 100644
--- a/res/resources.xml
+++ b/res/resources.xml
@@ -7,6 +7,7 @@
ui/part_editor.ui
ui/person_editor.ui
ui/person_selector.ui
+ ui/section_editor.ui
ui/window.ui
ui/work_editor.ui
diff --git a/res/ui/section_editor.ui b/res/ui/section_editor.ui
new file mode 100644
index 0000000..57a8801
--- /dev/null
+++ b/res/ui/section_editor.ui
@@ -0,0 +1,73 @@
+
+
+
+
+
+
diff --git a/res/ui/work_editor.ui b/res/ui/work_editor.ui
index 14e9ed4..0f2a8c8 100644
--- a/res/ui/work_editor.ui
+++ b/res/ui/work_editor.ui
@@ -257,25 +257,6 @@
0
-
-
- True
- True
- True
-
-
- True
- False
- list-remove-symbolic
-
-
-
-
- False
- True
- 1
-
-
True
@@ -289,12 +270,50 @@
+
+ False
+ True
+ 1
+
+
+
+
+ True
+ True
+ True
+
+
+ True
+ False
+ edit-symbolic
+
+
+
False
True
2
+
+
+ True
+ True
+ True
+
+
+ True
+ False
+ list-remove-symbolic
+
+
+
+
+ False
+ True
+ 3
+
+
True
@@ -312,7 +331,7 @@
False
True
end
- 2
+ 4
@@ -332,25 +351,6 @@
False
True
end
- 3
-
-
-
-
- True
- True
- True
-
-
- True
- False
- edit-symbolic
-
-
-
-
- False
- True
5
diff --git a/src/dialogs/mod.rs b/src/dialogs/mod.rs
index d38a64d..b9dcc53 100644
--- a/src/dialogs/mod.rs
+++ b/src/dialogs/mod.rs
@@ -16,6 +16,9 @@ pub use person_editor::*;
pub mod person_selector;
pub use person_selector::*;
+pub mod section_editor;
+pub use section_editor::*;
+
pub mod selector_row;
pub mod work_editor;
diff --git a/src/dialogs/section_editor.rs b/src/dialogs/section_editor.rs
new file mode 100644
index 0000000..625d8c2
--- /dev/null
+++ b/src/dialogs/section_editor.rs
@@ -0,0 +1,61 @@
+use crate::database::*;
+use glib::clone;
+use gtk::prelude::*;
+use gtk_macros::get_widget;
+use std::rc::Rc;
+
+pub struct SectionEditor {
+ window: gtk::Window,
+ title_entry: gtk::Entry,
+}
+
+impl SectionEditor {
+ pub fn new () + 'static, P: IsA>(
+ parent: &P,
+ section: Option,
+ callback: F,
+ ) -> Rc {
+ let builder =
+ gtk::Builder::from_resource("/de/johrpan/musicus_editor/ui/section_editor.ui");
+
+ get_widget!(builder, gtk::Window, window);
+ get_widget!(builder, gtk::Button, cancel_button);
+ get_widget!(builder, gtk::Button, save_button);
+ get_widget!(builder, gtk::Entry, title_entry);
+
+ match section {
+ Some(section) => {
+ title_entry.set_text(§ion.title);
+ }
+ None => (),
+ }
+
+ let result = Rc::new(SectionEditor {
+ window: window,
+ title_entry: title_entry,
+ });
+
+ cancel_button.connect_clicked(clone!(@strong result => move |_| {
+ result.window.close();
+ }));
+
+ save_button.connect_clicked(clone!(@strong result => move |_| {
+ result.window.close();
+
+ let section = WorkSectionDescription {
+ before_index: 0,
+ title: result.title_entry.get_text().to_string(),
+ };
+
+ callback(section);
+ }));
+
+ result.window.set_transient_for(Some(parent));
+
+ result
+ }
+
+ pub fn show(&self) {
+ self.window.show();
+ }
+}
diff --git a/src/dialogs/work_editor.rs b/src/dialogs/work_editor.rs
index 607c9fe..da13924 100644
--- a/src/dialogs/work_editor.rs
+++ b/src/dialogs/work_editor.rs
@@ -1,5 +1,5 @@
use super::selector_row::SelectorRow;
-use super::{InstrumentSelector, PersonSelector, PartEditor};
+use super::{InstrumentSelector, PersonSelector, PartEditor, SectionEditor};
use crate::database::*;
use glib::clone;
use gtk::prelude::*;
@@ -226,17 +226,15 @@ impl WorkEditor {
})).show();
}));
- remove_part_button.connect_clicked(clone!(@strong result => move |_| {
- let row = result.get_selected_part_row();
- match row {
- Some(row) => {
- let index = row.get_index();
- let index: usize = index.try_into().unwrap();
- result.structure.borrow_mut().remove(index);
- result.show_parts();
+ add_section_button.connect_clicked(clone!(@strong result => move |_| {
+ SectionEditor::new(&result.window, None, clone!(@strong result => move |section| {
+ {
+ let mut structure = result.structure.borrow_mut();
+ structure.push(PartOrSection::section(section));
}
- None => (),
- }
+
+ result.show_parts();
+ })).show();
}));
edit_part_button.connect_clicked(clone!(@strong result => move |_| {
@@ -245,15 +243,38 @@ impl WorkEditor {
Some(row) => {
let index = row.get_index();
let index: usize = index.try_into().unwrap();
- let part = &result.structure.borrow()[index];
+ let pos = &result.structure.borrow()[index];
+
+ if pos.is_part() {
+ let editor =
+ PartEditor::new(result.db.clone(), &result.window, Some(pos.unwrap_part()), clone!(@strong result => move |part| {
+ result.structure.borrow_mut()[index] = PartOrSection::part(part);
+ result.show_parts();
+ }));
- let editor =
- PartEditor::new(result.db.clone(), &result.window, Some(part.unwrap_part()), clone!(@strong result => move |part| {
- result.structure.borrow_mut()[index] = PartOrSection::part(part);
- result.show_parts();
- }));
+ editor.show();
+ } else {
+ let editor =
+ SectionEditor::new(&result.window, Some(pos.unwrap_section()), clone!(@strong result => move |section| {
+ result.structure.borrow_mut()[index] = PartOrSection::section(section);
+ result.show_parts();
+ }));
- editor.show();
+ editor.show();
+ }
+ }
+ None => (),
+ }
+ }));
+
+ remove_part_button.connect_clicked(clone!(@strong result => move |_| {
+ let row = result.get_selected_part_row();
+ match row {
+ Some(row) => {
+ let index = row.get_index();
+ let index: usize = index.try_into().unwrap();
+ result.structure.borrow_mut().remove(index);
+ result.show_parts();
}
None => (),
}
@@ -330,6 +351,15 @@ impl WorkEditor {
for (index, part) in self.structure.borrow().iter().enumerate() {
let label = gtk::Label::new(Some(&part.get_title()));
label.set_halign(gtk::Align::Start);
+
+ if part.is_part() {
+ label.set_margin_start(6);
+ } else {
+ let attributes = pango::AttrList::new();
+ attributes.insert(pango::Attribute::new_weight(pango::Weight::Bold).unwrap());
+ label.set_attributes(Some(&attributes));
+ }
+
let row = SelectorRow::new(index.try_into().unwrap(), &label);
row.show_all();
self.part_list.insert(&row, -1);