mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Add ensemble editor dialog
This commit is contained in:
parent
1a6a6f7450
commit
44cb9fa410
5 changed files with 152 additions and 3 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<gresources>
|
<gresources>
|
||||||
<gresource prefix="/de/johrpan/musicus_editor">
|
<gresource prefix="/de/johrpan/musicus_editor">
|
||||||
|
<file preprocess="xml-stripblanks">ui/ensemble_editor.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/instrument_editor.ui</file>
|
<file preprocess="xml-stripblanks">ui/instrument_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/window.ui</file>
|
<file preprocess="xml-stripblanks">ui/window.ui</file>
|
||||||
|
|
|
||||||
73
res/ui/ensemble_editor.ui
Normal file
73
res/ui/ensemble_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">Name</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="left_attach">0</property>
|
||||||
|
<property name="top_attach">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkEntry" id="name_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">Ensemble</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>
|
||||||
66
src/dialogs/ensemble_editor.rs
Normal file
66
src/dialogs/ensemble_editor.rs
Normal file
|
|
@ -0,0 +1,66 @@
|
||||||
|
use crate::database::*;
|
||||||
|
use glib::clone;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
use gtk_macros::get_widget;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
pub struct EnsembleEditor {
|
||||||
|
window: gtk::Window,
|
||||||
|
id: i64,
|
||||||
|
name_entry: gtk::Entry,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EnsembleEditor {
|
||||||
|
pub fn new<F: Fn(Ensemble) -> () + 'static, P: IsA<gtk::Window>>(
|
||||||
|
db: Rc<Database>,
|
||||||
|
parent: &P,
|
||||||
|
ensemble: Option<Ensemble>,
|
||||||
|
callback: F,
|
||||||
|
) -> Rc<Self> {
|
||||||
|
let builder =
|
||||||
|
gtk::Builder::from_resource("/de/johrpan/musicus_editor/ui/ensemble_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, name_entry);
|
||||||
|
|
||||||
|
let id = match ensemble {
|
||||||
|
Some(ensemble) => {
|
||||||
|
name_entry.set_text(&ensemble.name);
|
||||||
|
ensemble.id
|
||||||
|
}
|
||||||
|
None => rand::random::<u32>().into(),
|
||||||
|
};
|
||||||
|
|
||||||
|
let result = Rc::new(EnsembleEditor {
|
||||||
|
id: id,
|
||||||
|
window: window,
|
||||||
|
name_entry: name_entry,
|
||||||
|
});
|
||||||
|
|
||||||
|
cancel_button.connect_clicked(clone!(@strong result => move |_| {
|
||||||
|
result.window.close();
|
||||||
|
}));
|
||||||
|
|
||||||
|
save_button.connect_clicked(clone!(@strong result => move |_| {
|
||||||
|
result.window.close();
|
||||||
|
|
||||||
|
let ensemble = Ensemble {
|
||||||
|
id: result.id,
|
||||||
|
name: result.name_entry.get_text().to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
db.update_ensemble(ensemble.clone());
|
||||||
|
callback(ensemble);
|
||||||
|
}));
|
||||||
|
|
||||||
|
result.window.set_transient_for(Some(parent));
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn show(&self) {
|
||||||
|
self.window.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
pub mod ensemble_editor;
|
||||||
|
pub use ensemble_editor::*;
|
||||||
|
|
||||||
pub mod instrument_editor;
|
pub mod instrument_editor;
|
||||||
pub use instrument_editor::*;
|
pub use instrument_editor::*;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,9 +48,15 @@ impl Window {
|
||||||
println!("TODO: Add work.");
|
println!("TODO: Add work.");
|
||||||
});
|
});
|
||||||
|
|
||||||
action!(result.window, "add-ensemble", |_, _| {
|
action!(
|
||||||
println!("TODO: Add ensemble.");
|
result.window,
|
||||||
});
|
"add-ensemble",
|
||||||
|
clone!(@strong result => move |_, _| {
|
||||||
|
EnsembleEditor::new(result.db.clone(), &result.window, None, |ensemble| {
|
||||||
|
println!("{:?}", ensemble);
|
||||||
|
}).show();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
action!(result.window, "add-recording", |_, _| {
|
action!(result.window, "add-recording", |_, _| {
|
||||||
println!("TODO: Add recording.");
|
println!("TODO: Add recording.");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue