From bac75b96dd1c431732815cdbff4e4fb92de4f76d Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 25 Feb 2019 12:14:44 +0200 Subject: [PATCH] Add Contact create --- ui/src/components/contacts/contact_list.rs | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/ui/src/components/contacts/contact_list.rs b/ui/src/components/contacts/contact_list.rs index 2879a722f..a812e8f3a 100644 --- a/ui/src/components/contacts/contact_list.rs +++ b/ui/src/components/contacts/contact_list.rs @@ -54,8 +54,8 @@ impl ContactList { fn initialize(&mut self, context: &mut Context) { let account = &mut context.accounts[self.account_pos]; let book = &mut account.address_book; + self.length = book.len(); self.content.resize(MAX_COLS, book.len(), Cell::with_char(' ')); - eprintln!("initialize {:?}", book); self.id_positions.clear(); if self.id_positions.capacity() < book.len() { @@ -127,6 +127,27 @@ impl Component for ContactList { return true; }, + UIEventType::Input(Key::Char('n')) => { + let card = Card::new(); + let mut manager = ContactManager::default(); + manager.card = card; + manager.account_pos = self.account_pos; + let entity = Entity::from(Box::new(manager)); + self.mode = ViewMode::View(*entity.id()); + self.view = Some(entity); + + return true; + }, + UIEventType::Input(Key::Up) => { + self.set_dirty(); + self.new_cursor_pos = self.cursor_pos.saturating_sub(1); + return true; + }, + UIEventType::Input(Key::Down) if self.cursor_pos < self.length.saturating_sub(1) => { + self.set_dirty(); + self.new_cursor_pos += 1; + return true; + }, UIEventType::EntityKill(ref kill_id) if self.mode == ViewMode::View(*kill_id) => { self.mode = ViewMode::List; self.view.take();