mirror of
https://github.com/johrpan/musicus.git
synced 2025-10-26 11:47:25 +01:00
Add work selector
This commit is contained in:
parent
96df2fb148
commit
a222e00688
4 changed files with 605 additions and 0 deletions
|
|
@ -10,5 +10,6 @@
|
||||||
<file preprocess="xml-stripblanks">ui/section_editor.ui</file>
|
<file preprocess="xml-stripblanks">ui/section_editor.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/window.ui</file>
|
<file preprocess="xml-stripblanks">ui/window.ui</file>
|
||||||
<file preprocess="xml-stripblanks">ui/work_editor.ui</file>
|
<file preprocess="xml-stripblanks">ui/work_editor.ui</file>
|
||||||
|
<file preprocess="xml-stripblanks">ui/work_selector.ui</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
</gresources>
|
</gresources>
|
||||||
|
|
|
||||||
351
res/ui/work_selector.ui
Normal file
351
res/ui/work_selector.ui
Normal file
|
|
@ -0,0 +1,351 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- Generated with glade 3.38.1 -->
|
||||||
|
<interface>
|
||||||
|
<requires lib="gtk+" version="3.22" />
|
||||||
|
<requires lib="libhandy" version="1.0" />
|
||||||
|
<object class="HdyWindow" id="window">
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="default-width">600</property>
|
||||||
|
<property name="default-height">424</property>
|
||||||
|
<property name="modal">True</property>
|
||||||
|
<property name="destroy-with-parent">True</property>
|
||||||
|
<property name="type-hint">dialog</property>
|
||||||
|
<child>
|
||||||
|
<object class="HdyLeaflet" id="leaflet">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="visible-child">sidebar_box</property>
|
||||||
|
<property name="can-swipe-back">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox" id="sidebar_box">
|
||||||
|
<property name="width-request">225</property>
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="hexpand">False</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<child>
|
||||||
|
<object class="HdyHeaderBar" id="left_header">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="show-close-button">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="add_button">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">True</property>
|
||||||
|
<property name="receives-default">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkImage">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="icon-name">list-add-symbolic</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="HdySearchBar">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="search-mode-enabled">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="HdyClamp">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="maximum-size">400</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSearchEntry" id="person_search_entry">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">True</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 persons …</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkStack" id="sidebar_stack">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="transition-type">crossfade</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSpinner">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="active">True</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="name">loading</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="name">persons_list</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">2</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="name">sidebar</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSeparator">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<style>
|
||||||
|
<class name="sidebar" />
|
||||||
|
</style>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="navigatable">False</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkStack" id="stack">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="transition-type">crossfade</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox" id="empty_screen">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<child>
|
||||||
|
<object class="HdyHeaderBar" id="empty_header">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="hexpand">True</property>
|
||||||
|
<property name="title" translatable="yes">Select work</property>
|
||||||
|
<property name="show-close-button">True</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="label" translatable="yes">Select a composer on the left.</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="name">empty_screen</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="orientation">vertical</property>
|
||||||
|
<child>
|
||||||
|
<object class="HdyHeaderBar" id="header">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="show-close-button">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkRevealer">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="transition-type">crossfade</property>
|
||||||
|
<property name="transition-duration" bind-source="leaflet" bind-property="mode-transition-duration" bind-flags="bidirectional|sync-create">0</property>
|
||||||
|
<property name="reveal-child" bind-source="leaflet" bind-property="folded" bind-flags="sync-create">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkButton" id="back_button">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">True</property>
|
||||||
|
<property name="receives-default">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkImage">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="icon-name">go-previous-symbolic</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkToggleButton" id="search_button">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">True</property>
|
||||||
|
<property name="receives-default">True</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkImage">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="icon-name">edit-find-symbolic</property>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="pack-type">end</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="HdySearchBar">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="search-mode-enabled" bind-source="search_button" bind-property="active" bind-flags="bidirectional|sync-create">False</property>
|
||||||
|
<child>
|
||||||
|
<object class="HdyClamp">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="maximum-size">400</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSearchEntry" id="search_entry">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">True</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>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkStack" id="content_stack">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="transition-type">crossfade</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkSpinner">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can-focus">False</property>
|
||||||
|
<property name="active">True</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="name">loading</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>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="name">content</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">2</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="name">person_screen</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="name">content</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<object class="HdyHeaderGroup" id="inner_header_group">
|
||||||
|
<headerbars>
|
||||||
|
<headerbar name="empty_header" />
|
||||||
|
<headerbar name="header" />
|
||||||
|
</headerbars>
|
||||||
|
</object>
|
||||||
|
<object class="HdyHeaderGroup">
|
||||||
|
<headerbars>
|
||||||
|
<headerbar name="left_header" />
|
||||||
|
<headerbar name="inner_header_group" />
|
||||||
|
</headerbars>
|
||||||
|
</object>
|
||||||
|
</interface>
|
||||||
|
|
@ -24,3 +24,6 @@ pub use selector_row::*;
|
||||||
|
|
||||||
pub mod work_editor;
|
pub mod work_editor;
|
||||||
pub use work_editor::*;
|
pub use work_editor::*;
|
||||||
|
|
||||||
|
pub mod work_selector;
|
||||||
|
pub use work_selector::*;
|
||||||
|
|
|
||||||
250
src/dialogs/work_selector.rs
Normal file
250
src/dialogs/work_selector.rs
Normal file
|
|
@ -0,0 +1,250 @@
|
||||||
|
use super::*;
|
||||||
|
use crate::backend::Backend;
|
||||||
|
use crate::database::*;
|
||||||
|
use gio::prelude::*;
|
||||||
|
use glib::clone;
|
||||||
|
use gtk::prelude::*;
|
||||||
|
use gtk_macros::get_widget;
|
||||||
|
use libhandy::prelude::*;
|
||||||
|
use libhandy::HeaderBarExt;
|
||||||
|
use std::cell::Cell;
|
||||||
|
use std::convert::TryInto;
|
||||||
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
enum WorkSelectorState {
|
||||||
|
Loading,
|
||||||
|
Persons(Vec<Person>),
|
||||||
|
PersonLoading(Person),
|
||||||
|
Person(Vec<WorkDescription>),
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct WorkSelector<F>
|
||||||
|
where
|
||||||
|
F: Fn(WorkDescription) -> () + 'static,
|
||||||
|
{
|
||||||
|
window: libhandy::Window,
|
||||||
|
backend: Rc<Backend>,
|
||||||
|
callback: F,
|
||||||
|
leaflet: libhandy::Leaflet,
|
||||||
|
sidebar_stack: gtk::Stack,
|
||||||
|
person_search_entry: gtk::SearchEntry,
|
||||||
|
person_list: gtk::ListBox,
|
||||||
|
stack: gtk::Stack,
|
||||||
|
header: libhandy::HeaderBar,
|
||||||
|
search_entry: gtk::SearchEntry,
|
||||||
|
content_stack: gtk::Stack,
|
||||||
|
work_list: gtk::ListBox,
|
||||||
|
person_list_row_activated_handler_id: Cell<Option<glib::SignalHandlerId>>,
|
||||||
|
work_list_row_activated_handler_id: Cell<Option<glib::SignalHandlerId>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<F> WorkSelector<F>
|
||||||
|
where
|
||||||
|
F: Fn(WorkDescription) -> () + 'static,
|
||||||
|
{
|
||||||
|
pub fn new<P: IsA<gtk::Window>>(backend: Rc<Backend>, parent: &P, callback: F) -> Rc<Self> {
|
||||||
|
use WorkSelectorState::*;
|
||||||
|
|
||||||
|
let builder = gtk::Builder::from_resource("/de/johrpan/musicus_editor/ui/work_selector.ui");
|
||||||
|
|
||||||
|
get_widget!(builder, libhandy::Window, window);
|
||||||
|
get_widget!(builder, libhandy::Leaflet, leaflet);
|
||||||
|
get_widget!(builder, gtk::Button, add_button);
|
||||||
|
get_widget!(builder, gtk::SearchEntry, person_search_entry);
|
||||||
|
get_widget!(builder, gtk::Stack, sidebar_stack);
|
||||||
|
get_widget!(builder, gtk::ListBox, person_list);
|
||||||
|
get_widget!(builder, gtk::Stack, stack);
|
||||||
|
get_widget!(builder, libhandy::HeaderBar, header);
|
||||||
|
get_widget!(builder, gtk::SearchEntry, search_entry);
|
||||||
|
get_widget!(builder, gtk::Button, back_button);
|
||||||
|
get_widget!(builder, gtk::Stack, content_stack);
|
||||||
|
get_widget!(builder, gtk::ListBox, work_list);
|
||||||
|
|
||||||
|
let result = Rc::new(WorkSelector {
|
||||||
|
window: window,
|
||||||
|
backend: backend,
|
||||||
|
callback: callback,
|
||||||
|
leaflet: leaflet,
|
||||||
|
sidebar_stack: sidebar_stack,
|
||||||
|
person_list: person_list,
|
||||||
|
person_search_entry: person_search_entry,
|
||||||
|
stack: stack,
|
||||||
|
header: header,
|
||||||
|
search_entry: search_entry,
|
||||||
|
content_stack: content_stack,
|
||||||
|
work_list: work_list,
|
||||||
|
person_list_row_activated_handler_id: Cell::new(None),
|
||||||
|
work_list_row_activated_handler_id: Cell::new(None),
|
||||||
|
});
|
||||||
|
|
||||||
|
add_button.connect_clicked(clone!(@strong result => move |_| {
|
||||||
|
let editor = WorkEditor::new(
|
||||||
|
result.backend.clone(),
|
||||||
|
&result.window,
|
||||||
|
None,
|
||||||
|
clone!(@strong result => move |work| {
|
||||||
|
result.window.close();
|
||||||
|
(result.callback)(work);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
editor.show();
|
||||||
|
}));
|
||||||
|
|
||||||
|
back_button.connect_clicked(clone!(@strong result => move |_| {
|
||||||
|
result.back();
|
||||||
|
}));
|
||||||
|
|
||||||
|
result
|
||||||
|
.person_search_entry
|
||||||
|
.connect_search_changed(clone!(@strong result => move |_| {
|
||||||
|
result.person_list.invalidate_filter();
|
||||||
|
}));
|
||||||
|
|
||||||
|
result
|
||||||
|
.search_entry
|
||||||
|
.connect_search_changed(clone!(@strong result => move |_| {
|
||||||
|
result.work_list.invalidate_filter();
|
||||||
|
}));
|
||||||
|
|
||||||
|
result.window.set_transient_for(Some(parent));
|
||||||
|
result.clone().set_state(Loading);
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn show(&self) {
|
||||||
|
self.window.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn set_state(self: Rc<Self>, state: WorkSelectorState) {
|
||||||
|
use WorkSelectorState::*;
|
||||||
|
|
||||||
|
match state {
|
||||||
|
Loading => {
|
||||||
|
self.backend
|
||||||
|
.get_persons(clone!(@strong self as self_ => move |persons| {
|
||||||
|
self_.clone().set_state(Persons(persons));
|
||||||
|
}));
|
||||||
|
|
||||||
|
self.sidebar_stack.set_visible_child_name("loading");
|
||||||
|
self.stack.set_visible_child_name("empty_screen");
|
||||||
|
self.leaflet.set_visible_child_name("sidebar");
|
||||||
|
}
|
||||||
|
Persons(persons) => {
|
||||||
|
for child in self.person_list.get_children() {
|
||||||
|
self.person_list.remove(&child);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (index, person) in persons.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
match self.person_list_row_activated_handler_id.take() {
|
||||||
|
Some(id) => self.person_list.disconnect(id),
|
||||||
|
None => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
let handler_id = self.person_list.connect_row_activated(
|
||||||
|
clone!(@strong self as self_, @strong persons => move |_, row| {
|
||||||
|
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
||||||
|
let index: usize = row.get_index().try_into().unwrap();
|
||||||
|
let person = persons[index].clone();
|
||||||
|
self_.clone().set_state(PersonLoading(person));
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
self.person_list_row_activated_handler_id
|
||||||
|
.set(Some(handler_id));
|
||||||
|
|
||||||
|
self.person_list.set_filter_func(Some(Box::new(
|
||||||
|
clone!(@strong self as self_, @strong persons => move |row| {
|
||||||
|
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
||||||
|
let index: usize = row.get_index().try_into().unwrap();
|
||||||
|
let search = self_.person_search_entry.get_text().to_string().to_lowercase();
|
||||||
|
|
||||||
|
search.is_empty() || persons[index]
|
||||||
|
.name_lf()
|
||||||
|
.to_lowercase()
|
||||||
|
.contains(&search)
|
||||||
|
}),
|
||||||
|
)));
|
||||||
|
|
||||||
|
self.sidebar_stack.set_visible_child_name("persons_list");
|
||||||
|
self.stack.set_visible_child_name("empty_screen");
|
||||||
|
self.leaflet.set_visible_child_name("sidebar");
|
||||||
|
}
|
||||||
|
PersonLoading(person) => {
|
||||||
|
self.header.set_title(Some(&person.name_fl()));
|
||||||
|
|
||||||
|
self.backend.get_work_descriptions(
|
||||||
|
person.id,
|
||||||
|
clone!(@strong self as self_ => move |works| {
|
||||||
|
self_.clone().set_state(Person(works));
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
self.content_stack.set_visible_child_name("loading");
|
||||||
|
self.stack.set_visible_child_name("person_screen");
|
||||||
|
self.leaflet.set_visible_child_name("content");
|
||||||
|
}
|
||||||
|
Person(works) => {
|
||||||
|
for child in self.work_list.get_children() {
|
||||||
|
self.work_list.remove(&child);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (index, work) in works.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
match self.work_list_row_activated_handler_id.take() {
|
||||||
|
Some(id) => self.work_list.disconnect(id),
|
||||||
|
None => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
let handler_id = self.work_list.connect_row_activated(
|
||||||
|
clone!(@strong self as self_, @strong works => move |_, row| {
|
||||||
|
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
||||||
|
let index: usize = row.get_index().try_into().unwrap();
|
||||||
|
let work = works[index].clone();
|
||||||
|
(self_.callback)(work);
|
||||||
|
self_.window.close();
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
self.work_list_row_activated_handler_id
|
||||||
|
.set(Some(handler_id));
|
||||||
|
|
||||||
|
self.work_list.set_filter_func(Some(Box::new(
|
||||||
|
clone!(@strong self as self_, @strong works => move |row| {
|
||||||
|
let row = row.get_child().unwrap().downcast::<SelectorRow>().unwrap();
|
||||||
|
let index: usize = row.get_index().try_into().unwrap();
|
||||||
|
let search = self_.search_entry.get_text().to_string().to_lowercase();
|
||||||
|
|
||||||
|
search.is_empty() || works[index]
|
||||||
|
.title
|
||||||
|
.to_lowercase()
|
||||||
|
.contains(&search)
|
||||||
|
}),
|
||||||
|
)));
|
||||||
|
|
||||||
|
self.content_stack.set_visible_child_name("content");
|
||||||
|
self.stack.set_visible_child_name("person_screen");
|
||||||
|
self.leaflet.set_visible_child_name("content");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn back(&self) {
|
||||||
|
self.stack.set_visible_child_name("empty_screen");
|
||||||
|
self.leaflet.set_visible_child_name("sidebar");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue