From addd27f2093d5f0998680a9073719fbe2b52bedd Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 11 Aug 2018 22:47:38 +0300 Subject: [PATCH] Put root folders on top in account menu --- melib/src/mailbox/backends/maildir.rs | 4 ++-- ui/src/components/mail/mod.rs | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/melib/src/mailbox/backends/maildir.rs b/melib/src/mailbox/backends/maildir.rs index ba7a0dc0..ce41f0df 100644 --- a/melib/src/mailbox/backends/maildir.rs +++ b/melib/src/mailbox/backends/maildir.rs @@ -246,16 +246,16 @@ impl MaildirType { children }; let path = PathBuf::from(f.root_folder()); - let path_children = recurse_folders(&mut folders, &path); if path.is_dir() { if let Ok(f) = MaildirFolder::new( path.to_str().unwrap().to_string(), path.file_name().unwrap().to_str().unwrap().to_string(), - path_children, + Vec::with_capacity(0), ) { folders.push(f); } } + folders[0].children = recurse_folders(&mut folders, &path); MaildirType { folders, path: f.root_folder().to_string(), diff --git a/ui/src/components/mail/mod.rs b/ui/src/components/mail/mod.rs index 96cfc8b8..b9714332 100644 --- a/ui/src/components/mail/mod.rs +++ b/ui/src/components/mail/mod.rs @@ -34,7 +34,9 @@ pub use self::compose::*; #[derive(Debug)] struct AccountMenuEntry { name: String, + // Index in the config account vector. index: usize, + // Each entry and its index in the account entries: Vec<(usize, Folder)>, } @@ -78,6 +80,9 @@ impl AccountMenu { cursor: None, } } + /* + * Print a single account in the menu area. + */ fn print_account( &self, grid: &mut CellBuffer, @@ -180,7 +185,7 @@ impl AccountMenu { lines[idx].to_string() }; let (color_fg, color_bg) = if highlight { - if idx > 1 && self.cursor.unwrap().1 == idx - 2 { + if self.cursor.unwrap().1 + 1 == idx { (Color::Byte(233), Color::Byte(15)) } else { (Color::Byte(15), Color::Byte(233)) @@ -198,7 +203,7 @@ impl AccountMenu { false, ); - if highlight && idx > 1 && self.cursor.unwrap().1 == idx - 2 { + if highlight && idx > 1 && self.cursor.unwrap().1 == idx - 1 { change_colors(grid, ((x, y), (get_x(bottom_right), y)), color_fg, color_bg); } else { change_colors(grid, ((x, y), set_y(bottom_right, y)), color_fg, color_bg);