From e1328a3e3f6f006cc7702b772932ca3e50c09b53 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 3 Feb 2024 10:54:27 +0000 Subject: [PATCH] Change FileType::CAN_LIST into a method. Now it can return extra information determined at run time. --- src/file.rs | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/file.rs b/src/file.rs index 9fc7dad..3141285 100644 --- a/src/file.rs +++ b/src/file.rs @@ -75,7 +75,7 @@ trait FileDataSource { fn extendable(&self) -> bool; fn single_id(&self) -> String { - panic!("Should only call this if the FileType sets CAN_LIST, CAN_GET_POSTS or IS_EXAMINE_USER"); + panic!("Should only call this if the FileType sets can_list(), CAN_GET_POSTS or IS_EXAMINE_USER"); } fn want_to_jump_to_new_content(&self) -> bool { @@ -169,7 +169,6 @@ enum CanList { trait FileType { type Item: TextFragment + Sized; - const CAN_LIST: CanList = CanList::Nothing; const CAN_GET_POSTS: bool = false; const IS_EXAMINE_USER: bool = false; @@ -182,6 +181,10 @@ trait FileType { fn feed_id(&self) -> Option<&FeedId> { None } + + fn can_list(&self) -> CanList { + CanList::Nothing + } } struct StatusFeedType { @@ -1237,7 +1240,7 @@ impl ActivityState } else { fs }; - let fs = if Type::CAN_LIST != CanList::Nothing { + let fs = if self.file_desc.can_list() != CanList::Nothing { fs.add(Pr('l'), "List", 40) } else { fs @@ -1309,7 +1312,7 @@ impl ActivityState ) } UIMode::ListSubmenu => { - let fs = match Type::CAN_LIST { + let fs = match self.file_desc.can_list() { CanList::ForUser => fs .add(Pr('I'), "List Followers", 99) .add(Pr('O'), "List Followed", 99), @@ -1575,7 +1578,7 @@ impl ActivityState } Pr('l') | Pr('L') => { - if Type::CAN_LIST != CanList::Nothing { + if self.file_desc.can_list() != CanList::Nothing { self.ui_mode = UIMode::ListSubmenu; } LogicalAction::Nothing @@ -1631,7 +1634,7 @@ impl ActivityState }, UIMode::ListSubmenu => match key { Pr('f') | Pr('F') => { - if Type::CAN_LIST == CanList::ForPost { + if self.file_desc.can_list() == CanList::ForPost { LogicalAction::Goto( UtilityActivity::ListStatusFavouriters( self.contents.source.single_id(), @@ -1644,7 +1647,7 @@ impl ActivityState } Pr('b') | Pr('B') => { - if Type::CAN_LIST == CanList::ForPost { + if self.file_desc.can_list() == CanList::ForPost { LogicalAction::Goto( UtilityActivity::ListStatusBoosters( self.contents.source.single_id(), @@ -1657,7 +1660,7 @@ impl ActivityState } Pr('i') | Pr('I') => { - if Type::CAN_LIST == CanList::ForUser { + if self.file_desc.can_list() == CanList::ForUser { LogicalAction::Goto( UtilityActivity::ListUserFollowers( self.contents.source.single_id(), @@ -1670,7 +1673,7 @@ impl ActivityState } Pr('o') | Pr('O') => { - if Type::CAN_LIST == CanList::ForUser { + if self.file_desc.can_list() == CanList::ForUser { LogicalAction::Goto( UtilityActivity::ListUserFollowees( self.contents.source.single_id(), @@ -2062,7 +2065,6 @@ pub fn hashtag_timeline( struct ExamineUserFileType {} impl FileType for ExamineUserFileType { type Item = ExamineUserDisplay; - const CAN_LIST: CanList = CanList::ForUser; const CAN_GET_POSTS: bool = true; const IS_EXAMINE_USER: bool = true; @@ -2074,6 +2076,10 @@ impl FileType for ExamineUserFileType { let ac = client.account_by_id(id)?; ExamineUserDisplay::new(ac, client) } + + fn can_list(&self) -> CanList { + CanList::ForUser + } } pub fn examine_user( @@ -2102,7 +2108,6 @@ pub fn examine_user( struct DetailedStatusFileType {} impl FileType for DetailedStatusFileType { type Item = DetailedStatusDisplay; - const CAN_LIST: CanList = CanList::ForPost; fn get_item( &self, @@ -2112,6 +2117,10 @@ impl FileType for DetailedStatusFileType { let st = client.status_by_id(id)?; Ok(DetailedStatusDisplay::new(st, client)) } + + fn can_list(&self) -> CanList { + CanList::ForPost + } } pub fn view_single_post( -- 2.30.2