mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Merge work selector and editor to single dialog
This commit is contained in:
parent
9ee7bf166d
commit
d20d80d1ac
26 changed files with 1559 additions and 1742 deletions
63
src/dialogs/work/work_editor_dialog.rs
Normal file
63
src/dialogs/work/work_editor_dialog.rs
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
use super::work_editor::*;
|
||||
use crate::backend::*;
|
||||
use crate::database::*;
|
||||
use glib::clone;
|
||||
use gtk::prelude::*;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
/// A dialog for creating or editing a work.
|
||||
pub struct WorkEditorDialog {
|
||||
pub window: libhandy::Window,
|
||||
saved_cb: RefCell<Option<Box<dyn Fn(WorkDescription) -> ()>>>,
|
||||
}
|
||||
|
||||
impl WorkEditorDialog {
|
||||
/// Create a new work editor dialog and optionally initialize it.
|
||||
pub fn new<W: IsA<gtk::Window>>(
|
||||
backend: Rc<Backend>,
|
||||
parent: &W,
|
||||
work: Option<WorkDescription>,
|
||||
) -> Rc<Self> {
|
||||
// Create UI
|
||||
|
||||
let window = libhandy::Window::new();
|
||||
window.set_type_hint(gdk::WindowTypeHint::Dialog);
|
||||
window.set_modal(true);
|
||||
window.set_transient_for(Some(parent));
|
||||
|
||||
let editor = WorkEditor::new(backend.clone(), &window, work);
|
||||
window.add(&editor.widget);
|
||||
window.show_all();
|
||||
|
||||
let this = Rc::new(Self {
|
||||
window,
|
||||
saved_cb: RefCell::new(None),
|
||||
});
|
||||
|
||||
// Connect signals and callbacks
|
||||
|
||||
editor.set_cancel_cb(clone!(@strong this => move || {
|
||||
this.window.close();
|
||||
}));
|
||||
|
||||
editor.set_saved_cb(clone!(@strong this => move |work| {
|
||||
if let Some(cb) = &*this.saved_cb.borrow() {
|
||||
cb(work);
|
||||
this.window.close();
|
||||
}
|
||||
}));
|
||||
|
||||
this
|
||||
}
|
||||
|
||||
/// Set the closure to be called when the user edited or created a work.
|
||||
pub fn set_saved_cb<F: Fn(WorkDescription) -> () + 'static>(&self, cb: F) {
|
||||
self.saved_cb.replace(Some(Box::new(cb)));
|
||||
}
|
||||
|
||||
/// Show the work editor dialog.
|
||||
pub fn show(&self) {
|
||||
self.window.show();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue