Add preferences dialog

This commit is contained in:
Elias Projahn 2020-10-31 23:48:11 +01:00
parent b8911eafaa
commit cf96792029
7 changed files with 117 additions and 29 deletions

View file

@ -13,6 +13,7 @@
<file preprocess="xml-stripblanks">ui/person_screen.ui</file> <file preprocess="xml-stripblanks">ui/person_screen.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/poe_list.ui</file> <file preprocess="xml-stripblanks">ui/poe_list.ui</file>
<file preprocess="xml-stripblanks">ui/preferences.ui</file>
<file preprocess="xml-stripblanks">ui/recording_editor.ui</file> <file preprocess="xml-stripblanks">ui/recording_editor.ui</file>
<file preprocess="xml-stripblanks">ui/recording_screen.ui</file> <file preprocess="xml-stripblanks">ui/recording_screen.ui</file>
<file preprocess="xml-stripblanks">ui/recording_selector.ui</file> <file preprocess="xml-stripblanks">ui/recording_selector.ui</file>

44
res/ui/preferences.ui Normal file
View file

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.1 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<requires lib="libhandy" version="0.0"/>
<object class="HdyPreferencesWindow" id="window">
<property name="can-focus">False</property>
<property name="modal">True</property>
<property name="type-hint">dialog</property>
<child>
<object class="HdyPreferencesPage">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="title" translatable="yes">General</property>
<child>
<object class="HdyPreferencesGroup">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="title" translatable="yes">Music library</property>
<child>
<object class="HdyActionRow" id="music_library_path_row">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="selectable">False</property>
<property name="title" translatable="yes">Music library folder</property>
<property name="activatable-widget">select_music_library_path_button</property>
<property name="subtitle" translatable="yes">None selected</property>
<child>
<object class="GtkButton" id="select_music_library_path_button">
<property name="label" translatable="yes">Select</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="valign">center</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>

View file

@ -106,11 +106,10 @@
<property name="can-focus">False</property> <property name="can-focus">False</property>
<property name="show-close-button" bind-source="leaflet" bind-property="folded" bind-flags="sync-create">False</property> <property name="show-close-button" bind-source="leaflet" bind-property="folded" bind-flags="sync-create">False</property>
<child> <child>
<object class="GtkMenuButton"> <object class="GtkButton" id="add_button">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="receives-default">True</property> <property name="receives-default">True</property>
<property name="menu-model">add_menu</property>
<child> <child>
<object class="GtkImage"> <object class="GtkImage">
<property name="visible">True</property> <property name="visible">True</property>
@ -126,7 +125,7 @@
<property name="can-focus">True</property> <property name="can-focus">True</property>
<property name="focus-on-click">False</property> <property name="focus-on-click">False</property>
<property name="receives-default">True</property> <property name="receives-default">True</property>
<property name="menu-model">add_menu</property> <property name="menu-model">menu</property>
<child> <child>
<object class="GtkImage"> <object class="GtkImage">
<property name="visible">True</property> <property name="visible">True</property>
@ -171,31 +170,11 @@
</object> </object>
</child> </child>
</object> </object>
<menu id="add_menu"> <menu id="menu">
<section> <section>
<item> <item>
<attribute name="label" translatable="yes">Add person</attribute> <attribute name="label" translatable="yes">Preferences</attribute>
<attribute name="action">win.add-person</attribute> <attribute name="action">win.preferences</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Add instrument</attribute>
<attribute name="action">win.add-instrument</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Add work</attribute>
<attribute name="action">win.add-work</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Add ensemble</attribute>
<attribute name="action">win.add-ensemble</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Add recording</attribute>
<attribute name="action">win.add-recording</attribute>
</item>
<item>
<attribute name="label" translatable="yes">Add tracks</attribute>
<attribute name="action">win.add-tracks</attribute>
</item> </item>
</section> </section>
</menu> </menu>

View file

@ -314,8 +314,8 @@ impl Backend {
receiver.await? receiver.await?
} }
pub fn set_music_library_path(&self, path: &str) { pub fn set_music_library_path(&self, path: PathBuf) {
self.music_library_path.replace(Some(PathBuf::from(path))); self.music_library_path.replace(Some(path.clone()));
} }
pub fn get_music_library_path(&self) -> Option<PathBuf> { pub fn get_music_library_path(&self) -> Option<PathBuf> {

View file

@ -22,6 +22,9 @@ pub use person_editor::*;
pub mod person_selector; pub mod person_selector;
pub use person_selector::*; pub use person_selector::*;
pub mod preferences;
pub use preferences::*;
pub mod recording_editor; pub mod recording_editor;
pub use recording_editor::*; pub use recording_editor::*;

View file

@ -0,0 +1,43 @@
use crate::backend::Backend;
use glib::clone;
use gtk::prelude::*;
use gtk_macros::get_widget;
use libhandy::prelude::*;
use std::rc::Rc;
pub struct Preferences {
window: gtk::Window,
}
impl Preferences {
pub fn new<P: IsA<gtk::Window>>(backend: Rc<Backend>, parent: &P) -> Self {
let builder = gtk::Builder::from_resource("/de/johrpan/musicus_editor/ui/preferences.ui");
get_widget!(builder, gtk::Window, window);
get_widget!(builder, libhandy::ActionRow, music_library_path_row);
get_widget!(builder, gtk::Button, select_music_library_path_button);
window.set_transient_for(Some(parent));
if let Some(path) = backend.get_music_library_path() {
music_library_path_row.set_subtitle(Some(path.to_str().unwrap()));
}
select_music_library_path_button.connect_clicked(clone!(@strong window, @strong backend, @strong music_library_path_row => move |_| {
let dialog = gtk::FileChooserNative::new(Some("Select music library folder"), Some(&window), gtk::FileChooserAction::SelectFolder, None, None);
if let gtk::ResponseType::Accept = dialog.run() {
if let Some(path) = dialog.get_filename() {
music_library_path_row.set_subtitle(Some(path.to_str().unwrap()));
backend.set_music_library_path(path);
}
}
}));
Self { window }
}
pub fn show(&self) {
self.window.show();
}
}

View file

@ -24,10 +24,14 @@ impl Window {
get_widget!(builder, libhandy::ApplicationWindow, window); get_widget!(builder, libhandy::ApplicationWindow, window);
get_widget!(builder, libhandy::Leaflet, leaflet); get_widget!(builder, libhandy::Leaflet, leaflet);
get_widget!(builder, gtk::Button, add_button);
get_widget!(builder, gtk::Box, sidebar_box); get_widget!(builder, gtk::Box, sidebar_box);
get_widget!(builder, gtk::Box, empty_screen); get_widget!(builder, gtk::Box, empty_screen);
let backend = Rc::new(Backend::new("test.sqlite", std::env::current_dir().unwrap())); let backend = Rc::new(Backend::new(
"test.sqlite",
std::env::current_dir().unwrap(),
));
let poe_list = PoeList::new(backend.clone()); let poe_list = PoeList::new(backend.clone());
let navigator = Navigator::new(&empty_screen); let navigator = Navigator::new(&empty_screen);
@ -60,6 +64,20 @@ impl Window {
.pack_start(&result.poe_list.widget, true, true, 0); .pack_start(&result.poe_list.widget, true, true, 0);
result.window.set_application(Some(app)); result.window.set_application(Some(app));
add_button.connect_clicked(clone!(@strong result => move |_| {
TracksEditor::new(result.backend.clone(), &result.window, clone!(@strong result => move || {
result.reload();
})).show();
}));
action!(
result.window,
"preferences",
clone!(@strong result => move |_, _| {
Preferences::new(result.backend.clone(), &result.window).show();
})
);
action!( action!(
result.window, result.window,
"add-person", "add-person",