ui: put INBOX first in AccountMenu
parent
42a512d010
commit
b993375fa0
|
@ -39,8 +39,6 @@ struct AccountMenuEntry {
|
||||||
name: String,
|
name: String,
|
||||||
// Index in the config account vector.
|
// Index in the config account vector.
|
||||||
index: usize,
|
index: usize,
|
||||||
// Each entry and its index in the account
|
|
||||||
entries: Vec<(usize, Folder)>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The account sidebar.
|
/// The account sidebar.
|
||||||
|
@ -67,13 +65,6 @@ impl AccountMenu {
|
||||||
.map(|(i, a)| AccountMenuEntry {
|
.map(|(i, a)| AccountMenuEntry {
|
||||||
name: a.name().to_string(),
|
name: a.name().to_string(),
|
||||||
index: i,
|
index: i,
|
||||||
entries: {
|
|
||||||
let mut entries = Vec::with_capacity(a.len());
|
|
||||||
for (idx, acc) in a.list_folders().into_iter().enumerate() {
|
|
||||||
entries.push((idx, acc));
|
|
||||||
}
|
|
||||||
entries
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
AccountMenu {
|
AccountMenu {
|
||||||
|
@ -96,16 +87,27 @@ impl AccountMenu {
|
||||||
if cfg!(feature = "debug_log") && !is_valid_area!(area) {
|
if cfg!(feature = "debug_log") && !is_valid_area!(area) {
|
||||||
eprintln!("BUG: invalid area in print_account");
|
eprintln!("BUG: invalid area in print_account");
|
||||||
}
|
}
|
||||||
|
// Each entry and its index in the account
|
||||||
|
let entries: Vec<(usize, Folder)> = {
|
||||||
|
let a = &context.accounts[a.index];
|
||||||
|
let mut entries = Vec::with_capacity(a.len());
|
||||||
|
for (idx, acc) in a.list_folders().into_iter().enumerate() {
|
||||||
|
entries.push((idx, acc));
|
||||||
|
}
|
||||||
|
entries
|
||||||
|
};
|
||||||
let upper_left = upper_left!(area);
|
let upper_left = upper_left!(area);
|
||||||
let bottom_right = bottom_right!(area);
|
let bottom_right = bottom_right!(area);
|
||||||
|
|
||||||
let highlight = self.cursor.map(|(x, _)| x == a.index).unwrap_or(false);
|
let highlight = self.cursor.map(|(x, _)| x == a.index).unwrap_or(false);
|
||||||
|
|
||||||
let mut parents: Vec<Option<usize>> = vec![None; a.entries.len()];
|
let mut parents: Vec<Option<usize>> = vec![None; entries.len()];
|
||||||
|
|
||||||
for (idx, e) in a.entries.iter().enumerate() {
|
for (idx, e) in entries.iter().enumerate() {
|
||||||
for c in e.1.children() {
|
for &c in e.1.children() {
|
||||||
parents[*c] = Some(idx);
|
if c < parents.len() {
|
||||||
|
parents[c] = Some(idx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut roots = Vec::new();
|
let mut roots = Vec::new();
|
||||||
|
@ -137,6 +139,9 @@ impl AccountMenu {
|
||||||
index: usize, //account index
|
index: usize, //account index
|
||||||
context: &mut Context,
|
context: &mut Context,
|
||||||
) {
|
) {
|
||||||
|
if root >= entries.len() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let len = s.len();
|
let len = s.len();
|
||||||
match context.accounts[index].status(root) {
|
match context.accounts[index].status(root) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
|
@ -167,7 +172,7 @@ impl AccountMenu {
|
||||||
}
|
}
|
||||||
for r in roots {
|
for r in roots {
|
||||||
print(
|
print(
|
||||||
r, &parents, &mut depth, &a.entries, &mut s, &mut inc, a.index, context,
|
r, &parents, &mut depth, &entries, &mut s, &mut inc, a.index, context,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,6 +279,9 @@ impl Component for AccountMenu {
|
||||||
UIEventType::StartupCheck(_) => {
|
UIEventType::StartupCheck(_) => {
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
|
UIEventType::MailboxUpdate(_) => {
|
||||||
|
self.dirty = true;
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
|
|
|
@ -123,13 +123,32 @@ impl<'a> Iterator for MailboxIterator<'a> {
|
||||||
impl Account {
|
impl Account {
|
||||||
pub fn new(name: String, settings: AccountConf, map: &Backends, notify_fn: NotifyFn) -> Self {
|
pub fn new(name: String, settings: AccountConf, map: &Backends, notify_fn: NotifyFn) -> Self {
|
||||||
let mut backend = map.get(settings.account().format())(settings.account());
|
let mut backend = map.get(settings.account().format())(settings.account());
|
||||||
let ref_folders: Vec<Folder> = backend.folders();
|
let mut ref_folders: Vec<Folder> = backend.folders();
|
||||||
let mut folders: Vec<Option<Result<Mailbox>>> = Vec::with_capacity(ref_folders.len());
|
let mut folders: Vec<Option<Result<Mailbox>>> = Vec::with_capacity(ref_folders.len());
|
||||||
let mut workers: Vec<Worker> = Vec::new();
|
let mut workers: Vec<Worker> = Vec::new();
|
||||||
|
let notify_fn = Arc::new(notify_fn);
|
||||||
|
|
||||||
|
if let Some(pos) = ref_folders
|
||||||
|
.iter()
|
||||||
|
.position(|f| f.name().eq_ignore_ascii_case("INBOX"))
|
||||||
|
{
|
||||||
|
ref_folders.swap(pos, 0);
|
||||||
|
}
|
||||||
let sent_folder = ref_folders
|
let sent_folder = ref_folders
|
||||||
.iter()
|
.iter()
|
||||||
.position(|x: &Folder| x.name() == settings.account().sent_folder);
|
.position(|x: &Folder| x.name() == settings.account().sent_folder);
|
||||||
let notify_fn = Arc::new(notify_fn);
|
if let Some(folder_confs) = settings.conf().folders() {
|
||||||
|
//if cfg!(feature = "debug_log") {
|
||||||
|
//eprintln!("folder renames: {:?}", folder_renames);
|
||||||
|
//}
|
||||||
|
for f in &mut ref_folders {
|
||||||
|
if let Some(r) = folder_confs.get(&f.name().to_ascii_lowercase()) {
|
||||||
|
if let Some(rename) = r.rename() {
|
||||||
|
f.change_name(rename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
for f in ref_folders {
|
for f in ref_folders {
|
||||||
folders.push(None);
|
folders.push(None);
|
||||||
workers.push(Account::new_worker(f, &mut backend, notify_fn.clone()));
|
workers.push(Account::new_worker(f, &mut backend, notify_fn.clone()));
|
||||||
|
@ -258,6 +277,12 @@ impl Account {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(pos) = folders
|
||||||
|
.iter()
|
||||||
|
.position(|f| f.name().eq_ignore_ascii_case("INBOX"))
|
||||||
|
{
|
||||||
|
folders.swap(pos, 0);
|
||||||
|
}
|
||||||
folders
|
folders
|
||||||
}
|
}
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
|
|
Loading…
Reference in New Issue