2016-08-03 16:37:12 +00:00
|
|
|
{- items that a command can act on
|
|
|
|
-
|
|
|
|
- Copyright 2016 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
|
|
|
|
|
|
|
|
module Types.ActionItem where
|
|
|
|
|
2017-02-24 17:42:30 +00:00
|
|
|
import Key
|
2016-08-03 16:37:12 +00:00
|
|
|
import Types.Transfer
|
|
|
|
import Git.FilePath
|
|
|
|
|
|
|
|
data ActionItem
|
|
|
|
= ActionItemAssociatedFile AssociatedFile
|
|
|
|
| ActionItemKey
|
|
|
|
| ActionItemBranchFilePath BranchFilePath
|
|
|
|
| ActionItemFailedTransfer Transfer TransferInfo
|
|
|
|
|
|
|
|
class MkActionItem t where
|
|
|
|
mkActionItem :: t -> ActionItem
|
|
|
|
|
|
|
|
instance MkActionItem AssociatedFile where
|
|
|
|
mkActionItem = ActionItemAssociatedFile
|
|
|
|
|
|
|
|
instance MkActionItem Key where
|
|
|
|
mkActionItem _ = ActionItemKey
|
|
|
|
|
|
|
|
instance MkActionItem BranchFilePath where
|
|
|
|
mkActionItem = ActionItemBranchFilePath
|
|
|
|
|
|
|
|
instance MkActionItem (Transfer, TransferInfo) where
|
|
|
|
mkActionItem = uncurry ActionItemFailedTransfer
|
|
|
|
|
|
|
|
actionItemDesc :: ActionItem -> Key -> String
|
2017-03-10 17:12:24 +00:00
|
|
|
actionItemDesc (ActionItemAssociatedFile (AssociatedFile (Just f))) _ = f
|
2019-01-14 17:03:35 +00:00
|
|
|
actionItemDesc (ActionItemAssociatedFile (AssociatedFile Nothing)) k = serializeKey k
|
|
|
|
actionItemDesc ActionItemKey k = serializeKey k
|
2016-08-03 16:37:12 +00:00
|
|
|
actionItemDesc (ActionItemBranchFilePath bfp) _ = descBranchFilePath bfp
|
2017-03-10 17:12:24 +00:00
|
|
|
actionItemDesc (ActionItemFailedTransfer _ i) k =
|
|
|
|
actionItemDesc (ActionItemAssociatedFile (associatedFile i)) k
|
2016-08-03 16:37:12 +00:00
|
|
|
|
|
|
|
actionItemWorkTreeFile :: ActionItem -> Maybe FilePath
|
2017-03-10 17:12:24 +00:00
|
|
|
actionItemWorkTreeFile (ActionItemAssociatedFile (AssociatedFile af)) = af
|
2016-08-03 16:37:12 +00:00
|
|
|
actionItemWorkTreeFile _ = Nothing
|
|
|
|
|
|
|
|
actionItemTransferDirection :: ActionItem -> Maybe Direction
|
|
|
|
actionItemTransferDirection (ActionItemFailedTransfer t _) = Just $
|
|
|
|
transferDirection t
|
|
|
|
actionItemTransferDirection _ = Nothing
|