/*
* meli
*
* Copyright 2017-2018 Manos Pitsidianakis
*
* This file is part of meli.
*
* meli is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* meli is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with meli. If not, see <http://www.gnu.org/licenses/>.
*/
use super::*;
use crate::components::PageMovement;
use std::cmp;
#[derive(Debug, Clone)]
struct ThreadEntry {
index: (usize, ThreadNodeHash, usize),
/// (indentation, thread_node index, line number in listing)
indentation: usize,
msg_hash: EnvelopeHash,
seen: bool,
dirty: bool,
hidden: bool,
heading: String,
}
#[derive(Debug, Default, Clone)]
pub struct ThreadView {
new_cursor_pos: usize,
cursor_pos: usize,
expanded_pos: usize,
new_expanded_pos: usize,
reversed: bool,
coordinates: (AccountHash, MailboxHash, usize),
thread_group: ThreadHash,
mailview: MailView,
show_mailview: bool,
show_thread: bool,
entries: Vec<ThreadEntry>,
visible_entries: Vec<Vec<usize>>,
indentation_colors: [ThemeAttribute; 6],
use_color: bool,
movement: Option<PageMovement>,
dirty: bool,
content: CellBuffer,
id: ComponentId,
}
impl ThreadView {
const DESCRIPTION: &'static str = "thread view";
/*
* coordinates: (account index, mailbox_hash, root set thread_node index)
* expanded_hash: optional position of expanded entry when we render the threadview. Default
* expanded message is the last one.
* context: current context
*/
pub fn new(
coordinates: (AccountHash, MailboxHash, usize),
thread_group: ThreadHash,
expanded_hash: Option<ThreadNodeHash>,
context: &Context,
) -> Self {
let mut view = ThreadView {
reversed: false,
coordinates,
thread_group,
mailview: MailView::default(),
show_mailview: true,
show_thread: true,
entries: Vec::new(),
cursor_pos: 1,
new_cursor_pos: 0,
dirty: true,
id: ComponentId::new_v4(),
indentation_colors: [
crate::conf::value(context, "mail.view.thread.indentation.a"),
crate::conf::value(context, "mail.view.thread.indentation.b"),
crate::conf::value(context, "mail.view.thread.indentation.c"),
crate::conf::value(context, "mail.view.thread.indentation.d"),
crate::conf::value(context, "mail.view.thread.indentation.e"),
crate::conf::value(context, "mail.view.thread.indentation.f"),
],
use_color: context.settings.terminal.use_color(),
..Default::default()
};
view.initiate(expanded_hash, context);
view.new_cursor_pos = view.new_expanded_pos;
view
}
pub fn update(&mut self, context: &Context) {
if self.entries.is_empty() {
return;
}
let old_entries = self.entries.clone();
let old_focused_entry = if self.entries.len() > self.cursor_pos {
Some(self.entries.remove(self.cursor_pos))
} else {
None
};
let old_expanded_entry =