{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Data.GI.Base.Attributes (
AttrInfo(..),
AttrOpTag(..),
AttrOp(..),
AttrOpAllowed,
AttrGetC,
AttrSetC,
AttrConstructC,
AttrClearC,
get,
set,
clear,
AttrLabelProxy(..),
resolveAttr,
bindPropToField,
EqMaybe(..)
) where
import Control.Monad (void, when)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Data.GI.Base.BasicTypes (GObject)
import Data.GI.Base.DynVal (DynVal(..), ModelProxy, DVKey(..),
modelProxyCurrentValue, modelProxyRegisterHandler,
modelProxyUpdate, dvKeys, dvRead)
import Data.GI.Base.GValue (GValueConstruct)
import Data.GI.Base.Overloading (HasAttributeList, ResolveAttribute,
ResolvedSymbolInfo)
import Data.GI.Base.Internal.PathFieldAccess (PathFieldAccess(..), Components)
import {-# SOURCE #-} Data.GI.Base.Signals (SignalInfo(..),
SignalProxy,
on, after, connectGObjectNotify,
SignalConnectMode(..))
import Data.Kind (Type)
import Data.Proxy (Proxy(..))
import qualified Data.Text as T
import GHC.TypeLits (Symbol, KnownSymbol, ErrorMessage(..), TypeError,
symbolVal)
import GHC.Exts (Constraint)
import GHC.OverloadedLabels (IsLabel(..))
import qualified Optics.Core as O
infixr 0 :=,:~,:=>,:~>,:<~,:!<~
data AttrLabelProxy (a :: Symbol) = AttrLabelProxy
#if MIN_VERSION_base(4,10,0)
instance a ~ x => IsLabel x (AttrLabelProxy a) where
fromLabel :: AttrLabelProxy a
fromLabel = AttrLabelProxy a
forall (a :: Symbol). AttrLabelProxy a
AttrLabelProxy
#else
instance a ~ x => IsLabel x (AttrLabelProxy a) where
fromLabel _ = AttrLabelProxy
#endif
class AttrInfo (info :: Type) where
type AttrAllowedOps info :: [AttrOpTag]
type AttrBaseTypeConstraint info :: Type -> Constraint
type AttrGetType info
type AttrSetTypeConstraint info :: Type -> Constraint
type AttrSetTypeConstraint info = (~) (AttrGetType info)
type AttrTransferTypeConstraint info :: Type -> Constraint
type AttrTransferTypeConstraint info = (~) (AttrTransferType info)
type AttrTransferType info :: Type
type AttrTransferType info = AttrGetType info
type AttrLabel info :: Symbol
type AttrOrigin info
attrGet :: AttrBaseTypeConstraint info o =>
o -> IO (AttrGetType info)
default attrGet ::
CheckNotElem 'AttrGet (AttrAllowedOps info)
(GetNotProvidedError info) =>
o -> IO (AttrGetType info)
attrGet = o -> IO (AttrGetType info)
forall a. HasCallStack => a
undefined
attrSet :: (AttrBaseTypeConstraint info o,
AttrSetTypeConstraint info b) =>
o -> b -> IO ()
default attrSet ::
CheckNotElem 'AttrSet (AttrAllowedOps info)
(SetNotProvidedError info) =>
o -> b -> IO ()
attrSet = o -> b -> IO ()
forall a. HasCallStack => a
undefined
attrClear :: AttrBaseTypeConstraint info o =>
o -> IO ()
default attrClear ::
CheckNotElem 'AttrClear (AttrAllowedOps info)
(ClearNotProvidedError info) =>
o -> IO ()
attrClear = o -> IO ()
forall a. HasCallStack => a
undefined
attrConstruct :: (AttrBaseTypeConstraint info o,
AttrSetTypeConstraint info b) =>
b -> IO (GValueConstruct o)
default attrConstruct ::
CheckNotElem 'AttrConstruct (AttrAllowedOps info)
(ConstructNotProvidedError info) =>
b -> IO (GValueConstruct o)
attrConstruct = b -> IO (GValueConstruct o)
forall a. HasCallStack => a
undefined
attrTransfer :: forall o b. (AttrBaseTypeConstraint info o,
AttrTransferTypeConstraint info b) =>
Proxy o -> b -> IO (AttrTransferType info)
default attrTransfer :: forall o b. (AttrBaseTypeConstraint info o,
AttrTransferTypeConstraint info b,
b ~ AttrGetType info,
b ~ AttrTransferType info) =>
Proxy o -> b -> IO (AttrTransferType info)
attrTransfer Proxy o
_ = b -> IO b
b -> IO (AttrTransferType info)
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return
attrPut :: AttrBaseTypeConstraint info o =>
o -> AttrGetType info -> IO ()
default attrPut ::
CheckNotElem 'AttrPut (AttrAllowedOps info)
(PutNotProvidedError info) =>
o -> AttrGetType info -> IO ()
attrPut = o -> AttrGetType info -> IO ()
forall a. HasCallStack => a
undefined
dbgAttrInfo :: Maybe ResolvedSymbolInfo
dbgAttrInfo = Maybe ResolvedSymbolInfo
forall a. Maybe a
Nothing
type family TypeOriginInfo definingType useType :: ErrorMessage where
TypeOriginInfo definingType definingType =
'Text "‘" ':<>: 'ShowType definingType ':<>: 'Text "’"
TypeOriginInfo definingType useType =
'Text "‘" ':<>: 'ShowType useType ':<>:
'Text "’ (inherited from parent type ‘" ':<>:
'ShowType definingType ':<>: 'Text "’)"
type family AttrOpIsAllowed (tag :: AttrOpTag) (ops :: [AttrOpTag]) (label :: Symbol) (definingType :: Type) (useType :: Type) :: Constraint where
AttrOpIsAllowed tag '[] label definingType useType =
TypeError ('Text "Attribute ‘" ':<>: 'Text label ':<>:
'Text "’ for type " ':<>:
TypeOriginInfo definingType useType ':<>:
'Text " is not " ':<>:
'Text (AttrOpText tag) ':<>: 'Text ".")
AttrOpIsAllowed tag (tag ': ops) label definingType useType = ()
AttrOpIsAllowed tag (other ': ops) label definingType useType = AttrOpIsAllowed tag ops label definingType useType
type family AttrOpAllowed (tag :: AttrOpTag) (info :: Type) (useType :: Type) :: Constraint where
AttrOpAllowed tag info useType =
AttrOpIsAllowed tag (AttrAllowedOps info) (AttrLabel info) (AttrOrigin info) useType
type family OpNotProvidedError (info :: o) (op :: AttrOpTag) (methodName :: Symbol) :: ErrorMessage where
OpNotProvidedError info op methodName =
'Text "The attribute ‘" ':<>: 'Text (AttrLabel info) ':<>:
'Text "’ for type ‘" ':<>:
'ShowType (AttrOrigin info) ':<>:
'Text "’ is declared as " ':<>:
'Text (AttrOpText op) ':<>:
'Text ", but no implementation of ‘" ':<>:
'Text methodName ':<>:
'Text "’ has been provided."
':$$: 'Text "Either provide an implementation of ‘" ':<>:
'Text methodName ':<>:
'Text "’ or remove ‘" ':<>:
'ShowType op ':<>:
'Text "’ from ‘AttrAllowedOps’."
type family ClearNotProvidedError (info :: o) :: ErrorMessage where
ClearNotProvidedError info = OpNotProvidedError info 'AttrClear "attrClear"
type family GetNotProvidedError (info :: o) :: ErrorMessage where
GetNotProvidedError info = OpNotProvidedError info 'AttrGet "attrGet"
type family SetNotProvidedError (info :: o) :: ErrorMessage where
SetNotProvidedError info = OpNotProvidedError info 'AttrSet "attrSet"
type family PutNotProvidedError (info :: o) :: ErrorMessage where
PutNotProvidedError info = OpNotProvidedError info 'AttrSet "attrPut"
type family ConstructNotProvidedError (info :: o) :: ErrorMessage where
ConstructNotProvidedError info = OpNotProvidedError info 'AttrConstruct "attrConstruct"
type family CheckNotElem (a :: k) (as :: [k]) (msg :: ErrorMessage) :: Constraint where
CheckNotElem a '[] msg = ()
CheckNotElem a (a ': rest) msg = TypeError msg
CheckNotElem a (other ': rest) msg = CheckNotElem a rest msg
data AttrOpTag = AttrGet
| AttrSet
| AttrConstruct
| AttrClear
| AttrPut
deriving (AttrOpTag -> AttrOpTag -> Bool
(AttrOpTag -> AttrOpTag -> Bool)
-> (AttrOpTag -> AttrOpTag -> Bool) -> Eq AttrOpTag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: AttrOpTag -> AttrOpTag -> Bool
== :: AttrOpTag -> AttrOpTag -> Bool
$c/= :: AttrOpTag -> AttrOpTag -> Bool
/= :: AttrOpTag -> AttrOpTag -> Bool
Eq, Eq AttrOpTag
Eq AttrOpTag =>
(AttrOpTag -> AttrOpTag -> Ordering)
-> (AttrOpTag -> AttrOpTag -> Bool)
-> (AttrOpTag -> AttrOpTag -> Bool)
-> (AttrOpTag -> AttrOpTag -> Bool)
-> (AttrOpTag -> AttrOpTag -> Bool)
-> (AttrOpTag -> AttrOpTag -> AttrOpTag)
-> (AttrOpTag -> AttrOpTag -> AttrOpTag)
-> Ord AttrOpTag
AttrOpTag -> AttrOpTag -> Bool
AttrOpTag -> AttrOpTag -> Ordering
AttrOpTag -> AttrOpTag -> AttrOpTag
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: AttrOpTag -> AttrOpTag -> Ordering
compare :: AttrOpTag -> AttrOpTag -> Ordering
$c< :: AttrOpTag -> AttrOpTag -> Bool
< :: AttrOpTag -> AttrOpTag -> Bool
$c<= :: AttrOpTag -> AttrOpTag -> Bool
<= :: AttrOpTag -> AttrOpTag -> Bool
$c> :: AttrOpTag -> AttrOpTag -> Bool
> :: AttrOpTag -> AttrOpTag -> Bool
$c>= :: AttrOpTag -> AttrOpTag -> Bool
>= :: AttrOpTag -> AttrOpTag -> Bool
$cmax :: AttrOpTag -> AttrOpTag -> AttrOpTag
max :: AttrOpTag -> AttrOpTag -> AttrOpTag
$cmin :: AttrOpTag -> AttrOpTag -> AttrOpTag
min :: AttrOpTag -> AttrOpTag -> AttrOpTag
Ord, Int -> AttrOpTag
AttrOpTag -> Int
AttrOpTag -> [AttrOpTag]
AttrOpTag -> AttrOpTag
AttrOpTag -> AttrOpTag -> [AttrOpTag]
AttrOpTag -> AttrOpTag -> AttrOpTag -> [AttrOpTag]
(AttrOpTag -> AttrOpTag)
-> (AttrOpTag -> AttrOpTag)
-> (Int -> AttrOpTag)
-> (AttrOpTag -> Int)
-> (AttrOpTag -> [AttrOpTag])
-> (AttrOpTag -> AttrOpTag -> [AttrOpTag])
-> (AttrOpTag -> AttrOpTag -> [AttrOpTag])
-> (AttrOpTag -> AttrOpTag -> AttrOpTag -> [AttrOpTag])
-> Enum AttrOpTag
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: AttrOpTag -> AttrOpTag
succ :: AttrOpTag -> AttrOpTag
$cpred :: AttrOpTag -> AttrOpTag
pred :: AttrOpTag -> AttrOpTag
$ctoEnum :: Int -> AttrOpTag
toEnum :: Int -> AttrOpTag
$cfromEnum :: AttrOpTag -> Int
fromEnum :: AttrOpTag -> Int
$cenumFrom :: AttrOpTag -> [AttrOpTag]
enumFrom :: AttrOpTag -> [AttrOpTag]
$cenumFromThen :: AttrOpTag -> AttrOpTag -> [AttrOpTag]
enumFromThen :: AttrOpTag -> AttrOpTag -> [AttrOpTag]
$cenumFromTo :: AttrOpTag -> AttrOpTag -> [AttrOpTag]
enumFromTo :: AttrOpTag -> AttrOpTag -> [AttrOpTag]
$cenumFromThenTo :: AttrOpTag -> AttrOpTag -> AttrOpTag -> [AttrOpTag]
enumFromThenTo :: AttrOpTag -> AttrOpTag -> AttrOpTag -> [AttrOpTag]
Enum, AttrOpTag
AttrOpTag -> AttrOpTag -> Bounded AttrOpTag
forall a. a -> a -> Bounded a
$cminBound :: AttrOpTag
minBound :: AttrOpTag
$cmaxBound :: AttrOpTag
maxBound :: AttrOpTag
Bounded, Int -> AttrOpTag -> ShowS
[AttrOpTag] -> ShowS
AttrOpTag -> String
(Int -> AttrOpTag -> ShowS)
-> (AttrOpTag -> String)
-> ([AttrOpTag] -> ShowS)
-> Show AttrOpTag
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> AttrOpTag -> ShowS
showsPrec :: Int -> AttrOpTag -> ShowS
$cshow :: AttrOpTag -> String
show :: AttrOpTag -> String
$cshowList :: [AttrOpTag] -> ShowS
showList :: [AttrOpTag] -> ShowS
Show)
type family AttrOpText (tag :: AttrOpTag) :: Symbol where
AttrOpText 'AttrGet = "gettable"
AttrOpText 'AttrSet = "settable"
AttrOpText 'AttrConstruct = "constructible"
AttrOpText 'AttrClear = "nullable"
AttrOpText 'AttrPut = "puttable"
type AttrSetC info obj attr value = (HasAttributeList obj,
info ~ ResolveAttribute attr obj,
AttrInfo info,
AttrBaseTypeConstraint info obj,
AttrOpAllowed 'AttrSet info obj,
(AttrSetTypeConstraint info) value)
type AttrConstructC info obj attr value = (HasAttributeList obj,
info ~ ResolveAttribute attr obj,
AttrInfo info,
AttrBaseTypeConstraint info obj,
AttrOpAllowed 'AttrConstruct info obj,
(AttrSetTypeConstraint info) value)
data AttrOp obj (tag :: AttrOpTag) where
(:=) :: (HasAttributeList obj,
info ~ ResolveAttribute attr obj,
AttrInfo info,
AttrBaseTypeConstraint info obj,
AttrOpAllowed tag info obj,
(AttrSetTypeConstraint info) b) =>
AttrLabelProxy (attr :: Symbol) -> b -> AttrOp obj tag
(:=>) :: (HasAttributeList obj,
info ~ ResolveAttribute attr obj,
AttrInfo info,
AttrBaseTypeConstraint info obj,
AttrOpAllowed tag info obj,
(AttrSetTypeConstraint info) b) =>
AttrLabelProxy (attr :: Symbol) -> IO b -> AttrOp obj tag
(:~) :: (HasAttributeList obj,
info ~ ResolveAttribute attr obj,
AttrInfo info,
AttrBaseTypeConstraint info obj,
tag ~ 'AttrSet,
AttrOpAllowed 'AttrSet info obj,
AttrOpAllowed 'AttrGet info obj,
(AttrSetTypeConstraint info) b,
a ~ (AttrGetType info)) =>
AttrLabelProxy (attr :: Symbol) -> (a -> b) -> AttrOp obj tag
(:~>) :: (HasAttributeList obj,
info ~ ResolveAttribute attr obj,
AttrInfo info,
AttrBaseTypeConstraint info obj,
tag ~ 'AttrSet,
AttrOpAllowed 'AttrSet info obj,
AttrOpAllowed 'AttrGet info obj,
(AttrSetTypeConstraint info) b,
a ~ (AttrGetType info)) =>
AttrLabelProxy (attr :: Symbol) -> (a -> IO b) -> AttrOp obj tag
(:&=) :: (HasAttributeList obj,
info ~ ResolveAttribute attr obj,
AttrInfo info,
AttrBaseTypeConstraint info obj,
AttrOpAllowed tag info obj,
(AttrTransferTypeConstraint info) b,
AttrSetTypeConstraint info (AttrTransferType info)) =>
AttrLabelProxy (attr :: Symbol) -> b -> AttrOp obj tag
(:!<~) :: (HasAttributeList obj,
info ~ ResolveAttribute attr obj,
AttrInfo info,
AttrBaseTypeConstraint info obj,
AttrOpAllowed tag info obj,
(AttrSetTypeConstraint info) b,
?_haskell_gi_modelProxy :: ModelProxy model
) =>
AttrLabelProxy (attr :: Symbol) -> DynVal model b -> AttrOp obj ta
(:<~) :: (HasAttributeList obj,
info ~ ResolveAttribute attr obj,
AttrInfo info,
AttrBaseTypeConstraint info obj,
AttrOpAllowed tag info obj,
(AttrSetTypeConstraint info) b,
AttrOpAllowed 'AttrGet info obj,
EqMaybe b (AttrGetType info),
?_haskell_gi_modelProxy :: ModelProxy model
) =>
AttrLabelProxy (attr :: Symbol) -> DynVal model b -> AttrOp obj tag
Bind :: (HasAttributeList obj,
GObject obj,
info ~ ResolveAttribute propName obj,
AttrInfo info,
KnownSymbol (AttrLabel info),
AttrBaseTypeConstraint info obj,
AttrOpAllowed tag info obj,
AttrOpAllowed 'AttrPut info obj,
?_haskell_gi_modelProxy :: ModelProxy model,
outType ~ AttrGetType info,
(AttrSetTypeConstraint info) outType,
components ~ Components fieldName,
PathFieldAccess components model outType,
KnownSymbol fieldName,
Eq outType
) =>
AttrLabelProxy (propName :: Symbol) ->
AttrLabelProxy (fieldName :: Symbol) ->
AttrOp obj tag
On :: (GObject obj, SignalInfo info) =>
SignalProxy obj info
-> ((?self :: obj) => HaskellCallbackType info)
-> AttrOp obj tag
After :: (GObject obj, SignalInfo info) =>
SignalProxy obj info
-> ((?self :: obj) => HaskellCallbackType info)
-> AttrOp obj tag
class EqMaybe a b where
eqMaybe :: a -> b -> Bool
instance Eq a => EqMaybe a a where
eqMaybe :: a -> a -> Bool
eqMaybe a
x a
y = a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y
instance Eq a => EqMaybe a (Maybe a) where
eqMaybe :: a -> Maybe a -> Bool
eqMaybe a
_ Maybe a
Nothing = Bool
False
eqMaybe a
x (Just a
y) = a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y
set :: forall o m. MonadIO m => o -> [AttrOp o 'AttrSet] -> m ()
set :: forall o (m :: * -> *).
MonadIO m =>
o -> [AttrOp o 'AttrSet] -> m ()
set o
obj = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ())
-> ([AttrOp o 'AttrSet] -> IO ()) -> [AttrOp o 'AttrSet] -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AttrOp o 'AttrSet -> IO ()) -> [AttrOp o 'AttrSet] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ AttrOp o 'AttrSet -> IO ()
app
where
app :: AttrOp o 'AttrSet -> IO ()
app :: AttrOp o 'AttrSet -> IO ()
app ((AttrLabelProxy attr
_attr :: AttrLabelProxy label) := b
x) =
forall info o b.
(AttrInfo info, AttrBaseTypeConstraint info o,
AttrSetTypeConstraint info b) =>
o -> b -> IO ()
attrSet @(ResolveAttribute label o) o
obj b
x
app ((AttrLabelProxy attr
_attr :: AttrLabelProxy label) :=> IO b
x) =
IO b
x IO b -> (b -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall info o b.
(AttrInfo info, AttrBaseTypeConstraint info o,
AttrSetTypeConstraint info b) =>
o -> b -> IO ()
attrSet @(ResolveAttribute label o) o
obj
app ((AttrLabelProxy attr
_attr :: AttrLabelProxy label) :~ a -> b
f) =
forall info o.
(AttrInfo info, AttrBaseTypeConstraint info o) =>
o -> IO (AttrGetType info)
attrGet @(ResolveAttribute label o) o
obj IO a -> (a -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
\a
v -> forall info o b.
(AttrInfo info, AttrBaseTypeConstraint info o,
AttrSetTypeConstraint info b) =>
o -> b -> IO ()
attrSet @(ResolveAttribute label o) o
obj (a -> b
f a
v)
app ((AttrLabelProxy attr
_attr :: AttrLabelProxy label) :~> a -> IO b
f) =
forall info o.
(AttrInfo info, AttrBaseTypeConstraint info o) =>
o -> IO (AttrGetType info)
attrGet @(ResolveAttribute label o) o
obj IO a -> (a -> IO b) -> IO b
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= a -> IO b
f IO b -> (b -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
forall info o b.
(AttrInfo info, AttrBaseTypeConstraint info o,
AttrSetTypeConstraint info b) =>
o -> b -> IO ()
attrSet @(ResolveAttribute label o) o
obj
app ((AttrLabelProxy attr
_attr :: AttrLabelProxy label) :&= b
x) =
forall info o b.
(AttrInfo info, AttrBaseTypeConstraint info o,
AttrTransferTypeConstraint info b) =>
Proxy o -> b -> IO (AttrTransferType info)
attrTransfer @(ResolveAttribute label o) (forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @o) b
x IO (AttrTransferType info)
-> (AttrTransferType info -> IO ()) -> IO ()
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>=
forall info o b.
(AttrInfo info, AttrBaseTypeConstraint info o,
AttrSetTypeConstraint info b) =>
o -> b -> IO ()
attrSet @(ResolveAttribute label o) o
obj
app ((AttrLabelProxy attr
_attr :: AttrLabelProxy label) :!<~ DynVal model b
dv) = do
model
model <- ModelProxy model -> IO model
forall model. ModelProxy model -> IO model
modelProxyCurrentValue ?_haskell_gi_modelProxy::ModelProxy model
ModelProxy model
?_haskell_gi_modelProxy
forall info o b.
(AttrInfo info, AttrBaseTypeConstraint info o,
AttrSetTypeConstraint info b) =>
o -> b -> IO ()
attrSet @(ResolveAttribute label o) o
obj (DynVal model b -> model -> b
forall model a. DynVal model a -> model -> a
dvRead DynVal model b
dv model
model)
ModelProxy model -> DVKey -> (model -> IO ()) -> IO ()
forall model.
ModelProxy model -> DVKey -> (model -> IO ()) -> IO ()
modelProxyRegisterHandler ?_haskell_gi_modelProxy::ModelProxy model
ModelProxy model
?_haskell_gi_modelProxy (DynVal model b -> DVKey
forall model a. DynVal model a -> DVKey
dvKeys DynVal model b
dv) ((model -> IO ()) -> IO ()) -> (model -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \model
modifiedModel ->
forall info o b.
(AttrInfo info, AttrBaseTypeConstraint info o,
AttrSetTypeConstraint info b) =>
o -> b -> IO ()
attrSet @(ResolveAttribute label o) o
obj (DynVal model b -> model -> b
forall model a. DynVal model a -> model -> a
dvRead DynVal model b
dv model
modifiedModel)
app ((AttrLabelProxy attr
_attr :: AttrLabelProxy label) :<~ DynVal model b
dv) = do
model
model <- ModelProxy model -> IO model
forall model. ModelProxy model -> IO model
modelProxyCurrentValue ?_haskell_gi_modelProxy::ModelProxy model
ModelProxy model
?_haskell_gi_modelProxy
AttrGetType info
currentValue <- forall info o.
(AttrInfo info, AttrBaseTypeConstraint info o) =>
o -> IO (AttrGetType info)
attrGet @(ResolveAttribute label o) o
obj
let newValue :: b
newValue = DynVal model b -> model -> b
forall model a. DynVal model a -> model -> a
dvRead DynVal model b
dv model
model
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ b
newValue b -> AttrGetType info -> Bool
forall a b. EqMaybe a b => a -> b -> Bool
`eqMaybe` AttrGetType info
currentValue) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$ do
forall info o b.
(AttrInfo info, AttrBaseTypeConstraint info o,
AttrSetTypeConstraint info b) =>
o -> b -> IO ()
attrSet @(ResolveAttribute label o) o
obj b
newValue
ModelProxy model -> DVKey -> (model -> IO ()) -> IO ()
forall model.
ModelProxy model -> DVKey -> (model -> IO ()) -> IO ()
modelProxyRegisterHandler ?_haskell_gi_modelProxy::ModelProxy model
ModelProxy model
?_haskell_gi_modelProxy (DynVal model b -> DVKey
forall model a. DynVal model a -> DVKey
dvKeys DynVal model b
dv) ((model -> IO ()) -> IO ()) -> (model -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \model
modifiedModel -> do
AttrGetType info
current <- forall info o.
(AttrInfo info, AttrBaseTypeConstraint info o) =>
o -> IO (AttrGetType info)
attrGet @(ResolveAttribute label o) o
obj
let modifiedValue :: b
modifiedValue = DynVal model b -> model -> b
forall model a. DynVal model a -> model -> a
dvRead DynVal model b
dv model
modifiedModel
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ b
modifiedValue b -> AttrGetType info -> Bool
forall a b. EqMaybe a b => a -> b -> Bool
`eqMaybe` AttrGetType info
current) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
forall info o b.
(AttrInfo info, AttrBaseTypeConstraint info o,
AttrSetTypeConstraint info b) =>
o -> b -> IO ()
attrSet @(ResolveAttribute label o) o
obj b
modifiedValue
app (Bind AttrLabelProxy propName
pattr AttrLabelProxy fieldName
fattr) = Proxy 'AttrSet
-> o
-> AttrLabelProxy propName
-> AttrLabelProxy fieldName
-> IO ()
forall o info (prop :: Symbol) (field :: Symbol) model outType
(tag :: AttrOpTag) (components :: [Symbol]).
(HasAttributeList o, GObject o, info ~ ResolveAttribute prop o,
AttrInfo info, KnownSymbol (AttrLabel info),
AttrBaseTypeConstraint info o, AttrOpAllowed tag info o,
AttrOpAllowed 'AttrPut info o,
?_haskell_gi_modelProxy::ModelProxy model,
outType ~ AttrGetType info, AttrSetTypeConstraint info outType,
components ~ Components field,
PathFieldAccess components model outType, KnownSymbol field,
Eq outType) =>
Proxy tag
-> o -> AttrLabelProxy prop -> AttrLabelProxy field -> IO ()
bindPropToField (forall {k} (t :: k). Proxy t
forall (t :: AttrOpTag). Proxy t
Proxy @'AttrSet) o
obj AttrLabelProxy propName
pattr AttrLabelProxy fieldName
fattr
app (On SignalProxy o info
signal (?self::o) => HaskellCallbackType info
callback) = IO SignalHandlerId -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO SignalHandlerId -> IO ()) -> IO SignalHandlerId -> IO ()
forall a b. (a -> b) -> a -> b
$ o
-> SignalProxy o info
-> ((?self::o) => HaskellCallbackType info)
-> IO SignalHandlerId
forall object info (m :: * -> *).
(GObject object, MonadIO m, SignalInfo info) =>
object
-> SignalProxy object info
-> ((?self::object) => HaskellCallbackType info)
-> m SignalHandlerId
on o
obj SignalProxy o info
signal HaskellCallbackType info
(?self::o) => HaskellCallbackType info
callback
app (After SignalProxy o info
signal (?self::o) => HaskellCallbackType info
callback) = IO SignalHandlerId -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO SignalHandlerId -> IO ()) -> IO SignalHandlerId -> IO ()
forall a b. (a -> b) -> a -> b
$ o
-> SignalProxy o info
-> ((?self::o) => HaskellCallbackType info)
-> IO SignalHandlerId
forall object info (m :: * -> *).
(GObject object, MonadIO m, SignalInfo info) =>
object
-> SignalProxy object info
-> ((?self::object) => HaskellCallbackType info)
-> m SignalHandlerId
after o
obj SignalProxy o info
signal HaskellCallbackType info
(?self::o) => HaskellCallbackType info
callback
type AttrGetC info obj attr result = (HasAttributeList obj,
info ~ ResolveAttribute attr obj,
AttrInfo info,
(AttrBaseTypeConstraint info) obj,
AttrOpAllowed 'AttrGet info obj,
result ~ AttrGetType info)
get :: forall info attr obj result m.
(AttrGetC info obj attr result, MonadIO m) =>
obj -> AttrLabelProxy (attr :: Symbol) -> m result
get :: forall info (attr :: Symbol) obj result (m :: * -> *).
(AttrGetC info obj attr result, MonadIO m) =>
obj -> AttrLabelProxy attr -> m result
get obj
o AttrLabelProxy attr
_ = IO (AttrGetType info) -> m (AttrGetType info)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (AttrGetType info) -> m (AttrGetType info))
-> IO (AttrGetType info) -> m (AttrGetType info)
forall a b. (a -> b) -> a -> b
$ forall info o.
(AttrInfo info, AttrBaseTypeConstraint info o) =>
o -> IO (AttrGetType info)
attrGet @info obj
o
type AttrClearC info obj attr = (HasAttributeList obj,
info ~ ResolveAttribute attr obj,
AttrInfo info,
(AttrBaseTypeConstraint info) obj,
AttrOpAllowed 'AttrClear info obj)
clear :: forall info attr obj m.
(AttrClearC info obj attr, MonadIO m) =>
obj -> AttrLabelProxy (attr :: Symbol) -> m ()
clear :: forall info (attr :: Symbol) obj (m :: * -> *).
(AttrClearC info obj attr, MonadIO m) =>
obj -> AttrLabelProxy attr -> m ()
clear obj
o AttrLabelProxy attr
_ = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ forall info o.
(AttrInfo info, AttrBaseTypeConstraint info o) =>
o -> IO ()
attrClear @info obj
o
resolveAttr :: forall info attr obj.
(HasAttributeList obj, info ~ ResolveAttribute attr obj,
AttrInfo info) =>
obj -> AttrLabelProxy (attr :: Symbol) -> Maybe ResolvedSymbolInfo
resolveAttr :: forall info (attr :: Symbol) obj.
(HasAttributeList obj, info ~ ResolveAttribute attr obj,
AttrInfo info) =>
obj -> AttrLabelProxy attr -> Maybe ResolvedSymbolInfo
resolveAttr obj
_o AttrLabelProxy attr
_p = forall info. AttrInfo info => Maybe ResolvedSymbolInfo
dbgAttrInfo @info
bindPropToField :: forall o info prop field model outType tag components.
(HasAttributeList o,
GObject o,
info ~ ResolveAttribute prop o,
AttrInfo info,
KnownSymbol (AttrLabel info),
AttrBaseTypeConstraint info o,
AttrOpAllowed tag info o,
AttrOpAllowed 'AttrPut info o,
?_haskell_gi_modelProxy :: ModelProxy model,
outType ~ AttrGetType info,
(AttrSetTypeConstraint info) outType,
components ~ Components field,
PathFieldAccess components model outType,
KnownSymbol field,
Eq outType
) =>
Proxy tag -> o -> AttrLabelProxy (prop :: Symbol) ->
AttrLabelProxy (field :: Symbol) -> IO ()
bindPropToField :: forall o info (prop :: Symbol) (field :: Symbol) model outType
(tag :: AttrOpTag) (components :: [Symbol]).
(HasAttributeList o, GObject o, info ~ ResolveAttribute prop o,
AttrInfo info, KnownSymbol (AttrLabel info),
AttrBaseTypeConstraint info o, AttrOpAllowed tag info o,
AttrOpAllowed 'AttrPut info o,
?_haskell_gi_modelProxy::ModelProxy model,
outType ~ AttrGetType info, AttrSetTypeConstraint info outType,
components ~ Components field,
PathFieldAccess components model outType, KnownSymbol field,
Eq outType) =>
Proxy tag
-> o -> AttrLabelProxy prop -> AttrLabelProxy field -> IO ()
bindPropToField Proxy tag
_ o
obj AttrLabelProxy prop
_ AttrLabelProxy field
_ = do
model
model <- ModelProxy model -> IO model
forall model. ModelProxy model -> IO model
modelProxyCurrentValue ?_haskell_gi_modelProxy::ModelProxy model
ModelProxy model
?_haskell_gi_modelProxy
outType
currentPropValue <- forall info o.
(AttrInfo info, AttrBaseTypeConstraint info o) =>
o -> IO (AttrGetType info)
attrGet @(ResolveAttribute prop o) o
obj
let (Lens' model outType
lens, [Text]
components) = Proxy components -> Proxy model -> (Lens' model outType, [Text])
forall (path :: [Symbol]) model val.
PathFieldAccess path model val =>
Proxy path -> Proxy model -> (Lens' model val, [Text])
pathFieldAccess (forall (t :: [Symbol]). Proxy t
forall {k} (t :: k). Proxy t
Proxy @components)
(forall t. Proxy t
forall {k} (t :: k). Proxy t
Proxy @model)
key :: DVKey
key = [Text] -> DVKey
DVKeyDirect [Text]
components
currentModelValue :: outType
currentModelValue = Lens' model outType -> model -> outType
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
O.view Lens' model outType
lens model
model
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (outType
currentModelValue outType -> outType -> Bool
forall a. Eq a => a -> a -> Bool
/= outType
currentPropValue) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
forall info o.
(AttrInfo info, AttrBaseTypeConstraint info o) =>
o -> AttrGetType info -> IO ()
attrPut @(ResolveAttribute prop o) o
obj outType
AttrGetType (ResolveAttribute prop o)
currentModelValue
ModelProxy model -> DVKey -> (model -> IO ()) -> IO ()
forall model.
ModelProxy model -> DVKey -> (model -> IO ()) -> IO ()
modelProxyRegisterHandler ?_haskell_gi_modelProxy::ModelProxy model
ModelProxy model
?_haskell_gi_modelProxy DVKey
key ((model -> IO ()) -> IO ()) -> (model -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \model
modifiedModel -> do
let newVal :: outType
newVal = Lens' model outType -> model -> outType
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
O.view Lens' model outType
lens model
modifiedModel
outType
oldVal <- forall info o.
(AttrInfo info, AttrBaseTypeConstraint info o) =>
o -> IO (AttrGetType info)
attrGet @(ResolveAttribute prop o) o
obj
Bool -> IO () -> IO ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (outType
newVal outType -> outType -> Bool
forall a. Eq a => a -> a -> Bool
/= outType
oldVal) (IO () -> IO ()) -> IO () -> IO ()
forall a b. (a -> b) -> a -> b
$
forall info o.
(AttrInfo info, AttrBaseTypeConstraint info o) =>
o -> AttrGetType info -> IO ()
attrPut @(ResolveAttribute prop o) o
obj outType
AttrGetType (ResolveAttribute prop o)
newVal
let handler :: o -> GParamSpec -> IO ()
handler = \o
_parent GParamSpec
_psec -> do
outType
newVal <- forall info o.
(AttrInfo info, AttrBaseTypeConstraint info o) =>
o -> IO (AttrGetType info)
attrGet @(ResolveAttribute prop o) o
obj
let doUpdate :: model -> Maybe model
doUpdate model
curModel =
let oldVal :: outType
oldVal = Lens' model outType -> model -> outType
forall k (is :: IxList) s a.
Is k A_Getter =>
Optic' k is s a -> s -> a
O.view Lens' model outType
lens model
curModel
in if outType
newVal outType -> outType -> Bool
forall a. Eq a => a -> a -> Bool
== outType
oldVal
then Maybe model
forall a. Maybe a
Nothing
else model -> Maybe model
forall a. a -> Maybe a
Just (model -> Maybe model) -> model -> Maybe model
forall a b. (a -> b) -> a -> b
$ Lens' model outType -> outType -> model -> model
forall k (is :: IxList) s t a b.
Is k A_Setter =>
Optic k is s t a b -> b -> s -> t
O.set Lens' model outType
lens outType
newVal model
curModel
ModelProxy model -> [Text] -> (model -> Maybe model) -> IO ()
forall model.
ModelProxy model -> [Text] -> (model -> Maybe model) -> IO ()
modelProxyUpdate ?_haskell_gi_modelProxy::ModelProxy model
ModelProxy model
?_haskell_gi_modelProxy [Text]
components model -> Maybe model
doUpdate
propName :: Text
propName = String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ Proxy (AttrLabel info) -> String
forall (n :: Symbol) (proxy :: Symbol -> *).
KnownSymbol n =>
proxy n -> String
symbolVal (forall {k} (t :: k). Proxy t
forall (t :: Symbol). Proxy t
Proxy @(AttrLabel (ResolveAttribute prop o)))
IO SignalHandlerId -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO SignalHandlerId -> IO ()) -> IO SignalHandlerId -> IO ()
forall a b. (a -> b) -> a -> b
$ o
-> (o -> GParamSpec -> IO ())
-> SignalConnectMode
-> Maybe Text
-> IO SignalHandlerId
forall o.
GObject o =>
o
-> (o -> GParamSpec -> IO ())
-> SignalConnectMode
-> Maybe Text
-> IO SignalHandlerId
connectGObjectNotify o
obj o -> GParamSpec -> IO ()
handler SignalConnectMode
SignalConnectBefore (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
propName)