mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 19:57:25 +01:00
Use new editor widget for instruments and ensembles
This commit is contained in:
parent
499fc87a59
commit
eac168880d
7 changed files with 76 additions and 489 deletions
|
|
@ -2,12 +2,9 @@
|
||||||
<gresources>
|
<gresources>
|
||||||
<gresource prefix="/de/johrpan/musicus">
|
<gresource prefix="/de/johrpan/musicus">
|
||||||
<file preprocess="xml-stripblanks">ui/editor.ui</file>
|
<file preprocess="xml-stripblanks">ui/editor.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/ensemble_editor.ui</file>
|
|
||||||
<file preprocess="xml-stripblanks">ui/instrument_editor.ui</file>
|
|
||||||
<file preprocess="xml-stripblanks">ui/login_dialog.ui</file>
|
<file preprocess="xml-stripblanks">ui/login_dialog.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/medium_editor.ui</file>
|
<file preprocess="xml-stripblanks">ui/medium_editor.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/performance_editor.ui</file>
|
<file preprocess="xml-stripblanks">ui/performance_editor.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/person_editor.ui</file>
|
|
||||||
<file preprocess="xml-stripblanks">ui/player_bar.ui</file>
|
<file preprocess="xml-stripblanks">ui/player_bar.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/player_screen.ui</file>
|
<file preprocess="xml-stripblanks">ui/player_screen.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/poe_list.ui</file>
|
<file preprocess="xml-stripblanks">ui/poe_list.ui</file>
|
||||||
|
|
|
||||||
|
|
@ -1,134 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<interface>
|
|
||||||
<requires lib="gtk" version="4.0"/>
|
|
||||||
<requires lib="libadwaita" version="1.0"/>
|
|
||||||
<object class="GtkStack" id="widget">
|
|
||||||
<property name="transition-type">crossfade</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkStackPage">
|
|
||||||
<property name="name">content</property>
|
|
||||||
<property name="child">
|
|
||||||
<object class="GtkBox">
|
|
||||||
<property name="orientation">vertical</property>
|
|
||||||
<child>
|
|
||||||
<object class="AdwHeaderBar">
|
|
||||||
<property name="show-start-title-buttons">false</property>
|
|
||||||
<property name="show-end-title-buttons">false</property>
|
|
||||||
<property name="title-widget">
|
|
||||||
<object class="GtkLabel">
|
|
||||||
<property name="label" translatable="yes">Ensemble</property>
|
|
||||||
<style>
|
|
||||||
<class name="title"/>
|
|
||||||
</style>
|
|
||||||
</object>
|
|
||||||
</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkButton" id="back_button">
|
|
||||||
<property name="icon-name">go-previous-symbolic</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child type="end">
|
|
||||||
<object class="GtkButton" id="save_button">
|
|
||||||
<property name="icon-name">object-select-symbolic</property>
|
|
||||||
<style>
|
|
||||||
<class name="suggested-action"/>
|
|
||||||
</style>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkInfoBar" id="info_bar">
|
|
||||||
<property name="revealed">False</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkScrolledWindow">
|
|
||||||
<property name="vexpand">true</property>
|
|
||||||
<child>
|
|
||||||
<object class="AdwClamp">
|
|
||||||
<property name="margin-start">12</property>
|
|
||||||
<property name="margin-end">12</property>
|
|
||||||
<property name="margin-top">18</property>
|
|
||||||
<property name="margin-bottom">12</property>
|
|
||||||
<property name="maximum-size">500</property>
|
|
||||||
<property name="tightening-threshold">300</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkFrame">
|
|
||||||
<property name="valign">start</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkListBox">
|
|
||||||
<property name="selection-mode">none</property>
|
|
||||||
<child>
|
|
||||||
<object class="AdwActionRow">
|
|
||||||
<property name="activatable">True</property>
|
|
||||||
<property name="title" translatable="yes">Name</property>
|
|
||||||
<property name="activatable-widget">name_entry</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkEntry" id="name_entry">
|
|
||||||
<property name="valign">center</property>
|
|
||||||
<property name="hexpand">True</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="AdwActionRow">
|
|
||||||
<property name="activatable">True</property>
|
|
||||||
<property name="title" translatable="yes">Publish to the server</property>
|
|
||||||
<property name="activatable-widget">upload_switch</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkSwitch" id="upload_switch">
|
|
||||||
<property name="valign">center</property>
|
|
||||||
<property name="active">True</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkStackPage">
|
|
||||||
<property name="name">loading</property>
|
|
||||||
<property name="child">
|
|
||||||
<object class="GtkBox">
|
|
||||||
<property name="orientation">vertical</property>
|
|
||||||
<child>
|
|
||||||
<object class="AdwHeaderBar">
|
|
||||||
<property name="show-start-title-buttons">false</property>
|
|
||||||
<property name="show-end-title-buttons">false</property>
|
|
||||||
<property name="title-widget">
|
|
||||||
<object class="GtkLabel">
|
|
||||||
<property name="label" translatable="yes">Ensemble</property>
|
|
||||||
<style>
|
|
||||||
<class name="title"/>
|
|
||||||
</style>
|
|
||||||
</object>
|
|
||||||
</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkSpinner">
|
|
||||||
<property name="spinning">true</property>
|
|
||||||
<property name="hexpand">true</property>
|
|
||||||
<property name="vexpand">true</property>
|
|
||||||
<property name="halign">center</property>
|
|
||||||
<property name="valign">center</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</interface>
|
|
||||||
|
|
@ -1,134 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<interface>
|
|
||||||
<requires lib="gtk" version="4.0"/>
|
|
||||||
<requires lib="libadwaita" version="1.0"/>
|
|
||||||
<object class="GtkStack" id="widget">
|
|
||||||
<property name="transition-type">crossfade</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkStackPage">
|
|
||||||
<property name="name">content</property>
|
|
||||||
<property name="child">
|
|
||||||
<object class="GtkBox">
|
|
||||||
<property name="orientation">vertical</property>
|
|
||||||
<child>
|
|
||||||
<object class="AdwHeaderBar">
|
|
||||||
<property name="show-start-title-buttons">false</property>
|
|
||||||
<property name="show-end-title-buttons">false</property>
|
|
||||||
<property name="title-widget">
|
|
||||||
<object class="GtkLabel">
|
|
||||||
<property name="label" translatable="yes">Instrument</property>
|
|
||||||
<style>
|
|
||||||
<class name="title"/>
|
|
||||||
</style>
|
|
||||||
</object>
|
|
||||||
</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkButton" id="back_button">
|
|
||||||
<property name="icon-name">go-previous-symbolic</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child type="end">
|
|
||||||
<object class="GtkButton" id="save_button">
|
|
||||||
<property name="icon-name">object-select-symbolic</property>
|
|
||||||
<style>
|
|
||||||
<class name="suggested-action"/>
|
|
||||||
</style>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkInfoBar" id="info_bar">
|
|
||||||
<property name="revealed">False</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkScrolledWindow">
|
|
||||||
<property name="vexpand">true</property>
|
|
||||||
<child>
|
|
||||||
<object class="AdwClamp">
|
|
||||||
<property name="margin-start">12</property>
|
|
||||||
<property name="margin-end">12</property>
|
|
||||||
<property name="margin-top">18</property>
|
|
||||||
<property name="margin-bottom">12</property>
|
|
||||||
<property name="maximum-size">500</property>
|
|
||||||
<property name="tightening-threshold">300</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkFrame">
|
|
||||||
<property name="valign">start</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkListBox">
|
|
||||||
<property name="selection-mode">none</property>
|
|
||||||
<child>
|
|
||||||
<object class="AdwActionRow">
|
|
||||||
<property name="activatable">True</property>
|
|
||||||
<property name="title" translatable="yes">Name</property>
|
|
||||||
<property name="activatable-widget">name_entry</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkEntry" id="name_entry">
|
|
||||||
<property name="valign">center</property>
|
|
||||||
<property name="hexpand">True</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="AdwActionRow">
|
|
||||||
<property name="activatable">True</property>
|
|
||||||
<property name="title" translatable="yes">Publish to the server</property>
|
|
||||||
<property name="activatable-widget">upload_switch</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkSwitch" id="upload_switch">
|
|
||||||
<property name="valign">center</property>
|
|
||||||
<property name="active">True</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkStackPage">
|
|
||||||
<property name="name">loading</property>
|
|
||||||
<property name="child">
|
|
||||||
<object class="GtkBox">
|
|
||||||
<property name="orientation">vertical</property>
|
|
||||||
<child>
|
|
||||||
<object class="AdwHeaderBar">
|
|
||||||
<property name="show-start-title-buttons">false</property>
|
|
||||||
<property name="show-end-title-buttons">false</property>
|
|
||||||
<property name="title-widget">
|
|
||||||
<object class="GtkLabel">
|
|
||||||
<property name="label" translatable="yes">Instrument</property>
|
|
||||||
<style>
|
|
||||||
<class name="title"/>
|
|
||||||
</style>
|
|
||||||
</object>
|
|
||||||
</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkSpinner">
|
|
||||||
<property name="spinning">true</property>
|
|
||||||
<property name="hexpand">true</property>
|
|
||||||
<property name="vexpand">true</property>
|
|
||||||
<property name="halign">center</property>
|
|
||||||
<property name="valign">center</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</interface>
|
|
||||||
|
|
@ -1,147 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<interface>
|
|
||||||
<requires lib="gtk" version="4.0"/>
|
|
||||||
<requires lib="libadwaita" version="1.0"/>
|
|
||||||
<object class="GtkStack" id="widget">
|
|
||||||
<property name="transition-type">crossfade</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkStackPage">
|
|
||||||
<property name="name">content</property>
|
|
||||||
<property name="child">
|
|
||||||
<object class="GtkBox">
|
|
||||||
<property name="orientation">vertical</property>
|
|
||||||
<child>
|
|
||||||
<object class="AdwHeaderBar">
|
|
||||||
<property name="show-start-title-buttons">false</property>
|
|
||||||
<property name="show-end-title-buttons">false</property>
|
|
||||||
<property name="title-widget">
|
|
||||||
<object class="GtkLabel">
|
|
||||||
<property name="label" translatable="yes">Person</property>
|
|
||||||
<style>
|
|
||||||
<class name="title"/>
|
|
||||||
</style>
|
|
||||||
</object>
|
|
||||||
</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkButton" id="back_button">
|
|
||||||
<property name="icon-name">go-previous-symbolic</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child type="end">
|
|
||||||
<object class="GtkButton" id="save_button">
|
|
||||||
<property name="icon-name">object-select-symbolic</property>
|
|
||||||
<style>
|
|
||||||
<class name="suggested-action"/>
|
|
||||||
</style>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkInfoBar" id="info_bar">
|
|
||||||
<property name="revealed">False</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkScrolledWindow">
|
|
||||||
<property name="vexpand">true</property>
|
|
||||||
<child>
|
|
||||||
<object class="AdwClamp">
|
|
||||||
<property name="margin-start">12</property>
|
|
||||||
<property name="margin-end">12</property>
|
|
||||||
<property name="margin-top">18</property>
|
|
||||||
<property name="margin-bottom">12</property>
|
|
||||||
<property name="maximum-size">500</property>
|
|
||||||
<property name="tightening-threshold">300</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkFrame">
|
|
||||||
<property name="valign">start</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkListBox">
|
|
||||||
<property name="selection-mode">none</property>
|
|
||||||
<child>
|
|
||||||
<object class="AdwActionRow">
|
|
||||||
<property name="activatable">True</property>
|
|
||||||
<property name="title" translatable="yes">First name</property>
|
|
||||||
<property name="activatable-widget">first_name_entry</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkEntry" id="first_name_entry">
|
|
||||||
<property name="valign">center</property>
|
|
||||||
<property name="hexpand">True</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="AdwActionRow">
|
|
||||||
<property name="activatable">True</property>
|
|
||||||
<property name="title" translatable="yes">Last name</property>
|
|
||||||
<property name="activatable-widget">last_name_entry</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkEntry" id="last_name_entry">
|
|
||||||
<property name="valign">center</property>
|
|
||||||
<property name="hexpand">True</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="AdwActionRow">
|
|
||||||
<property name="activatable">True</property>
|
|
||||||
<property name="title" translatable="yes">Publish to the server</property>
|
|
||||||
<property name="activatable-widget">upload_switch</property>
|
|
||||||
<child>
|
|
||||||
<object class="GtkSwitch" id="upload_switch">
|
|
||||||
<property name="valign">center</property>
|
|
||||||
<property name="active">True</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkStackPage">
|
|
||||||
<property name="name">loading</property>
|
|
||||||
<property name="child">
|
|
||||||
<object class="GtkBox">
|
|
||||||
<property name="orientation">vertical</property>
|
|
||||||
<child>
|
|
||||||
<object class="AdwHeaderBar">
|
|
||||||
<property name="show-start-title-buttons">false</property>
|
|
||||||
<property name="show-end-title-buttons">false</property>
|
|
||||||
<property name="title-widget">
|
|
||||||
<object class="GtkLabel">
|
|
||||||
<property name="label" translatable="yes">Person</property>
|
|
||||||
<style>
|
|
||||||
<class name="title"/>
|
|
||||||
</style>
|
|
||||||
</object>
|
|
||||||
</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
<child>
|
|
||||||
<object class="GtkSpinner">
|
|
||||||
<property name="spinning">true</property>
|
|
||||||
<property name="hexpand">true</property>
|
|
||||||
<property name="vexpand">true</property>
|
|
||||||
<property name="halign">center</property>
|
|
||||||
<property name="valign">center</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</property>
|
|
||||||
</object>
|
|
||||||
</child>
|
|
||||||
</object>
|
|
||||||
</interface>
|
|
||||||
|
|
@ -1,21 +1,24 @@
|
||||||
use crate::backend::Backend;
|
use crate::backend::Backend;
|
||||||
use crate::database::*;
|
use crate::database::generate_id;
|
||||||
use crate::widgets::{Navigator, NavigatorScreen};
|
use crate::database::Ensemble;
|
||||||
|
use crate::widgets::{Editor, EntryRow, Navigator, NavigatorScreen, Section, UploadSection};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use gettextrs::gettext;
|
||||||
use glib::clone;
|
use glib::clone;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk_macros::get_widget;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
/// A dialog for creating or editing a ensemble.
|
/// A dialog for creating or editing a ensemble.
|
||||||
pub struct EnsembleEditor {
|
pub struct EnsembleEditor {
|
||||||
backend: Rc<Backend>,
|
backend: Rc<Backend>,
|
||||||
|
|
||||||
|
/// The ID of the ensemble that is edited or a newly generated one.
|
||||||
id: String,
|
id: String,
|
||||||
widget: gtk::Stack,
|
|
||||||
info_bar: gtk::InfoBar,
|
editor: Editor,
|
||||||
name_entry: gtk::Entry,
|
name: EntryRow,
|
||||||
upload_switch: gtk::Switch,
|
upload: UploadSection,
|
||||||
saved_cb: RefCell<Option<Box<dyn Fn(Ensemble) -> ()>>>,
|
saved_cb: RefCell<Option<Box<dyn Fn(Ensemble) -> ()>>>,
|
||||||
navigator: RefCell<Option<Rc<Navigator>>>,
|
navigator: RefCell<Option<Rc<Navigator>>>,
|
||||||
}
|
}
|
||||||
|
|
@ -23,21 +26,25 @@ pub struct EnsembleEditor {
|
||||||
impl EnsembleEditor {
|
impl EnsembleEditor {
|
||||||
/// Create a new ensemble editor and optionally initialize it.
|
/// Create a new ensemble editor and optionally initialize it.
|
||||||
pub fn new(backend: Rc<Backend>, ensemble: Option<Ensemble>) -> Rc<Self> {
|
pub fn new(backend: Rc<Backend>, ensemble: Option<Ensemble>) -> Rc<Self> {
|
||||||
// Create UI
|
let editor = Editor::new();
|
||||||
|
editor.set_title("Ensemble");
|
||||||
|
|
||||||
let builder = gtk::Builder::from_resource("/de/johrpan/musicus/ui/ensemble_editor.ui");
|
let list = gtk::ListBoxBuilder::new()
|
||||||
|
.selection_mode(gtk::SelectionMode::None)
|
||||||
|
.build();
|
||||||
|
|
||||||
get_widget!(builder, gtk::Stack, widget);
|
let name = EntryRow::new(&gettext("Name"));
|
||||||
get_widget!(builder, gtk::Button, back_button);
|
list.append(&name.widget);
|
||||||
get_widget!(builder, gtk::Button, save_button);
|
|
||||||
get_widget!(builder, gtk::InfoBar, info_bar);
|
let section = Section::new(&gettext("General"), &list);
|
||||||
get_widget!(builder, gtk::Entry, name_entry);
|
let upload = UploadSection::new();
|
||||||
get_widget!(builder, gtk::Switch, upload_switch);
|
|
||||||
|
editor.add_content(§ion.widget);
|
||||||
|
editor.add_content(&upload.widget);
|
||||||
|
|
||||||
let id = match ensemble {
|
let id = match ensemble {
|
||||||
Some(ensemble) => {
|
Some(ensemble) => {
|
||||||
name_entry.set_text(&ensemble.name);
|
name.set_text(&ensemble.name);
|
||||||
|
|
||||||
ensemble.id
|
ensemble.id
|
||||||
}
|
}
|
||||||
None => generate_id(),
|
None => generate_id(),
|
||||||
|
|
@ -46,28 +53,27 @@ impl EnsembleEditor {
|
||||||
let this = Rc::new(Self {
|
let this = Rc::new(Self {
|
||||||
backend,
|
backend,
|
||||||
id,
|
id,
|
||||||
widget,
|
editor,
|
||||||
info_bar,
|
name,
|
||||||
name_entry,
|
upload,
|
||||||
upload_switch,
|
|
||||||
saved_cb: RefCell::new(None),
|
saved_cb: RefCell::new(None),
|
||||||
navigator: RefCell::new(None),
|
navigator: RefCell::new(None),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Connect signals and callbacks
|
// Connect signals and callbacks
|
||||||
|
|
||||||
back_button.connect_clicked(clone!(@strong this => move |_| {
|
this.editor.set_back_cb(clone!(@strong this => move || {
|
||||||
let navigator = this.navigator.borrow().clone();
|
let navigator = this.navigator.borrow().clone();
|
||||||
if let Some(navigator) = navigator {
|
if let Some(navigator) = navigator {
|
||||||
navigator.pop();
|
navigator.pop();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
save_button.connect_clicked(clone!(@strong this => move |_| {
|
this.editor.set_save_cb(clone!(@strong this => move || {
|
||||||
let context = glib::MainContext::default();
|
let context = glib::MainContext::default();
|
||||||
let clone = this.clone();
|
let clone = this.clone();
|
||||||
context.spawn_local(async move {
|
context.spawn_local(async move {
|
||||||
clone.widget.set_visible_child_name("loading");
|
clone.editor.loading();
|
||||||
match clone.clone().save().await {
|
match clone.clone().save().await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let navigator = clone.navigator.borrow().clone();
|
let navigator = clone.navigator.borrow().clone();
|
||||||
|
|
@ -75,9 +81,9 @@ impl EnsembleEditor {
|
||||||
navigator.pop();
|
navigator.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(err) => {
|
||||||
clone.info_bar.set_revealed(true);
|
let description = gettext!("Cause: {}", err);
|
||||||
clone.widget.set_visible_child_name("content");
|
clone.editor.error(&gettext("Failed to save ensemble!"), &description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,22 +100,18 @@ impl EnsembleEditor {
|
||||||
|
|
||||||
/// Save the ensemble and possibly upload it to the server.
|
/// Save the ensemble and possibly upload it to the server.
|
||||||
async fn save(self: Rc<Self>) -> Result<()> {
|
async fn save(self: Rc<Self>) -> Result<()> {
|
||||||
let name = self.name_entry.get_text().unwrap().to_string();
|
let name = self.name.get_text();
|
||||||
|
|
||||||
let ensemble = Ensemble {
|
let ensemble = Ensemble {
|
||||||
id: self.id.clone(),
|
id: self.id.clone(),
|
||||||
name,
|
name,
|
||||||
};
|
};
|
||||||
|
|
||||||
let upload = self.upload_switch.get_active();
|
if self.upload.get_active() {
|
||||||
if upload {
|
|
||||||
self.backend.post_ensemble(&ensemble).await?;
|
self.backend.post_ensemble(&ensemble).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.backend
|
self.backend.db().update_ensemble(ensemble.clone()).await?;
|
||||||
.db()
|
|
||||||
.update_ensemble(ensemble.clone())
|
|
||||||
.await?;
|
|
||||||
self.backend.library_changed();
|
self.backend.library_changed();
|
||||||
|
|
||||||
if let Some(cb) = &*self.saved_cb.borrow() {
|
if let Some(cb) = &*self.saved_cb.borrow() {
|
||||||
|
|
@ -126,10 +128,11 @@ impl NavigatorScreen for EnsembleEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_widget(&self) -> gtk::Widget {
|
fn get_widget(&self) -> gtk::Widget {
|
||||||
self.widget.clone().upcast()
|
self.editor.widget.clone().upcast()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn detach_navigator(&self) {
|
fn detach_navigator(&self) {
|
||||||
self.navigator.replace(None);
|
self.navigator.replace(None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,21 +1,24 @@
|
||||||
use crate::backend::Backend;
|
use crate::backend::Backend;
|
||||||
use crate::database::*;
|
use crate::database::generate_id;
|
||||||
use crate::widgets::{Navigator, NavigatorScreen};
|
use crate::database::Instrument;
|
||||||
|
use crate::widgets::{Editor, EntryRow, Navigator, NavigatorScreen, Section, UploadSection};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use gettextrs::gettext;
|
||||||
use glib::clone;
|
use glib::clone;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk_macros::get_widget;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
/// A dialog for creating or editing a instrument.
|
/// A dialog for creating or editing a instrument.
|
||||||
pub struct InstrumentEditor {
|
pub struct InstrumentEditor {
|
||||||
backend: Rc<Backend>,
|
backend: Rc<Backend>,
|
||||||
|
|
||||||
|
/// The ID of the instrument that is edited or a newly generated one.
|
||||||
id: String,
|
id: String,
|
||||||
widget: gtk::Stack,
|
|
||||||
info_bar: gtk::InfoBar,
|
editor: Editor,
|
||||||
name_entry: gtk::Entry,
|
name: EntryRow,
|
||||||
upload_switch: gtk::Switch,
|
upload: UploadSection,
|
||||||
saved_cb: RefCell<Option<Box<dyn Fn(Instrument) -> ()>>>,
|
saved_cb: RefCell<Option<Box<dyn Fn(Instrument) -> ()>>>,
|
||||||
navigator: RefCell<Option<Rc<Navigator>>>,
|
navigator: RefCell<Option<Rc<Navigator>>>,
|
||||||
}
|
}
|
||||||
|
|
@ -23,21 +26,25 @@ pub struct InstrumentEditor {
|
||||||
impl InstrumentEditor {
|
impl InstrumentEditor {
|
||||||
/// Create a new instrument editor and optionally initialize it.
|
/// Create a new instrument editor and optionally initialize it.
|
||||||
pub fn new(backend: Rc<Backend>, instrument: Option<Instrument>) -> Rc<Self> {
|
pub fn new(backend: Rc<Backend>, instrument: Option<Instrument>) -> Rc<Self> {
|
||||||
// Create UI
|
let editor = Editor::new();
|
||||||
|
editor.set_title("Instrument/Role");
|
||||||
|
|
||||||
let builder = gtk::Builder::from_resource("/de/johrpan/musicus/ui/instrument_editor.ui");
|
let list = gtk::ListBoxBuilder::new()
|
||||||
|
.selection_mode(gtk::SelectionMode::None)
|
||||||
|
.build();
|
||||||
|
|
||||||
get_widget!(builder, gtk::Stack, widget);
|
let name = EntryRow::new(&gettext("Name"));
|
||||||
get_widget!(builder, gtk::Button, back_button);
|
list.append(&name.widget);
|
||||||
get_widget!(builder, gtk::Button, save_button);
|
|
||||||
get_widget!(builder, gtk::InfoBar, info_bar);
|
let section = Section::new(&gettext("General"), &list);
|
||||||
get_widget!(builder, gtk::Entry, name_entry);
|
let upload = UploadSection::new();
|
||||||
get_widget!(builder, gtk::Switch, upload_switch);
|
|
||||||
|
editor.add_content(§ion.widget);
|
||||||
|
editor.add_content(&upload.widget);
|
||||||
|
|
||||||
let id = match instrument {
|
let id = match instrument {
|
||||||
Some(instrument) => {
|
Some(instrument) => {
|
||||||
name_entry.set_text(&instrument.name);
|
name.set_text(&instrument.name);
|
||||||
|
|
||||||
instrument.id
|
instrument.id
|
||||||
}
|
}
|
||||||
None => generate_id(),
|
None => generate_id(),
|
||||||
|
|
@ -46,28 +53,27 @@ impl InstrumentEditor {
|
||||||
let this = Rc::new(Self {
|
let this = Rc::new(Self {
|
||||||
backend,
|
backend,
|
||||||
id,
|
id,
|
||||||
widget,
|
editor,
|
||||||
info_bar,
|
name,
|
||||||
name_entry,
|
upload,
|
||||||
upload_switch,
|
|
||||||
saved_cb: RefCell::new(None),
|
saved_cb: RefCell::new(None),
|
||||||
navigator: RefCell::new(None),
|
navigator: RefCell::new(None),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Connect signals and callbacks
|
// Connect signals and callbacks
|
||||||
|
|
||||||
back_button.connect_clicked(clone!(@strong this => move |_| {
|
this.editor.set_back_cb(clone!(@strong this => move || {
|
||||||
let navigator = this.navigator.borrow().clone();
|
let navigator = this.navigator.borrow().clone();
|
||||||
if let Some(navigator) = navigator {
|
if let Some(navigator) = navigator {
|
||||||
navigator.pop();
|
navigator.pop();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
save_button.connect_clicked(clone!(@strong this => move |_| {
|
this.editor.set_save_cb(clone!(@strong this => move || {
|
||||||
let context = glib::MainContext::default();
|
let context = glib::MainContext::default();
|
||||||
let clone = this.clone();
|
let clone = this.clone();
|
||||||
context.spawn_local(async move {
|
context.spawn_local(async move {
|
||||||
clone.widget.set_visible_child_name("loading");
|
clone.editor.loading();
|
||||||
match clone.clone().save().await {
|
match clone.clone().save().await {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
let navigator = clone.navigator.borrow().clone();
|
let navigator = clone.navigator.borrow().clone();
|
||||||
|
|
@ -75,9 +81,9 @@ impl InstrumentEditor {
|
||||||
navigator.pop();
|
navigator.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(err) => {
|
||||||
clone.info_bar.set_revealed(true);
|
let description = gettext!("Cause: {}", err);
|
||||||
clone.widget.set_visible_child_name("content");
|
clone.editor.error(&gettext("Failed to save instrument!"), &description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,22 +100,18 @@ impl InstrumentEditor {
|
||||||
|
|
||||||
/// Save the instrument and possibly upload it to the server.
|
/// Save the instrument and possibly upload it to the server.
|
||||||
async fn save(self: Rc<Self>) -> Result<()> {
|
async fn save(self: Rc<Self>) -> Result<()> {
|
||||||
let name = self.name_entry.get_text().unwrap().to_string();
|
let name = self.name.get_text();
|
||||||
|
|
||||||
let instrument = Instrument {
|
let instrument = Instrument {
|
||||||
id: self.id.clone(),
|
id: self.id.clone(),
|
||||||
name,
|
name,
|
||||||
};
|
};
|
||||||
|
|
||||||
let upload = self.upload_switch.get_active();
|
if self.upload.get_active() {
|
||||||
if upload {
|
|
||||||
self.backend.post_instrument(&instrument).await?;
|
self.backend.post_instrument(&instrument).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.backend
|
self.backend.db().update_instrument(instrument.clone()).await?;
|
||||||
.db()
|
|
||||||
.update_instrument(instrument.clone())
|
|
||||||
.await?;
|
|
||||||
self.backend.library_changed();
|
self.backend.library_changed();
|
||||||
|
|
||||||
if let Some(cb) = &*self.saved_cb.borrow() {
|
if let Some(cb) = &*self.saved_cb.borrow() {
|
||||||
|
|
@ -126,10 +128,11 @@ impl NavigatorScreen for InstrumentEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_widget(&self) -> gtk::Widget {
|
fn get_widget(&self) -> gtk::Widget {
|
||||||
self.widget.clone().upcast()
|
self.editor.widget.clone().upcast()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn detach_navigator(&self) {
|
fn detach_navigator(&self) {
|
||||||
self.navigator.replace(None);
|
self.navigator.replace(None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ use anyhow::Result;
|
||||||
use gettextrs::gettext;
|
use gettextrs::gettext;
|
||||||
use glib::clone;
|
use glib::clone;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk_macros::get_widget;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue