mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
Add preview of main window contents
This commit is contained in:
parent
6cdaf97a36
commit
21ad91d9a9
5 changed files with 266 additions and 13 deletions
140
res/ui/window.ui
140
res/ui/window.ui
|
|
@ -6,9 +6,149 @@
|
|||
<property name="can_focus">False</property>
|
||||
<property name="default_width">800</property>
|
||||
<property name="default_height">566</property>
|
||||
<child>
|
||||
<object class="GtkPaned">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkSearchEntry" id="person_search_entry">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="margin_start">6</property>
|
||||
<property name="margin_end">6</property>
|
||||
<property name="margin_top">6</property>
|
||||
<property name="margin_bottom">6</property>
|
||||
<property name="primary_icon_name">edit-find-symbolic</property>
|
||||
<property name="primary_icon_activatable">False</property>
|
||||
<property name="primary_icon_sensitive">False</property>
|
||||
<property name="placeholder_text" translatable="yes">Search composers …</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child>
|
||||
<object class="GtkViewport">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="shadow_type">none</property>
|
||||
<child>
|
||||
<object class="GtkListBox" id="person_list">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child type="placeholder">
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">No persons found.</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="resize">False</property>
|
||||
<property name="shrink">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkPaned">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkSearchEntry" id="work_search_entry">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="margin_left">6</property>
|
||||
<property name="margin_right">6</property>
|
||||
<property name="margin_start">6</property>
|
||||
<property name="margin_end">6</property>
|
||||
<property name="margin_top">6</property>
|
||||
<property name="margin_bottom">6</property>
|
||||
<property name="primary_icon_name">edit-find-symbolic</property>
|
||||
<property name="primary_icon_activatable">False</property>
|
||||
<property name="primary_icon_sensitive">False</property>
|
||||
<property name="placeholder_text" translatable="yes">Search works …</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<child>
|
||||
<object class="GtkViewport">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="shadow_type">none</property>
|
||||
<child>
|
||||
<object class="GtkListBox" id="work_list">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child type="placeholder">
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">No works found.</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="resize">False</property>
|
||||
<property name="shrink">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="resize">True</property>
|
||||
<property name="shrink">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar">
|
||||
<property name="visible">True</property>
|
||||
|
|
|
|||
|
|
@ -137,13 +137,13 @@ impl Database {
|
|||
.cloned()
|
||||
}
|
||||
|
||||
pub fn get_work_description_for_work(&self, work: Work) -> WorkDescription {
|
||||
pub fn get_work_description_for_work(&self, work: &Work) -> WorkDescription {
|
||||
WorkDescription {
|
||||
id: work.id,
|
||||
composer: self
|
||||
.get_person(work.composer)
|
||||
.expect("Could not find composer for work!"),
|
||||
title: work.title,
|
||||
title: work.title.clone(),
|
||||
instruments: instrumentations::table
|
||||
.filter(instrumentations::work.eq(work.id))
|
||||
.load::<Instrumentation>(&self.c)
|
||||
|
|
@ -195,7 +195,7 @@ impl Database {
|
|||
|
||||
pub fn get_work_description(&self, id: i64) -> Option<WorkDescription> {
|
||||
match self.get_work(id) {
|
||||
Some(work) => Some(self.get_work_description_for_work(work)),
|
||||
Some(work) => Some(self.get_work_description_for_work(&work)),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -213,6 +213,13 @@ impl Database {
|
|||
.expect("Error loading works!")
|
||||
}
|
||||
|
||||
pub fn get_work_descriptions(&self, composer_id: i64) -> Vec<WorkDescription> {
|
||||
self.get_works(composer_id)
|
||||
.iter()
|
||||
.map(|work| self.get_work_description_for_work(work))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn update_ensemble(&self, ensemble: Ensemble) {
|
||||
diesel::replace_into(ensembles::table)
|
||||
.values(ensemble)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ pub mod section_editor;
|
|||
pub use section_editor::*;
|
||||
|
||||
pub mod selector_row;
|
||||
pub use selector_row::*;
|
||||
|
||||
pub mod work_editor;
|
||||
pub use work_editor::*;
|
||||
|
|
|
|||
|
|
@ -67,12 +67,12 @@ where
|
|||
.set_filter_func(Some(Box::new(clone!(@strong result => move |row| {
|
||||
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
||||
let index: usize = row.get_index().try_into().unwrap();
|
||||
let search = result.search_entry.get_text().to_string();
|
||||
let search = result.search_entry.get_text().to_string().to_lowercase();
|
||||
|
||||
search.is_empty() || result.persons.borrow()[index]
|
||||
.name_lf()
|
||||
.to_lowercase()
|
||||
.contains(&result.search_entry.get_text().to_string().to_lowercase())
|
||||
.contains(&search)
|
||||
}))));
|
||||
|
||||
result
|
||||
|
|
|
|||
117
src/window.rs
117
src/window.rs
|
|
@ -5,32 +5,107 @@ use glib::clone;
|
|||
use gtk::prelude::*;
|
||||
use gtk_macros::{action, get_widget};
|
||||
use std::cell::RefCell;
|
||||
use std::convert::TryInto;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Window {
|
||||
window: gtk::ApplicationWindow,
|
||||
db: Rc<Database>,
|
||||
persons: RefCell<Vec<Person>>,
|
||||
person_search_entry: gtk::SearchEntry,
|
||||
person_list: gtk::ListBox,
|
||||
works: RefCell<Vec<WorkDescription>>,
|
||||
work_search_entry: gtk::SearchEntry,
|
||||
work_list: gtk::ListBox,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
pub fn new(app: >k::Application) -> Rc<Self> {
|
||||
let builder = gtk::Builder::from_resource("/de/johrpan/musicus_editor/ui/window.ui");
|
||||
get_widget!(builder, gtk::ApplicationWindow, window);
|
||||
get_widget!(builder, gtk::SearchEntry, person_search_entry);
|
||||
get_widget!(builder, gtk::ListBox, person_list);
|
||||
get_widget!(builder, gtk::SearchEntry, work_search_entry);
|
||||
get_widget!(builder, gtk::ListBox, work_list);
|
||||
|
||||
let db = Rc::new(Database::new("test.sqlite"));
|
||||
let persons = db.get_persons();
|
||||
|
||||
let result = Rc::new(Window {
|
||||
window: window,
|
||||
db: db,
|
||||
persons: RefCell::new(persons),
|
||||
person_list: person_list,
|
||||
person_search_entry: person_search_entry,
|
||||
works: RefCell::new(Vec::new()),
|
||||
work_search_entry: work_search_entry,
|
||||
work_list: work_list,
|
||||
});
|
||||
|
||||
result
|
||||
.person_list
|
||||
.connect_row_activated(clone!(@strong result => move |_, row| {
|
||||
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
||||
let index: usize = row.get_index().try_into().unwrap();
|
||||
|
||||
let works = result.db.get_work_descriptions(result.persons.borrow()[index].id);
|
||||
result.works.replace(works);
|
||||
result.show_works();
|
||||
}));
|
||||
|
||||
result
|
||||
.person_list
|
||||
.set_filter_func(Some(Box::new(clone!(@strong result => move |row| {
|
||||
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
||||
let index: usize = row.get_index().try_into().unwrap();
|
||||
let search = result.person_search_entry.get_text().to_string().to_lowercase();
|
||||
|
||||
search.is_empty() || result.persons.borrow()[index]
|
||||
.name_lf()
|
||||
.to_lowercase()
|
||||
.contains(&search)
|
||||
}))));
|
||||
|
||||
result
|
||||
.person_search_entry
|
||||
.connect_search_changed(clone!(@strong result => move |_| {
|
||||
result.person_list.invalidate_filter();
|
||||
}));
|
||||
|
||||
// result
|
||||
// .work_list
|
||||
// .connect_row_activated(clone!(@strong result => move |_, row| {
|
||||
// let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
||||
// let index: usize = row.get_index().try_into().unwrap();
|
||||
// }));
|
||||
|
||||
result
|
||||
.work_list
|
||||
.set_filter_func(Some(Box::new(clone!(@strong result => move |row| {
|
||||
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
||||
let index: usize = row.get_index().try_into().unwrap();
|
||||
let search = result.work_search_entry.get_text().to_string().to_lowercase();
|
||||
|
||||
search.is_empty() || result.works.borrow()[index]
|
||||
.title
|
||||
.to_lowercase()
|
||||
.contains(&search)
|
||||
}))));
|
||||
|
||||
result
|
||||
.work_search_entry
|
||||
.connect_search_changed(clone!(@strong result => move |_| {
|
||||
result.work_list.invalidate_filter();
|
||||
}));
|
||||
|
||||
action!(
|
||||
result.window,
|
||||
"add-person",
|
||||
clone!(@strong result => move |_, _| {
|
||||
PersonEditor::new(result.db.clone(), &result.window, None, |person| {
|
||||
println!("{:?}", person);
|
||||
}).show();
|
||||
PersonEditor::new(result.db.clone(), &result.window, None, clone!(@strong result => move |_| {
|
||||
result.persons.replace(result.db.get_persons());
|
||||
result.show_persons();
|
||||
})).show();
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -48,9 +123,10 @@ impl Window {
|
|||
result.window,
|
||||
"add-work",
|
||||
clone!(@strong result => move |_, _| {
|
||||
WorkEditor::new(result.db.clone(), &result.window, None, |work| {
|
||||
println!("{:?}", work);
|
||||
}).show();
|
||||
WorkEditor::new(result.db.clone(), &result.window, None, clone!(@strong result => move |_| {
|
||||
result.persons.replace(result.db.get_persons());
|
||||
result.show_persons();
|
||||
})).show();
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -69,6 +145,7 @@ impl Window {
|
|||
});
|
||||
|
||||
result.window.set_application(Some(app));
|
||||
result.show_persons();
|
||||
|
||||
result
|
||||
}
|
||||
|
|
@ -76,4 +153,32 @@ impl Window {
|
|||
pub fn present(&self) {
|
||||
self.window.present();
|
||||
}
|
||||
|
||||
fn show_persons(&self) {
|
||||
for child in self.person_list.get_children() {
|
||||
self.person_list.remove(&child);
|
||||
}
|
||||
|
||||
for (index, person) in self.persons.borrow().iter().enumerate() {
|
||||
let label = gtk::Label::new(Some(&person.name_lf()));
|
||||
label.set_halign(gtk::Align::Start);
|
||||
let row = SelectorRow::new(index.try_into().unwrap(), &label);
|
||||
row.show_all();
|
||||
self.person_list.insert(&row, -1);
|
||||
}
|
||||
}
|
||||
|
||||
fn show_works(&self) {
|
||||
for child in self.work_list.get_children() {
|
||||
self.work_list.remove(&child);
|
||||
}
|
||||
|
||||
for (index, work) in self.works.borrow().iter().enumerate() {
|
||||
let label = gtk::Label::new(Some(&work.title));
|
||||
label.set_halign(gtk::Align::Start);
|
||||
let row = SelectorRow::new(index.try_into().unwrap(), &label);
|
||||
row.show_all();
|
||||
self.work_list.insert(&row, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue