mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-27 04:07:25 +01:00
Move desktop app to subdirectory
This commit is contained in:
parent
ea3bd35ffd
commit
775f3ffe90
109 changed files with 64 additions and 53 deletions
|
|
@ -1,80 +0,0 @@
|
|||
use crate::backend::*;
|
||||
use crate::database::*;
|
||||
use glib::clone;
|
||||
use gtk::prelude::*;
|
||||
use gtk_macros::get_widget;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct InstrumentEditor<F>
|
||||
where
|
||||
F: Fn(Instrument) -> () + 'static,
|
||||
{
|
||||
backend: Rc<Backend>,
|
||||
window: libhandy::Window,
|
||||
callback: F,
|
||||
id: i64,
|
||||
name_entry: gtk::Entry,
|
||||
}
|
||||
|
||||
impl<F> InstrumentEditor<F>
|
||||
where
|
||||
F: Fn(Instrument) -> () + 'static,
|
||||
{
|
||||
pub fn new<P: IsA<gtk::Window>>(
|
||||
backend: Rc<Backend>,
|
||||
parent: &P,
|
||||
instrument: Option<Instrument>,
|
||||
callback: F,
|
||||
) -> Rc<Self> {
|
||||
let builder =
|
||||
gtk::Builder::from_resource("/de/johrpan/musicus/ui/instrument_editor.ui");
|
||||
|
||||
get_widget!(builder, libhandy::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 instrument {
|
||||
Some(instrument) => {
|
||||
name_entry.set_text(&instrument.name);
|
||||
instrument.id
|
||||
}
|
||||
None => rand::random::<u32>().into(),
|
||||
};
|
||||
|
||||
let result = Rc::new(InstrumentEditor {
|
||||
backend: backend,
|
||||
window: window,
|
||||
callback: callback,
|
||||
id: id,
|
||||
name_entry: name_entry,
|
||||
});
|
||||
|
||||
cancel_button.connect_clicked(clone!(@strong result => move |_| {
|
||||
result.window.close();
|
||||
}));
|
||||
|
||||
save_button.connect_clicked(clone!(@strong result => move |_| {
|
||||
let instrument = Instrument {
|
||||
id: result.id,
|
||||
name: result.name_entry.get_text().to_string(),
|
||||
};
|
||||
|
||||
let c = glib::MainContext::default();
|
||||
let clone = result.clone();
|
||||
c.spawn_local(async move {
|
||||
clone.backend.update_instrument(instrument.clone()).await.unwrap();
|
||||
clone.window.close();
|
||||
(clone.callback)(instrument.clone());
|
||||
});
|
||||
}));
|
||||
|
||||
result.window.set_transient_for(Some(parent));
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
pub fn show(&self) {
|
||||
self.window.show();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue