summaryrefslogtreecommitdiffstats
path: root/ui/src
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-02-21 15:44:26 +0200
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-06-10 19:40:37 +0300
commitbbaf87e3455ee52d8f413ae69d5da483c84689f9 (patch)
tree50ec9e246a723f1bd0bf44de26453feafc6457c0 /ui/src
parentba6c7d0d7bc492f5a36ea03d2e8fd820b38561d5 (diff)
Add type synonyms for Uuids
closes 58
Diffstat (limited to 'ui/src')
-rw-r--r--ui/src/components.rs12
-rw-r--r--ui/src/components/contacts/contact_list.rs18
-rw-r--r--ui/src/components/mail/compose.rs2
-rw-r--r--ui/src/components/utilities.rs12
4 files changed, 24 insertions, 20 deletions
diff --git a/ui/src/components.rs b/ui/src/components.rs
index d72378a0..a3460e62 100644
--- a/ui/src/components.rs
+++ b/ui/src/components.rs
@@ -75,10 +75,14 @@ const _DOUBLE_DOWN_AND_LEFT: char = '╗';
const _DOUBLE_UP_AND_LEFT: char = '╝';
const _DOUBLE_UP_AND_RIGHT: char = '╚';
+
+
+type EntityId = Uuid;
+
/// `Entity` is a container for Components.
#[derive(Debug)]
pub struct Entity {
- id: Uuid,
+ id: EntityId,
pub component: Box<Component>, // more than one?
}
@@ -128,7 +132,7 @@ impl Deref for Entity {
}
impl Entity {
- pub fn uuid(&self) -> &Uuid {
+ pub fn id(&self) -> &EntityId {
&self.id
}
/// Pass events to child component.
@@ -147,8 +151,8 @@ pub trait Component: Display + Debug {
true
}
fn set_dirty(&mut self);
- fn kill(&mut self, uuid: Uuid) {}
- fn set_id(&mut self, uuid: Uuid) {}
+ fn kill(&mut self, id: EntityId) {}
+ fn set_id(&mut self, id: EntityId) {}
}
/*
diff --git a/ui/src/components/contacts/contact_list.rs b/ui/src/components/contacts/contact_list.rs
index 73f8e743..f1717d37 100644
--- a/ui/src/components/contacts/contact_list.rs
+++ b/ui/src/components/contacts/contact_list.rs
@@ -5,7 +5,7 @@ const MAX_COLS: usize = 500;
#[derive(Debug, PartialEq)]
enum ViewMode {
List,
- View(Uuid),
+ View(EntityId),
}
#[derive(Debug)]
@@ -16,7 +16,7 @@ pub struct ContactList {
length: usize,
content: CellBuffer,
- uuid_positions: Vec<Uuid>,
+ id_positions: Vec<EntityId>,
mode: ViewMode,
initialized: bool,
@@ -44,7 +44,7 @@ impl ContactList {
new_cursor_pos: 0,
length: 0,
account_pos: 0,
- uuid_positions: Vec::new(),
+ id_positions: Vec::new(),
mode: ViewMode::List,
content,
initialized: false,
@@ -59,13 +59,13 @@ impl ContactList {
self.content.resize(MAX_COLS, book.len(), Cell::with_char(' '));
eprintln!("{:?}", book);
- self.uuid_positions.clear();
- if self.uuid_positions.capacity() < book.len() {
- self.uuid_positions.reserve(book.len());
+ self.id_positions.clear();
+ if self.id_positions.capacity() < book.len() {
+ self.id_positions.reserve(book.len());
}
for (i, c) in book.values().enumerate() {
- self.uuid_positions.push(*c.uuid());
+ self.id_positions.push(*c.id());
write_string_to_grid(
c.email(),
@@ -109,7 +109,7 @@ impl Component for ContactList {
UIEventType::Input(Key::Char('e')) => {
let account = &mut context.accounts[self.account_pos];
let book = &mut account.address_book;
- let card = book[&self.uuid_positions[self.cursor_pos]].clone();
+ let card = book[&self.id_positions[self.cursor_pos]].clone();
let mut manager = ContactManager::default();
manager.card = card;
@@ -117,7 +117,7 @@ impl Component for ContactList {
let entity = Entity::from(Box::new(manager));
- self.mode = ViewMode::View(*entity.uuid());
+ self.mode = ViewMode::View(*entity.id());
self.view = Some(entity);
self.set_dirty();
diff --git a/ui/src/components/mail/compose.rs b/ui/src/components/mail/compose.rs
index 37a2f3cd..854a90e4 100644
--- a/ui/src/components/mail/compose.rs
+++ b/ui/src/components/mail/compose.rs
@@ -570,7 +570,7 @@ impl Component for Composer {
},
Cursor::To | Cursor::Cc | Cursor::Bcc => {
let account = &context.accounts[self.account_cursor];
- let mut entries = account.address_book.values().map(|v| (v.uuid().as_bytes().to_vec(), v.email().to_string())).collect();
+ let mut entries = account.address_book.values().map(|v| (v.id().as_bytes().to_vec(), v.email().to_string())).collect();
self.mode = ViewMode::Selector(Selector::new(entries, true));
},
Cursor::Attachments => {
diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs
index da0426df..5a7cd315 100644
--- a/ui/src/components/utilities.rs
+++ b/ui/src/components/utilities.rs
@@ -808,20 +808,20 @@ impl Component for Tabbed {
return true;
}
UIEventType::Action(Tab(Close)) => {
- let uuid = *self.children[self.cursor_pos].uuid();
- self.children[self.cursor_pos].kill(uuid);
+ let id = *self.children[self.cursor_pos].id();
+ self.children[self.cursor_pos].kill(id);
return true;
}
- UIEventType::Action(Tab(Kill(ref uuid))) => {
- if let Some(c_idx) = self.children.iter().position(|x| x.uuid() == uuid) {
+ UIEventType::Action(Tab(Kill(ref id))) => {
+ if let Some(c_idx) = self.children.iter().position(|x| x.id() == id) {
self.children.remove(c_idx);
self.cursor_pos = self.cursor_pos.saturating_sub(1);
self.set_dirty();
return true;
} else {
eprintln!(
- "DEBUG: Child entity with uuid {:?} not found.\nList: {:?}",
- uuid, self.children
+ "DEBUG: Child entity with id {:?} not found.\nList: {:?}",
+ id, self.children
);
}
}