mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
Add section editor and handling
This commit is contained in:
parent
277a1f6189
commit
6cdaf97a36
7 changed files with 226 additions and 57 deletions
|
|
@ -10,4 +10,5 @@ gio = "0.9.1"
|
||||||
glib = "0.10.2"
|
glib = "0.10.2"
|
||||||
gtk = { version = "0.9.2", features = ["v3_24"] }
|
gtk = { version = "0.9.2", features = ["v3_24"] }
|
||||||
gtk-macros = "0.2.0"
|
gtk-macros = "0.2.0"
|
||||||
|
pango = "0.9.1"
|
||||||
rand = "0.7.3"
|
rand = "0.7.3"
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
<file preprocess="xml-stripblanks">ui/part_editor.ui</file>
|
<file preprocess="xml-stripblanks">ui/part_editor.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/person_editor.ui</file>
|
<file preprocess="xml-stripblanks">ui/person_editor.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/person_selector.ui</file>
|
<file preprocess="xml-stripblanks">ui/person_selector.ui</file>
|
||||||
|
<file preprocess="xml-stripblanks">ui/section_editor.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/window.ui</file>
|
<file preprocess="xml-stripblanks">ui/window.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/work_editor.ui</file>
|
<file preprocess="xml-stripblanks">ui/work_editor.ui</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
|
|
|
||||||
73
res/ui/section_editor.ui
Normal file
73
res/ui/section_editor.ui
Normal file
|
|
@ -0,0 +1,73 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Generated with glade 3.36.0 -->
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk+" version="3.22"/>
|
||||||
|
<object class="GtkWindow" id="window">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="modal">True</property>
|
||||||
|
<property name="destroy_with_parent">True</property>
|
||||||
|
<property name="type_hint">dialog</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkGrid">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="border_width">18</property>
|
||||||
|
<property name="row_spacing">12</property>
|
||||||
|
<property name="column_spacing">6</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="halign">end</property>
|
||||||
|
<property name="label" translatable="yes">Title</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkEntry" id="title_entry">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">1</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child type="titlebar">
|
||||||
|
<object class="GtkHeaderBar">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="title" translatable="yes">Work section</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="cancel_button">
|
||||||
|
<property name="label" translatable="yes">Cancel</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="save_button">
|
||||||
|
<property name="label" translatable="yes">Save</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
<style>
|
||||||
|
<class name="suggested-action"/>
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="pack_type">end</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</interface>
|
||||||
|
|
@ -257,25 +257,6 @@
|
||||||
<property name="position">0</property>
|
<property name="position">0</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
|
||||||
<object class="GtkButton" id="remove_part_button">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="receives_default">True</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkImage">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="icon_name">list-remove-symbolic</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="expand">False</property>
|
|
||||||
<property name="fill">True</property>
|
|
||||||
<property name="position">1</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="add_section_button">
|
<object class="GtkButton" id="add_section_button">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
|
@ -289,12 +270,50 @@
|
||||||
</object>
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="edit_part_button">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkImage">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="icon_name">edit-symbolic</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="position">2</property>
|
<property name="position">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="remove_part_button">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="receives_default">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkImage">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="icon_name">list-remove-symbolic</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">3</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkButton" id="move_part_down_button">
|
<object class="GtkButton" id="move_part_down_button">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
|
@ -312,7 +331,7 @@
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="pack_type">end</property>
|
<property name="pack_type">end</property>
|
||||||
<property name="position">2</property>
|
<property name="position">4</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
|
|
@ -332,25 +351,6 @@
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
<property name="fill">True</property>
|
<property name="fill">True</property>
|
||||||
<property name="pack_type">end</property>
|
<property name="pack_type">end</property>
|
||||||
<property name="position">3</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkButton" id="edit_part_button">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="receives_default">True</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkImage">
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">False</property>
|
|
||||||
<property name="icon_name">edit-symbolic</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
<packing>
|
|
||||||
<property name="expand">False</property>
|
|
||||||
<property name="fill">True</property>
|
|
||||||
<property name="position">5</property>
|
<property name="position">5</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,9 @@ pub use person_editor::*;
|
||||||
pub mod person_selector;
|
pub mod person_selector;
|
||||||
pub use person_selector::*;
|
pub use person_selector::*;
|
||||||
|
|
||||||
|
pub mod section_editor;
|
||||||
|
pub use section_editor::*;
|
||||||
|
|
||||||
pub mod selector_row;
|
pub mod selector_row;
|
||||||
|
|
||||||
pub mod work_editor;
|
pub mod work_editor;
|
||||||
|
|
|
||||||
61
src/dialogs/section_editor.rs
Normal file
61
src/dialogs/section_editor.rs
Normal file
|
|
@ -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<F: Fn(WorkSectionDescription) -> () + 'static, P: IsA<gtk::Window>>(
|
||||||
|
parent: &P,
|
||||||
|
section: Option<WorkSectionDescription>,
|
||||||
|
callback: F,
|
||||||
|
) -> Rc<Self> {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use super::selector_row::SelectorRow;
|
use super::selector_row::SelectorRow;
|
||||||
use super::{InstrumentSelector, PersonSelector, PartEditor};
|
use super::{InstrumentSelector, PersonSelector, PartEditor, SectionEditor};
|
||||||
use crate::database::*;
|
use crate::database::*;
|
||||||
use glib::clone;
|
use glib::clone;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
|
|
@ -226,17 +226,15 @@ impl WorkEditor {
|
||||||
})).show();
|
})).show();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
remove_part_button.connect_clicked(clone!(@strong result => move |_| {
|
add_section_button.connect_clicked(clone!(@strong result => move |_| {
|
||||||
let row = result.get_selected_part_row();
|
SectionEditor::new(&result.window, None, clone!(@strong result => move |section| {
|
||||||
match row {
|
{
|
||||||
Some(row) => {
|
let mut structure = result.structure.borrow_mut();
|
||||||
let index = row.get_index();
|
structure.push(PartOrSection::section(section));
|
||||||
let index: usize = index.try_into().unwrap();
|
|
||||||
result.structure.borrow_mut().remove(index);
|
|
||||||
result.show_parts();
|
|
||||||
}
|
}
|
||||||
None => (),
|
|
||||||
}
|
result.show_parts();
|
||||||
|
})).show();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
edit_part_button.connect_clicked(clone!(@strong result => move |_| {
|
edit_part_button.connect_clicked(clone!(@strong result => move |_| {
|
||||||
|
|
@ -245,15 +243,38 @@ impl WorkEditor {
|
||||||
Some(row) => {
|
Some(row) => {
|
||||||
let index = row.get_index();
|
let index = row.get_index();
|
||||||
let index: usize = index.try_into().unwrap();
|
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 =
|
editor.show();
|
||||||
PartEditor::new(result.db.clone(), &result.window, Some(part.unwrap_part()), clone!(@strong result => move |part| {
|
} else {
|
||||||
result.structure.borrow_mut()[index] = PartOrSection::part(part);
|
let editor =
|
||||||
result.show_parts();
|
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 => (),
|
None => (),
|
||||||
}
|
}
|
||||||
|
|
@ -330,6 +351,15 @@ impl WorkEditor {
|
||||||
for (index, part) in self.structure.borrow().iter().enumerate() {
|
for (index, part) in self.structure.borrow().iter().enumerate() {
|
||||||
let label = gtk::Label::new(Some(&part.get_title()));
|
let label = gtk::Label::new(Some(&part.get_title()));
|
||||||
label.set_halign(gtk::Align::Start);
|
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);
|
let row = SelectorRow::new(index.try_into().unwrap(), &label);
|
||||||
row.show_all();
|
row.show_all();
|
||||||
self.part_list.insert(&row, -1);
|
self.part_list.insert(&row, -1);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue