module Manatee.Plugin.Anything.Types where
import Control.Applicative hiding (empty)
import Control.Concurrent
import Control.Concurrent.STM
import DBus.Client hiding (Signal)
import Data.Map (Map)
import Data.Text.Lazy (Text)
import Data.Typeable
import Graphics.UI.Gtk hiding (get)
import Manatee.Core.Types
import Manatee.Plugin.Anything.TitleWidget
type AnythingName = String
type AnythingInput = String
type AnythingCompletion = String
type AnythingList = Map AnythingName Anything
type AnythingFilterRule = AnythingInput -> String -> Bool
type AnythingCompletionRule = AnythingInput -> AnythingCompletion
type AnythingColumnTitle = String
type AnythingColumnFun = AnythingCandidateWrap -> String
type AnythingCommandName = String
type AnythingAction = Client -> IO ()
type AnythingCommandFun = AnythingInput
-> AnythingCandidateWrap
-> AnythingInteractiveType
-> IO [(AnythingCommandName, AnythingAction)]
type AnythingSearchCache =
Map String (Either
(MVar [AnythingCandidateWrap], ThreadId, ThreadId)
HandlerId)
data FocusNode = FocusFirstNode
| FocusLastNode
deriving (Show, Ord, Eq)
class Typeable a => AnythingCandidate a where
candidateCommandName :: a -> String
candidateFilterName :: a -> String
candidateCompletionName :: a -> AnythingInput -> String
candidateExpandName :: a -> String -> IO String
data AnythingCandidateWrap = forall candidate . AnythingCandidate candidate =>
AnythingCandidateWrap {acwCandidate :: candidate}
data AnythingSearch = forall candidate . AnythingCandidate candidate =>
AnythingSearch {anythingSearchFun :: AnythingInput -> Client -> IO [candidate]}
data Anything =
Anything {anythingColumnTitle :: [AnythingColumnTitle]
,anythingColumnFun :: [AnythingColumnFun]
,anythingSearch :: AnythingSearch
,anythingFilterRule :: AnythingFilterRule
,anythingCompletionRule :: AnythingCompletionRule
,anythingInputDepend :: Bool
,anythingCommandFun :: AnythingCommandFun
,anythingCalculateDelay :: Int
}
instance AnythingCandidate String where
candidateCommandName = id
candidateFilterName = id
candidateCompletionName a _ = a
candidateExpandName a _ = return a
data AnythingView =
AnythingView {avNotebook :: Notebook
,avCandidateBox :: VBox
,avCandidateScrolledWindow :: ScrolledWindow
,avCandidateTab :: TVar AnythingCandidateTab
,avCommandTab :: AnythingCommandTab
,avCurrentCandidateIndex :: TVar Int
,avInteractiveType :: TVar AnythingInteractiveType
}
data AnythingCandidateView =
AnythingCandidateView {acavTreeView :: TreeView
,acavScrolledWindow :: ScrolledWindow
,acavListStore :: AnythingCandidateStore
,acavTitleWidget :: TitleWidget
}
data AnythingCommandView =
AnythingCommandView {acovTreeView :: TreeView
,acovListStore :: AnythingCommandStore}
type AnythingCandidateStore = ListStore AnythingCandidateWrap
type AnythingCommandStore = ListStore String
type AnythingCandidateTab = (Map Int ((AnythingName, Int), AnythingCandidateView))
type AnythingCommandTab = AnythingCommandView
data AnythingViewEnvironment =
AnythingViewEnvironment {aeView :: AnythingView
,aeClient :: Client
,aeCache :: TVar AnythingSearchCache
,aeInput :: AnythingViewInput
,aeKeyPressId :: Int}
data AnythingViewInput =
AnythingViewInput {aviAllText :: String
,aviUnselectText :: String}
class AnythingViewActionArgs a where
anythingViewExecute :: AnythingViewEnvironment -> IO a
data AnythingViewAction = forall a . AnythingViewActionArgs a =>
AnythingViewAction {anythingViewActionFun :: a -> IO ()}
type AnythingViewKeymap = Map Text AnythingViewAction
instance (AnythingViewActionArgs a, AnythingViewActionArgs b) => AnythingViewActionArgs (a, b) where
anythingViewExecute env = liftA2 (,) (anythingViewExecute env) (anythingViewExecute env)
instance AnythingViewActionArgs AnythingView where
anythingViewExecute env = return $ aeView env
instance AnythingViewActionArgs Client where
anythingViewExecute env = return $ aeClient env
instance AnythingViewActionArgs (TVar AnythingSearchCache) where
anythingViewExecute env = return $ aeCache env
instance AnythingViewActionArgs AnythingViewInput where
anythingViewExecute env = return $ aeInput env
instance AnythingViewActionArgs Int where
anythingViewExecute env = return $ aeKeyPressId env