2018-08-07 15:01:15 +03:00
|
|
|
/*
|
|
|
|
* meli - ui crate.
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2018-07-20 12:15:06 +03:00
|
|
|
use super::*;
|
2018-08-03 13:46:08 +03:00
|
|
|
|
2018-08-11 18:00:21 +03:00
|
|
|
mod compact;
|
|
|
|
pub use self::compact::*;
|
|
|
|
|
2018-09-07 09:44:37 +03:00
|
|
|
mod thread;
|
|
|
|
pub use self::thread::*;
|
2018-07-11 17:07:51 +03:00
|
|
|
|
2018-09-07 09:44:37 +03:00
|
|
|
mod plain;
|
|
|
|
pub use self::plain::*;
|
2018-07-11 17:07:51 +03:00
|
|
|
|
2019-04-03 16:58:42 +03:00
|
|
|
trait ListingTrait {
|
|
|
|
fn coordinates(&self) -> (usize, usize, Option<EnvelopeHash>);
|
|
|
|
fn set_coordinates(&mut self, (usize, usize, Option<EnvelopeHash>));
|
|
|
|
}
|
|
|
|
|
2018-09-07 09:44:37 +03:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum Listing {
|
|
|
|
Plain(PlainListing),
|
|
|
|
Threaded(ThreadListing),
|
|
|
|
Compact(CompactListing),
|
2018-08-07 15:01:15 +03:00
|
|
|
}
|
|
|
|
|
2018-09-07 09:44:37 +03:00
|
|
|
impl fmt::Display for Listing {
|
2018-08-11 18:00:21 +03:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2018-09-07 09:44:37 +03:00
|
|
|
match self {
|
|
|
|
Listing::Compact(l) => write!(f, "{}", l),
|
|
|
|
Listing::Plain(l) => write!(f, "{}", l),
|
|
|
|
Listing::Threaded(l) => write!(f, "{}", l),
|
2018-07-15 15:35:57 +03:00
|
|
|
}
|
|
|
|
}
|
2018-09-07 09:44:37 +03:00
|
|
|
}
|
2018-08-06 11:05:09 +03:00
|
|
|
|
2018-09-07 09:44:37 +03:00
|
|
|
impl Default for Listing {
|
|
|
|
fn default() -> Self {
|
2018-10-14 19:49:16 +03:00
|
|
|
Listing::Threaded(Default::default())
|
2018-07-22 11:14:23 +03:00
|
|
|
}
|
2018-07-11 17:07:51 +03:00
|
|
|
}
|
|
|
|
|
2018-09-07 09:44:37 +03:00
|
|
|
impl Component for Listing {
|
2018-07-14 15:04:42 +03:00
|
|
|
fn draw(&mut self, grid: &mut CellBuffer, area: Area, context: &mut Context) {
|
2018-09-07 09:44:37 +03:00
|
|
|
match self {
|
|
|
|
Listing::Compact(l) => l.draw(grid, area, context),
|
|
|
|
Listing::Plain(l) => l.draw(grid, area, context),
|
|
|
|
Listing::Threaded(l) => l.draw(grid, area, context),
|
2018-07-11 17:07:51 +03:00
|
|
|
}
|
|
|
|
}
|
2019-02-26 17:50:47 +02:00
|
|
|
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
|
2018-09-07 09:44:37 +03:00
|
|
|
if match self {
|
|
|
|
Listing::Plain(l) => l.process_event(event, context),
|
|
|
|
Listing::Compact(l) => l.process_event(event, context),
|
|
|
|
Listing::Threaded(l) => l.process_event(event, context),
|
|
|
|
} {
|
|
|
|
return true;
|
2018-08-23 14:39:54 +03:00
|
|
|
}
|
2018-09-07 09:44:37 +03:00
|
|
|
|
2019-04-10 23:37:20 +03:00
|
|
|
match *event {
|
|
|
|
UIEvent::Resize => self.set_dirty(),
|
|
|
|
UIEvent::Action(ref action) => match action {
|
2018-09-07 09:44:37 +03:00
|
|
|
Action::Listing(ListingAction::SetPlain) => {
|
2019-04-03 16:58:42 +03:00
|
|
|
let new_l = match self {
|
|
|
|
Listing::Plain(_) => {
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-04 14:24:05 +03:00
|
|
|
Listing::Threaded(l) => {
|
2019-04-03 16:58:42 +03:00
|
|
|
let mut new_l = PlainListing::default();
|
|
|
|
new_l.set_coordinates(l.coordinates());
|
|
|
|
new_l
|
|
|
|
}
|
|
|
|
Listing::Compact(l) => {
|
|
|
|
let mut new_l = PlainListing::default();
|
|
|
|
new_l.set_coordinates(l.coordinates());
|
|
|
|
new_l
|
|
|
|
}
|
|
|
|
};
|
|
|
|
*self = Listing::Plain(new_l);
|
2018-08-23 14:39:54 +03:00
|
|
|
return true;
|
2018-08-07 15:01:15 +03:00
|
|
|
}
|
2018-09-07 09:44:37 +03:00
|
|
|
Action::Listing(ListingAction::SetThreaded) => {
|
2019-04-03 16:58:42 +03:00
|
|
|
let new_l = match self {
|
|
|
|
Listing::Threaded(_) => {
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-04 14:24:05 +03:00
|
|
|
Listing::Plain(l) => {
|
2019-04-03 16:58:42 +03:00
|
|
|
let mut new_l = ThreadListing::default();
|
|
|
|
new_l.set_coordinates(l.coordinates());
|
|
|
|
new_l
|
|
|
|
}
|
|
|
|
Listing::Compact(l) => {
|
|
|
|
let mut new_l = ThreadListing::default();
|
|
|
|
new_l.set_coordinates(l.coordinates());
|
|
|
|
new_l
|
|
|
|
}
|
|
|
|
};
|
|
|
|
*self = Listing::Threaded(new_l);
|
2018-08-23 14:39:54 +03:00
|
|
|
return true;
|
2018-08-14 17:36:45 +03:00
|
|
|
}
|
2018-09-07 09:44:37 +03:00
|
|
|
Action::Listing(ListingAction::SetCompact) => {
|
2019-04-03 16:58:42 +03:00
|
|
|
let new_l = match self {
|
|
|
|
Listing::Compact(_) => {
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-04 14:24:05 +03:00
|
|
|
Listing::Threaded(l) => {
|
2019-04-03 16:58:42 +03:00
|
|
|
let mut new_l = CompactListing::default();
|
|
|
|
new_l.set_coordinates(l.coordinates());
|
|
|
|
new_l
|
|
|
|
}
|
|
|
|
Listing::Plain(l) => {
|
|
|
|
let mut new_l = CompactListing::default();
|
|
|
|
new_l.set_coordinates(l.coordinates());
|
|
|
|
new_l
|
|
|
|
}
|
|
|
|
};
|
|
|
|
*self = Listing::Compact(new_l);
|
2018-08-23 14:39:54 +03:00
|
|
|
return true;
|
2018-09-04 01:49:29 +03:00
|
|
|
}
|
|
|
|
_ => {}
|
2018-07-22 14:05:41 +03:00
|
|
|
},
|
2018-07-27 21:37:56 +03:00
|
|
|
_ => {}
|
2018-07-11 17:07:51 +03:00
|
|
|
}
|
2018-08-23 14:39:54 +03:00
|
|
|
false
|
2018-07-11 17:07:51 +03:00
|
|
|
}
|
2018-07-14 15:04:42 +03:00
|
|
|
fn is_dirty(&self) -> bool {
|
2018-09-07 09:44:37 +03:00
|
|
|
match self {
|
|
|
|
Listing::Compact(l) => l.is_dirty(),
|
|
|
|
Listing::Plain(l) => l.is_dirty(),
|
|
|
|
Listing::Threaded(l) => l.is_dirty(),
|
|
|
|
}
|
2018-07-14 15:04:42 +03:00
|
|
|
}
|
2018-08-11 18:00:21 +03:00
|
|
|
fn set_dirty(&mut self) {
|
2018-09-07 09:44:37 +03:00
|
|
|
match self {
|
|
|
|
Listing::Compact(l) => l.set_dirty(),
|
|
|
|
Listing::Plain(l) => l.set_dirty(),
|
|
|
|
Listing::Threaded(l) => l.set_dirty(),
|
|
|
|
}
|
2018-08-11 18:00:21 +03:00
|
|
|
}
|
2019-03-02 19:25:11 +02:00
|
|
|
|
2019-03-04 10:15:11 +02:00
|
|
|
fn get_shortcuts(&self, context: &Context) -> ShortcutMap {
|
2019-03-02 19:25:11 +02:00
|
|
|
match self {
|
2019-03-04 10:15:11 +02:00
|
|
|
Listing::Compact(l) => l.get_shortcuts(context),
|
|
|
|
Listing::Plain(l) => l.get_shortcuts(context),
|
|
|
|
Listing::Threaded(l) => l.get_shortcuts(context),
|
2019-03-02 19:25:11 +02:00
|
|
|
}
|
|
|
|
}
|
2019-04-10 22:01:02 +03:00
|
|
|
|
|
|
|
fn id(&self) -> ComponentId {
|
|
|
|
match self {
|
|
|
|
Listing::Compact(l) => l.id(),
|
|
|
|
Listing::Plain(l) => l.id(),
|
|
|
|
Listing::Threaded(l) => l.id(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn set_id(&mut self, id: ComponentId) {
|
|
|
|
match self {
|
|
|
|
Listing::Compact(l) => l.set_id(id),
|
|
|
|
Listing::Plain(l) => l.set_id(id),
|
|
|
|
Listing::Threaded(l) => l.set_id(id),
|
|
|
|
}
|
|
|
|
}
|
2018-07-11 17:07:51 +03:00
|
|
|
}
|
2019-02-18 23:14:06 +02:00
|
|
|
|
|
|
|
impl From<IndexStyle> for Listing {
|
|
|
|
fn from(index_style: IndexStyle) -> Self {
|
|
|
|
match index_style {
|
|
|
|
IndexStyle::Plain => Listing::Plain(Default::default()),
|
|
|
|
IndexStyle::Threaded => Listing::Threaded(Default::default()),
|
|
|
|
IndexStyle::Compact => Listing::Compact(Default::default()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|