Add access to editing and deleting persons

This also tweaks the UI and adds some polish.
This commit is contained in:
Elias Projahn 2020-09-28 23:33:48 +02:00
parent af1d7c4a01
commit 449b6f47b8
2 changed files with 274 additions and 54 deletions

View file

@ -17,7 +17,8 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="width_request">220</property>
<property name="width-request">250</property>
<property name="hexpand">False</property>
<child>
<object class="HdyHeaderBar" id="left_header">
<property name="visible">True</property>
@ -65,19 +66,29 @@
<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="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 persons and ensembles …</property>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
@ -122,39 +133,32 @@
<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="GtkBox" id="content_box">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkStack" id="header_stack">
<object class="GtkStack" id="stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="transition_type">crossfade</property>
<property name="visible_child">empty_screen</property>
<property name="hexpand">True</property>
<child>
<object class="HdyHeaderBar" id="empty_header">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">true</property>
<property name="title" translatable="yes">Musicus</property>
<property name="show_close_button">True</property>
</object>
<packing>
<property name="name">empty_header</property>
<property name="title">empty_header</property>
</packing>
</child>
<property name="orientation">vertical</property>
<child>
<object class="HdyHeaderBar" id="header">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">true</property>
<property name="title" translatable="yes">Musicus</property>
<property name="show_close_button">True</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="show_close_button">True</property>
<child>
<object class="GtkRevealer">
@ -178,17 +182,95 @@
</object>
</child>
</object>
<packing>
<property name="pack_type">start</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkMenuButton" id="header_menu_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</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">view-more-symbolic</property>
</object>
</child>
</object>
<packing>
<property name="name">header</property>
<property name="title">header</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</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="GtkScrolledWindow" id="content">
<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"></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 and recordings …</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="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="list">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
@ -196,6 +278,99 @@
</object>
</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>
</packing>
</child>
<child>
<object class="GtkBox" id="empty_screen">
<property name="visible">True</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">Musicus Editor</property>
<property name="show_close_button">True</property>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="orientation">vertical</property>
<property name="spacing">18</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="opacity">0.5</property>
<property name="pixel_size">80</property>
<property name="icon_name">folder-music-symbolic</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="opacity">0.5</property>
<property name="label" translatable="yes">Welcome to Musicus Editor!</property>
<attributes>
<attribute name="size" value="16384" />
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="opacity">0.5</property>
<property name="label" translatable="yes">Get startet by selecting something from the sidebar or adding new things to your library using the button in the top left corner.</property>
<property name="justify">center</property>
<property name="wrap">True</property>
<property name="max_width_chars">40</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</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>
</object>
</child>
</object>
</child>
</object>
<object class="HdyHeaderGroup" id="inner_header_group">

View file

@ -15,12 +15,12 @@ pub struct Window {
db: Rc<Database>,
leaflet: libhandy::Leaflet,
persons: RefCell<Vec<Person>>,
sidebar_box: gtk::Box,
person_search_entry: gtk::SearchEntry,
person_list: gtk::ListBox,
header_stack: gtk::Stack,
stack: gtk::Stack,
header: libhandy::HeaderBar,
content_box: gtk::Box,
content: gtk::ScrolledWindow,
header_menu_button: gtk::MenuButton,
}
impl Window {
@ -29,12 +29,12 @@ impl Window {
get_widget!(builder, libhandy::ApplicationWindow, window);
get_widget!(builder, libhandy::Leaflet, leaflet);
get_widget!(builder, gtk::Box, sidebar_box);
get_widget!(builder, gtk::SearchEntry, person_search_entry);
get_widget!(builder, gtk::ListBox, person_list);
get_widget!(builder, gtk::Stack, header_stack);
get_widget!(builder, gtk::Stack, stack);
get_widget!(builder, libhandy::HeaderBar, header);
get_widget!(builder, gtk::Box, content_box);
get_widget!(builder, gtk::ScrolledWindow, content);
get_widget!(builder, gtk::MenuButton, header_menu_button);
let db = Rc::new(Database::new("test.sqlite"));
let persons = db.get_persons();
@ -44,12 +44,12 @@ impl Window {
db: db,
leaflet: leaflet,
persons: RefCell::new(persons),
sidebar_box: sidebar_box,
person_list: person_list,
person_search_entry: person_search_entry,
header_stack: header_stack,
stack: stack,
header: header,
content_box: content_box,
content: content,
header_menu_button: header_menu_button,
});
result
@ -80,6 +80,14 @@ impl Window {
result.person_list.invalidate_filter();
}));
action!(
result.window,
"back",
clone!(@strong result => move |_, _| {
result.back();
})
);
action!(
result.window,
"add-person",
@ -126,6 +134,32 @@ impl Window {
println!("TODO: Add recording.");
});
action!(
result.window,
"edit-person",
Some(glib::VariantTy::new("x").unwrap()),
clone!(@strong result => move |_, id| {
let person = result.db.get_person(id.unwrap().get().unwrap()).unwrap();
PersonEditor::new(result.db.clone(), &result.window, Some(person), clone!(@strong result => move |person| {
result.persons.replace(result.db.get_persons());
result.show_persons();
result.show_person(person);
})).show();
})
);
action!(
result.window,
"delete-person",
Some(glib::VariantTy::new("x").unwrap()),
clone!(@strong result => move |_, id| {
result.db.delete_person(id.unwrap().get().unwrap());
result.back();
result.persons.replace(result.db.get_persons());
result.show_persons();
})
);
result.window.set_application(Some(app));
result.show_persons();
@ -152,17 +186,28 @@ impl Window {
fn show_person(&self, person: Person) {
self.header.set_title(Some(&person.name_fl()));
self.header_stack.set_visible_child_name("header");
self.set_view(&gtk::Label::new(Some(&person.name_fl())));
let edit_menu_item = gio::MenuItem::new(Some("Edit person"), None);
edit_menu_item.set_action_and_target_value(
Some("win.edit-person"),
Some(&glib::Variant::from(person.id)),
);
let delete_menu_item = gio::MenuItem::new(Some("Delete person"), None);
delete_menu_item.set_action_and_target_value(
Some("win.delete-person"),
Some(&glib::Variant::from(person.id)),
);
let menu = gio::Menu::new();
menu.append_item(&edit_menu_item);
menu.append_item(&delete_menu_item);
self.header_menu_button.set_menu_model(Some(&menu));
self.stack.set_visible_child_name("person_screen");
self.leaflet.set_visible_child(&self.stack);
}
fn set_view<T: IsA<gtk::Widget>>(&self, widget: &T) {
match self.content.get_child() {
Some(child) => self.content.remove(&child),
None => (),
}
self.content.add(widget);
self.leaflet.set_visible_child(&self.content_box);
fn back(&self) {
self.stack.set_visible_child_name("empty_screen");
self.leaflet.set_visible_child(&self.sidebar_box);
}
}