From 449b6f47b8bcc1bdfd9a2546b12d652c3a89bded Mon Sep 17 00:00:00 2001 From: Elias Projahn Date: Mon, 28 Sep 2020 23:33:48 +0200 Subject: [PATCH] Add access to editing and deleting persons This also tweaks the UI and adds some polish. --- res/ui/window.ui | 245 ++++++++++++++++++++++++++++++++++++++++------- src/window.rs | 83 ++++++++++++---- 2 files changed, 274 insertions(+), 54 deletions(-) diff --git a/res/ui/window.ui b/res/ui/window.ui index 80c63bb..49cf877 100644 --- a/res/ui/window.ui +++ b/res/ui/window.ui @@ -17,7 +17,8 @@ True False vertical - 220 + 250 + False True @@ -66,17 +67,27 @@ - + True - True - 6 - 6 - 6 - 6 - edit-find-symbolic - False - False - Search persons and ensembles … + False + True + + + True + False + 400 + + + True + True + edit-find-symbolic + False + False + Search persons and ensembles … + + + + False @@ -122,39 +133,32 @@ True False vertical + False - + True - vertical + False + crossfade + empty_screen + True - + True - False - crossfade - - - True - False - true - Musicus - True - - - empty_header - empty_header - - + vertical True False - true - Musicus + True + True + False True @@ -178,20 +182,191 @@ + + start + 0 + + + + + True + True + False + True + + + True + False + view-more-symbolic + + + + + end + 0 + + + + + True + True + True + + + True + False + edit-find-symbolic + + + + + end + 1 + - header - header + False + True + 0 + + + + + True + False + + + + True + False + 400 + + + True + True + edit-find-symbolic + False + False + Search works and recordings … + + + + + + + False + True + 1 + + + + + True + True + + + True + False + none + + + True + False + + + + + + + True + True + 2 + + person_screen + - + True - False + vertical + + + True + False + true + Musicus Editor + True + + + + + True + False + center + center + vertical + 18 + + + True + False + 0.5 + 80 + folder-music-symbolic + + + False + True + 0 + + + + + True + False + 0.5 + Welcome to Musicus Editor! + + + + + + False + True + 1 + + + + + True + False + 0.5 + Get startet by selecting something from the sidebar or adding new things to your library using the button in the top left corner. + center + True + 40 + + + False + True + 2 + + + + + True + True + 1 + + + + empty_screen + diff --git a/src/window.rs b/src/window.rs index 72b2bfd..c61890e 100644 --- a/src/window.rs +++ b/src/window.rs @@ -15,12 +15,12 @@ pub struct Window { db: Rc, leaflet: libhandy::Leaflet, persons: RefCell>, + 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(>k::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>(&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); } }