diff options
author | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-09-09 21:38:37 +0300 |
---|---|---|
committer | Manos Pitsidianakis <el13635@mail.ntua.gr> | 2019-09-15 13:21:14 +0300 |
commit | fd38dbed48e03eaf75c2c87e2949040c7d46a6de (patch) | |
tree | eaf3637d92e86d6e8ac77adb2ef2a5febec0c2e1 /ui/src/components/mail/listing.rs | |
parent | 81a55abc7c106ce3dfbef8ab98b7532a722edb00 (diff) |
override configuration with per-folder configs
Diffstat (limited to 'ui/src/components/mail/listing.rs')
-rw-r--r-- | ui/src/components/mail/listing.rs | 88 |
1 files changed, 67 insertions, 21 deletions
diff --git a/ui/src/components/mail/listing.rs b/ui/src/components/mail/listing.rs index bfece643..5c62210d 100644 --- a/ui/src/components/mail/listing.rs +++ b/ui/src/components/mail/listing.rs @@ -96,6 +96,40 @@ impl ListingTrait for ListingComponent { } } +impl ListingComponent { + fn set_style(&mut self, new_style: IndexStyle) { + match new_style { + IndexStyle::Plain => { + if let Plain(_) = self { + return; + } + let mut new_l = PlainListing::default(); + let coors = self.coordinates(); + new_l.set_coordinates((coors.0, coors.1, None)); + *self = Plain(new_l); + } + IndexStyle::Threaded => { + if let Threaded(_) = self { + return; + } + let mut new_l = ThreadListing::default(); + let coors = self.coordinates(); + new_l.set_coordinates((coors.0, coors.1, None)); + *self = Threaded(new_l); + } + IndexStyle::Compact => { + if let Compact(_) = self { + return; + } + let mut new_l = CompactListing::default(); + let coors = self.coordinates(); + new_l.set_coordinates((coors.0, coors.1, None)); + *self = Compact(new_l); + } + } + } +} + #[derive(Debug)] pub struct Listing { component: ListingComponent, @@ -226,6 +260,14 @@ impl Component for Listing { } let folder_hash = context.accounts[self.cursor_pos.0].folders_order[self.cursor_pos.1]; + /* Check if per-folder configuration overrides general configuration */ + if let Some(index_style) = context + .accounts + .get(self.cursor_pos.0) + .and_then(|account| account.folder_confs(folder_hash).conf_override.index) + { + self.component.set_style(index_style); + }; // Inform State that we changed the current folder view. context .replies @@ -258,6 +300,14 @@ impl Component for Listing { } let folder_hash = context.accounts[self.cursor_pos.0].folders_order[self.cursor_pos.1]; + /* Check if per-folder configuration overrides general configuration */ + if let Some(index_style) = context + .accounts + .get(self.cursor_pos.0) + .and_then(|account| account.folder_confs(folder_hash).conf_override.index) + { + self.component.set_style(index_style); + }; // Inform State that we changed the current folder view. context .replies @@ -266,30 +316,15 @@ impl Component for Listing { } UIEvent::Action(ref action) => match action { Action::Listing(ListingAction::SetPlain) => { - if let Plain(_) = self.component { - return true; - } - let mut new_l = PlainListing::default(); - new_l.set_coordinates((self.cursor_pos.0, self.cursor_pos.1, None)); - self.component = Plain(new_l); + self.component.set_style(IndexStyle::Plain); return true; } Action::Listing(ListingAction::SetThreaded) => { - if let Threaded(_) = self.component { - return true; - } - let mut new_l = ThreadListing::default(); - new_l.set_coordinates((self.cursor_pos.0, self.cursor_pos.1, None)); - self.component = Threaded(new_l); + self.component.set_style(IndexStyle::Threaded); return true; } Action::Listing(ListingAction::SetCompact) => { - if let Compact(_) = self.component { - return true; - } - let mut new_l = CompactListing::default(); - new_l.set_coordinates((self.cursor_pos.0, self.cursor_pos.1, None)); - self.component = Compact(new_l); + self.component.set_style(IndexStyle::Compact); return true; } _ => {} @@ -437,7 +472,7 @@ impl From<IndexStyle> for ListingComponent { impl Listing { const DESCRIPTION: &'static str = "listing"; pub fn new(accounts: &[Account]) -> Self { - let accounts = accounts + let account_entries = accounts .iter() .enumerate() .map(|(i, a)| AccountMenuEntry { @@ -445,9 +480,20 @@ impl Listing { index: i, }) .collect(); + /* Check if per-folder configuration overrides general configuration */ + let component = if let Some(index_style) = accounts.get(0).and_then(|account| { + account + .folders_order + .get(0) + .and_then(|folder_hash| account.folder_confs(*folder_hash).conf_override.index) + }) { + ListingComponent::from(index_style) + } else { + Compact(Default::default()) + }; Listing { - component: Compact(Default::default()), - accounts, + component, + accounts: account_entries, visible: true, dirty: true, cursor_pos: (0, 0), |