{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
module Matterhorn.Events.ManageAttachments
  ( onEventAttachmentList
  , onEventBrowseFile
  , attachmentListKeybindings
  , attachmentBrowseKeyHandlers
  , attachmentBrowseKeybindings
  , attachmentListKeyHandlers
  )
where

import           Prelude ()
import           Matterhorn.Prelude

import           Brick.Keybindings
import qualified Brick.Widgets.FileBrowser as FB
import qualified Brick.Widgets.List as L
import qualified Data.Text as T
import qualified Data.Vector as Vector
import qualified Graphics.Vty as V
import           Lens.Micro.Platform ( (?=), (%=), to, Lens', (.=) )

import           Matterhorn.Types
import           Matterhorn.State.Attachments
import           Matterhorn.State.Common


onEventAttachmentList :: Lens' ChatState (MessageInterface Name i)
                      -> V.Event
                      -> MH Bool
onEventAttachmentList :: forall i.
Lens' ChatState (MessageInterface Name i) -> Event -> MH Bool
onEventAttachmentList Lens' ChatState (MessageInterface Name i)
which =
    [Event -> MH Bool] -> Event -> MH Bool
handleEventWith [ (KeyConfig KeyEvent -> KeyDispatcher KeyEvent MH)
-> Event -> MH Bool
mhHandleKeyboardEvent (Lens' ChatState (MessageInterface Name i)
-> KeyConfig KeyEvent -> KeyDispatcher KeyEvent MH
forall i.
Lens' ChatState (MessageInterface Name i)
-> KeyConfig KeyEvent -> KeyDispatcher KeyEvent MH
attachmentListKeybindings (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which)
                    , \Event
e -> Lens' ChatState (GenericList Name Vector AttachmentData)
-> (Event
    -> EventM Name (GenericList Name Vector AttachmentData) ())
-> Event
-> MH ()
forall b e.
Lens' ChatState b -> (e -> EventM Name b ()) -> e -> MH ()
mhZoom ((MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> f (MessageInterface Name i))
 -> ChatState -> f ChatState)
-> ((GenericList Name Vector AttachmentData
     -> f (GenericList Name Vector AttachmentData))
    -> MessageInterface Name i -> f (MessageInterface Name i))
-> (GenericList Name Vector AttachmentData
    -> f (GenericList Name Vector AttachmentData))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> f (EditState Name))
-> MessageInterface Name i -> f (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> f (EditState Name))
 -> MessageInterface Name i -> f (MessageInterface Name i))
-> ((GenericList Name Vector AttachmentData
     -> f (GenericList Name Vector AttachmentData))
    -> EditState Name -> f (EditState Name))
-> (GenericList Name Vector AttachmentData
    -> f (GenericList Name Vector AttachmentData))
-> MessageInterface Name i
-> f (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(GenericList Name Vector AttachmentData
 -> f (GenericList Name Vector AttachmentData))
-> EditState Name -> f (EditState Name)
forall n (f :: * -> *).
Functor f =>
(List n AttachmentData -> f (List n AttachmentData))
-> EditState n -> f (EditState n)
esAttachmentList) Event -> EventM Name (GenericList Name Vector AttachmentData) ()
forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
Event -> EventM n (GenericList n t e) ()
L.handleListEvent Event
e MH () -> MH Bool -> MH Bool
forall a b. MH a -> MH b -> MH b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> MH Bool
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
                    ]

attachmentListKeybindings :: Lens' ChatState (MessageInterface Name i)
                          -> KeyConfig KeyEvent
                          -> KeyDispatcher KeyEvent MH
attachmentListKeybindings :: forall i.
Lens' ChatState (MessageInterface Name i)
-> KeyConfig KeyEvent -> KeyDispatcher KeyEvent MH
attachmentListKeybindings Lens' ChatState (MessageInterface Name i)
which KeyConfig KeyEvent
kc = KeyConfig KeyEvent
-> [KeyEventHandler KeyEvent MH] -> KeyDispatcher KeyEvent MH
forall k (m :: * -> *).
Ord k =>
KeyConfig k -> [KeyEventHandler k m] -> KeyDispatcher k m
unsafeKeyDispatcher KeyConfig KeyEvent
kc (Lens' ChatState (MessageInterface Name i)
-> [KeyEventHandler KeyEvent MH]
forall i.
Lens' ChatState (MessageInterface Name i)
-> [KeyEventHandler KeyEvent MH]
attachmentListKeyHandlers (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which)

attachmentListKeyHandlers :: Lens' ChatState (MessageInterface Name i)
                          -> [MHKeyEventHandler]
attachmentListKeyHandlers :: forall i.
Lens' ChatState (MessageInterface Name i)
-> [KeyEventHandler KeyEvent MH]
attachmentListKeyHandlers Lens' ChatState (MessageInterface Name i)
which =
    [ KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
CancelEvent Text
"Close attachment list" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
          (MessageInterface Name i -> Identity (MessageInterface Name i))
-> ChatState -> Identity ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> Identity (MessageInterface Name i))
 -> ChatState -> Identity ChatState)
-> ((MessageInterfaceMode -> Identity MessageInterfaceMode)
    -> MessageInterface Name i -> Identity (MessageInterface Name i))
-> (MessageInterfaceMode -> Identity MessageInterfaceMode)
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(MessageInterfaceMode -> Identity MessageInterfaceMode)
-> MessageInterface Name i -> Identity (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(MessageInterfaceMode -> f MessageInterfaceMode)
-> MessageInterface n i -> f (MessageInterface n i)
miMode ((MessageInterfaceMode -> Identity MessageInterfaceMode)
 -> ChatState -> Identity ChatState)
-> MessageInterfaceMode -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= MessageInterfaceMode
Compose
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
SelectUpEvent Text
"Move cursor up" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
          Lens' ChatState (GenericList Name Vector AttachmentData)
-> (Event
    -> EventM Name (GenericList Name Vector AttachmentData) ())
-> Event
-> MH ()
forall b e.
Lens' ChatState b -> (e -> EventM Name b ()) -> e -> MH ()
mhZoom ((MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> f (MessageInterface Name i))
 -> ChatState -> f ChatState)
-> ((GenericList Name Vector AttachmentData
     -> f (GenericList Name Vector AttachmentData))
    -> MessageInterface Name i -> f (MessageInterface Name i))
-> (GenericList Name Vector AttachmentData
    -> f (GenericList Name Vector AttachmentData))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> f (EditState Name))
-> MessageInterface Name i -> f (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> f (EditState Name))
 -> MessageInterface Name i -> f (MessageInterface Name i))
-> ((GenericList Name Vector AttachmentData
     -> f (GenericList Name Vector AttachmentData))
    -> EditState Name -> f (EditState Name))
-> (GenericList Name Vector AttachmentData
    -> f (GenericList Name Vector AttachmentData))
-> MessageInterface Name i
-> f (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(GenericList Name Vector AttachmentData
 -> f (GenericList Name Vector AttachmentData))
-> EditState Name -> f (EditState Name)
forall n (f :: * -> *).
Functor f =>
(List n AttachmentData -> f (List n AttachmentData))
-> EditState n -> f (EditState n)
esAttachmentList) Event -> EventM Name (GenericList Name Vector AttachmentData) ()
forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
Event -> EventM n (GenericList n t e) ()
L.handleListEvent (Key -> [Modifier] -> Event
V.EvKey Key
V.KUp [])
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
SelectDownEvent Text
"Move cursor down" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
          Lens' ChatState (GenericList Name Vector AttachmentData)
-> (Event
    -> EventM Name (GenericList Name Vector AttachmentData) ())
-> Event
-> MH ()
forall b e.
Lens' ChatState b -> (e -> EventM Name b ()) -> e -> MH ()
mhZoom ((MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> f (MessageInterface Name i))
 -> ChatState -> f ChatState)
-> ((GenericList Name Vector AttachmentData
     -> f (GenericList Name Vector AttachmentData))
    -> MessageInterface Name i -> f (MessageInterface Name i))
-> (GenericList Name Vector AttachmentData
    -> f (GenericList Name Vector AttachmentData))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> f (EditState Name))
-> MessageInterface Name i -> f (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> f (EditState Name))
 -> MessageInterface Name i -> f (MessageInterface Name i))
-> ((GenericList Name Vector AttachmentData
     -> f (GenericList Name Vector AttachmentData))
    -> EditState Name -> f (EditState Name))
-> (GenericList Name Vector AttachmentData
    -> f (GenericList Name Vector AttachmentData))
-> MessageInterface Name i
-> f (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(GenericList Name Vector AttachmentData
 -> f (GenericList Name Vector AttachmentData))
-> EditState Name -> f (EditState Name)
forall n (f :: * -> *).
Functor f =>
(List n AttachmentData -> f (List n AttachmentData))
-> EditState n -> f (EditState n)
esAttachmentList) Event -> EventM Name (GenericList Name Vector AttachmentData) ()
forall (t :: * -> *) n e.
(Foldable t, Splittable t, Ord n) =>
Event -> EventM n (GenericList n t e) ()
L.handleListEvent (Key -> [Modifier] -> Event
V.EvKey Key
V.KDown [])
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
AttachmentListAddEvent Text
"Add a new attachment to the attachment list" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
          Lens' ChatState (MessageInterface Name i) -> MH ()
forall i. Lens' ChatState (MessageInterface Name i) -> MH ()
showAttachmentFileBrowser (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
AttachmentOpenEvent Text
"Open the selected attachment using the URL open command" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
          Lens' ChatState (MessageInterface Name i) -> MH ()
forall i. Lens' ChatState (MessageInterface Name i) -> MH ()
openSelectedAttachment (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
AttachmentListDeleteEvent Text
"Delete the selected attachment from the attachment list" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
          Lens' ChatState (MessageInterface Name i) -> MH ()
forall i. Lens' ChatState (MessageInterface Name i) -> MH ()
deleteSelectedAttachment (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which
    ]

attachmentBrowseKeybindings :: Lens' ChatState (MessageInterface Name i)
                            -> KeyConfig KeyEvent
                            -> KeyDispatcher KeyEvent MH
attachmentBrowseKeybindings :: forall i.
Lens' ChatState (MessageInterface Name i)
-> KeyConfig KeyEvent -> KeyDispatcher KeyEvent MH
attachmentBrowseKeybindings Lens' ChatState (MessageInterface Name i)
which KeyConfig KeyEvent
kc =
    KeyConfig KeyEvent
-> [KeyEventHandler KeyEvent MH] -> KeyDispatcher KeyEvent MH
forall k (m :: * -> *).
Ord k =>
KeyConfig k -> [KeyEventHandler k m] -> KeyDispatcher k m
unsafeKeyDispatcher KeyConfig KeyEvent
kc (Lens' ChatState (MessageInterface Name i)
-> [KeyEventHandler KeyEvent MH]
forall i.
Lens' ChatState (MessageInterface Name i)
-> [KeyEventHandler KeyEvent MH]
attachmentBrowseKeyHandlers (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which)

attachmentBrowseKeyHandlers :: Lens' ChatState (MessageInterface Name i)
                            -> [MHKeyEventHandler]
attachmentBrowseKeyHandlers :: forall i.
Lens' ChatState (MessageInterface Name i)
-> [KeyEventHandler KeyEvent MH]
attachmentBrowseKeyHandlers Lens' ChatState (MessageInterface Name i)
which =
    [ KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
CancelEvent Text
"Cancel attachment file browse" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
      Lens' ChatState (MessageInterface Name i) -> MH ()
forall i. Lens' ChatState (MessageInterface Name i) -> MH ()
cancelAttachmentBrowse (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
AttachmentOpenEvent Text
"Open the selected file using the URL open command" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
      Lens' ChatState (MessageInterface Name i) -> MH ()
forall i. Lens' ChatState (MessageInterface Name i) -> MH ()
openSelectedBrowserEntry (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
FileBrowserBeginSearchEvent Text
"Begin search for name in list" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
      Lens' ChatState (FileBrowser Name)
-> EventM Name (FileBrowser Name) () -> MH ()
forall b. Lens' ChatState b -> EventM Name b () -> MH ()
mhZoom' ((MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> f (MessageInterface Name i))
 -> ChatState -> f ChatState)
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> MessageInterface Name i -> f (MessageInterface Name i))
-> (FileBrowser Name -> f (FileBrowser Name))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> f (EditState Name))
-> MessageInterface Name i -> f (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> f (EditState Name))
 -> MessageInterface Name i -> f (MessageInterface Name i))
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> EditState Name -> f (EditState Name))
-> (FileBrowser Name -> f (FileBrowser Name))
-> MessageInterface Name i
-> f (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(FileBrowser Name -> f (FileBrowser Name))
-> EditState Name -> f (EditState Name)
forall n (f :: * -> *).
Functor f =>
(FileBrowser n -> f (FileBrowser n))
-> EditState n -> f (EditState n)
unsafeEsFileBrowser)
        EventM Name (FileBrowser Name) ()
forall n. EventM n (FileBrowser n) ()
FB.actionFileBrowserBeginSearch
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
FileBrowserSelectEnterEvent Text
"Select file or enter directory" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$ do
      Lens' ChatState (FileBrowser Name)
-> EventM Name (FileBrowser Name) () -> MH ()
forall b. Lens' ChatState b -> EventM Name b () -> MH ()
mhZoom' ((MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> f (MessageInterface Name i))
 -> ChatState -> f ChatState)
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> MessageInterface Name i -> f (MessageInterface Name i))
-> (FileBrowser Name -> f (FileBrowser Name))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> f (EditState Name))
-> MessageInterface Name i -> f (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> f (EditState Name))
 -> MessageInterface Name i -> f (MessageInterface Name i))
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> EditState Name -> f (EditState Name))
-> (FileBrowser Name -> f (FileBrowser Name))
-> MessageInterface Name i
-> f (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(FileBrowser Name -> f (FileBrowser Name))
-> EditState Name -> f (EditState Name)
forall n (f :: * -> *).
Functor f =>
(FileBrowser n -> f (FileBrowser n))
-> EditState n -> f (EditState n)
unsafeEsFileBrowser)
        EventM Name (FileBrowser Name) ()
forall n. EventM n (FileBrowser n) ()
FB.actionFileBrowserSelectEnter
      Lens' ChatState (MessageInterface Name i)
-> (FileBrowser Name -> MH ()) -> MH ()
forall i.
Lens' ChatState (MessageInterface Name i)
-> (FileBrowser Name -> MH ()) -> MH ()
withFileBrowser (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which (Lens' ChatState (MessageInterface Name i) -> [FileInfo] -> MH ()
forall i.
Lens' ChatState (MessageInterface Name i) -> [FileInfo] -> MH ()
tryAddAttachment (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which ([FileInfo] -> MH ())
-> (FileBrowser Name -> [FileInfo]) -> FileBrowser Name -> MH ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FileBrowser Name -> [FileInfo]
forall n. FileBrowser n -> [FileInfo]
FB.fileBrowserSelection)
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
FileBrowserSelectCurrentEvent Text
"Select file" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
      Lens' ChatState (FileBrowser Name)
-> EventM Name (FileBrowser Name) () -> MH ()
forall b. Lens' ChatState b -> EventM Name b () -> MH ()
mhZoom' ((MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> f (MessageInterface Name i))
 -> ChatState -> f ChatState)
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> MessageInterface Name i -> f (MessageInterface Name i))
-> (FileBrowser Name -> f (FileBrowser Name))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> f (EditState Name))
-> MessageInterface Name i -> f (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> f (EditState Name))
 -> MessageInterface Name i -> f (MessageInterface Name i))
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> EditState Name -> f (EditState Name))
-> (FileBrowser Name -> f (FileBrowser Name))
-> MessageInterface Name i
-> f (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(FileBrowser Name -> f (FileBrowser Name))
-> EditState Name -> f (EditState Name)
forall n (f :: * -> *).
Functor f =>
(FileBrowser n -> f (FileBrowser n))
-> EditState n -> f (EditState n)
unsafeEsFileBrowser)
        EventM Name (FileBrowser Name) ()
forall n. EventM n (FileBrowser n) ()
FB.actionFileBrowserSelectCurrent
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
FileBrowserListPageUpEvent Text
"Move cursor one page up" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
      Lens' ChatState (FileBrowser Name)
-> EventM Name (FileBrowser Name) () -> MH ()
forall b. Lens' ChatState b -> EventM Name b () -> MH ()
mhZoom' ((MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> f (MessageInterface Name i))
 -> ChatState -> f ChatState)
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> MessageInterface Name i -> f (MessageInterface Name i))
-> (FileBrowser Name -> f (FileBrowser Name))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> f (EditState Name))
-> MessageInterface Name i -> f (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> f (EditState Name))
 -> MessageInterface Name i -> f (MessageInterface Name i))
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> EditState Name -> f (EditState Name))
-> (FileBrowser Name -> f (FileBrowser Name))
-> MessageInterface Name i
-> f (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(FileBrowser Name -> f (FileBrowser Name))
-> EditState Name -> f (EditState Name)
forall n (f :: * -> *).
Functor f =>
(FileBrowser n -> f (FileBrowser n))
-> EditState n -> f (EditState n)
unsafeEsFileBrowser)
        EventM Name (FileBrowser Name) ()
forall n. Ord n => EventM n (FileBrowser n) ()
FB.actionFileBrowserListPageUp
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
FileBrowserListPageDownEvent Text
"Move cursor one page down" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
      Lens' ChatState (FileBrowser Name)
-> EventM Name (FileBrowser Name) () -> MH ()
forall b. Lens' ChatState b -> EventM Name b () -> MH ()
mhZoom' ((MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> f (MessageInterface Name i))
 -> ChatState -> f ChatState)
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> MessageInterface Name i -> f (MessageInterface Name i))
-> (FileBrowser Name -> f (FileBrowser Name))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> f (EditState Name))
-> MessageInterface Name i -> f (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> f (EditState Name))
 -> MessageInterface Name i -> f (MessageInterface Name i))
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> EditState Name -> f (EditState Name))
-> (FileBrowser Name -> f (FileBrowser Name))
-> MessageInterface Name i
-> f (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(FileBrowser Name -> f (FileBrowser Name))
-> EditState Name -> f (EditState Name)
forall n (f :: * -> *).
Functor f =>
(FileBrowser n -> f (FileBrowser n))
-> EditState n -> f (EditState n)
unsafeEsFileBrowser)
        EventM Name (FileBrowser Name) ()
forall n. Ord n => EventM n (FileBrowser n) ()
FB.actionFileBrowserListPageDown
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
FileBrowserListHalfPageUpEvent Text
"Move cursor one-half page up" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
      Lens' ChatState (FileBrowser Name)
-> EventM Name (FileBrowser Name) () -> MH ()
forall b. Lens' ChatState b -> EventM Name b () -> MH ()
mhZoom' ((MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> f (MessageInterface Name i))
 -> ChatState -> f ChatState)
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> MessageInterface Name i -> f (MessageInterface Name i))
-> (FileBrowser Name -> f (FileBrowser Name))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> f (EditState Name))
-> MessageInterface Name i -> f (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> f (EditState Name))
 -> MessageInterface Name i -> f (MessageInterface Name i))
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> EditState Name -> f (EditState Name))
-> (FileBrowser Name -> f (FileBrowser Name))
-> MessageInterface Name i
-> f (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(FileBrowser Name -> f (FileBrowser Name))
-> EditState Name -> f (EditState Name)
forall n (f :: * -> *).
Functor f =>
(FileBrowser n -> f (FileBrowser n))
-> EditState n -> f (EditState n)
unsafeEsFileBrowser)
        EventM Name (FileBrowser Name) ()
forall n. Ord n => EventM n (FileBrowser n) ()
FB.actionFileBrowserListHalfPageUp
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
FileBrowserListHalfPageDownEvent Text
"Move cursor one-half page down" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
      Lens' ChatState (FileBrowser Name)
-> EventM Name (FileBrowser Name) () -> MH ()
forall b. Lens' ChatState b -> EventM Name b () -> MH ()
mhZoom' ((MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> f (MessageInterface Name i))
 -> ChatState -> f ChatState)
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> MessageInterface Name i -> f (MessageInterface Name i))
-> (FileBrowser Name -> f (FileBrowser Name))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> f (EditState Name))
-> MessageInterface Name i -> f (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> f (EditState Name))
 -> MessageInterface Name i -> f (MessageInterface Name i))
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> EditState Name -> f (EditState Name))
-> (FileBrowser Name -> f (FileBrowser Name))
-> MessageInterface Name i
-> f (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(FileBrowser Name -> f (FileBrowser Name))
-> EditState Name -> f (EditState Name)
forall n (f :: * -> *).
Functor f =>
(FileBrowser n -> f (FileBrowser n))
-> EditState n -> f (EditState n)
unsafeEsFileBrowser)
        EventM Name (FileBrowser Name) ()
forall n. Ord n => EventM n (FileBrowser n) ()
FB.actionFileBrowserListHalfPageDown
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
FileBrowserListTopEvent Text
"Move cursor to top of list" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
      Lens' ChatState (FileBrowser Name)
-> EventM Name (FileBrowser Name) () -> MH ()
forall b. Lens' ChatState b -> EventM Name b () -> MH ()
mhZoom' ((MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> f (MessageInterface Name i))
 -> ChatState -> f ChatState)
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> MessageInterface Name i -> f (MessageInterface Name i))
-> (FileBrowser Name -> f (FileBrowser Name))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> f (EditState Name))
-> MessageInterface Name i -> f (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> f (EditState Name))
 -> MessageInterface Name i -> f (MessageInterface Name i))
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> EditState Name -> f (EditState Name))
-> (FileBrowser Name -> f (FileBrowser Name))
-> MessageInterface Name i
-> f (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(FileBrowser Name -> f (FileBrowser Name))
-> EditState Name -> f (EditState Name)
forall n (f :: * -> *).
Functor f =>
(FileBrowser n -> f (FileBrowser n))
-> EditState n -> f (EditState n)
unsafeEsFileBrowser)
        EventM Name (FileBrowser Name) ()
forall n. Ord n => EventM n (FileBrowser n) ()
FB.actionFileBrowserListTop
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
FileBrowserListBottomEvent Text
"Move cursor to bottom of list" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
      Lens' ChatState (FileBrowser Name)
-> EventM Name (FileBrowser Name) () -> MH ()
forall b. Lens' ChatState b -> EventM Name b () -> MH ()
mhZoom' ((MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> f (MessageInterface Name i))
 -> ChatState -> f ChatState)
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> MessageInterface Name i -> f (MessageInterface Name i))
-> (FileBrowser Name -> f (FileBrowser Name))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> f (EditState Name))
-> MessageInterface Name i -> f (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> f (EditState Name))
 -> MessageInterface Name i -> f (MessageInterface Name i))
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> EditState Name -> f (EditState Name))
-> (FileBrowser Name -> f (FileBrowser Name))
-> MessageInterface Name i
-> f (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(FileBrowser Name -> f (FileBrowser Name))
-> EditState Name -> f (EditState Name)
forall n (f :: * -> *).
Functor f =>
(FileBrowser n -> f (FileBrowser n))
-> EditState n -> f (EditState n)
unsafeEsFileBrowser)
        EventM Name (FileBrowser Name) ()
forall n. Ord n => EventM n (FileBrowser n) ()
FB.actionFileBrowserListBottom
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
FileBrowserListNextEvent Text
"Move cursor down" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
      Lens' ChatState (FileBrowser Name)
-> EventM Name (FileBrowser Name) () -> MH ()
forall b. Lens' ChatState b -> EventM Name b () -> MH ()
mhZoom' ((MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> f (MessageInterface Name i))
 -> ChatState -> f ChatState)
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> MessageInterface Name i -> f (MessageInterface Name i))
-> (FileBrowser Name -> f (FileBrowser Name))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> f (EditState Name))
-> MessageInterface Name i -> f (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> f (EditState Name))
 -> MessageInterface Name i -> f (MessageInterface Name i))
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> EditState Name -> f (EditState Name))
-> (FileBrowser Name -> f (FileBrowser Name))
-> MessageInterface Name i
-> f (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(FileBrowser Name -> f (FileBrowser Name))
-> EditState Name -> f (EditState Name)
forall n (f :: * -> *).
Functor f =>
(FileBrowser n -> f (FileBrowser n))
-> EditState n -> f (EditState n)
unsafeEsFileBrowser)
        EventM Name (FileBrowser Name) ()
forall n. Ord n => EventM n (FileBrowser n) ()
FB.actionFileBrowserListNext
    , KeyEvent -> Text -> MH () -> KeyEventHandler KeyEvent MH
forall k (m :: * -> *). k -> Text -> m () -> KeyEventHandler k m
onEvent KeyEvent
FileBrowserListPrevEvent Text
"Move cursor up" (MH () -> KeyEventHandler KeyEvent MH)
-> MH () -> KeyEventHandler KeyEvent MH
forall a b. (a -> b) -> a -> b
$
      Lens' ChatState (FileBrowser Name)
-> EventM Name (FileBrowser Name) () -> MH ()
forall b. Lens' ChatState b -> EventM Name b () -> MH ()
mhZoom' ((MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> f (MessageInterface Name i))
 -> ChatState -> f ChatState)
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> MessageInterface Name i -> f (MessageInterface Name i))
-> (FileBrowser Name -> f (FileBrowser Name))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> f (EditState Name))
-> MessageInterface Name i -> f (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> f (EditState Name))
 -> MessageInterface Name i -> f (MessageInterface Name i))
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> EditState Name -> f (EditState Name))
-> (FileBrowser Name -> f (FileBrowser Name))
-> MessageInterface Name i
-> f (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(FileBrowser Name -> f (FileBrowser Name))
-> EditState Name -> f (EditState Name)
forall n (f :: * -> *).
Functor f =>
(FileBrowser n -> f (FileBrowser n))
-> EditState n -> f (EditState n)
unsafeEsFileBrowser)
        EventM Name (FileBrowser Name) ()
forall n. Ord n => EventM n (FileBrowser n) ()
FB.actionFileBrowserListPrev
    ]

withFileBrowser :: Lens' ChatState (MessageInterface Name i)
                -> ((FB.FileBrowser Name) -> MH ())
                -> MH ()
withFileBrowser :: forall i.
Lens' ChatState (MessageInterface Name i)
-> (FileBrowser Name -> MH ()) -> MH ()
withFileBrowser Lens' ChatState (MessageInterface Name i)
which FileBrowser Name -> MH ()
f = do
    Getting
  (Maybe (FileBrowser Name)) ChatState (Maybe (FileBrowser Name))
-> MH (Maybe (FileBrowser Name))
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((MessageInterface Name i
 -> Const (Maybe (FileBrowser Name)) (MessageInterface Name i))
-> ChatState -> Const (Maybe (FileBrowser Name)) ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i
  -> Const (Maybe (FileBrowser Name)) (MessageInterface Name i))
 -> ChatState -> Const (Maybe (FileBrowser Name)) ChatState)
-> ((Maybe (FileBrowser Name)
     -> Const (Maybe (FileBrowser Name)) (Maybe (FileBrowser Name)))
    -> MessageInterface Name i
    -> Const (Maybe (FileBrowser Name)) (MessageInterface Name i))
-> Getting
     (Maybe (FileBrowser Name)) ChatState (Maybe (FileBrowser Name))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name
 -> Const (Maybe (FileBrowser Name)) (EditState Name))
-> MessageInterface Name i
-> Const (Maybe (FileBrowser Name)) (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name
  -> Const (Maybe (FileBrowser Name)) (EditState Name))
 -> MessageInterface Name i
 -> Const (Maybe (FileBrowser Name)) (MessageInterface Name i))
-> ((Maybe (FileBrowser Name)
     -> Const (Maybe (FileBrowser Name)) (Maybe (FileBrowser Name)))
    -> EditState Name
    -> Const (Maybe (FileBrowser Name)) (EditState Name))
-> (Maybe (FileBrowser Name)
    -> Const (Maybe (FileBrowser Name)) (Maybe (FileBrowser Name)))
-> MessageInterface Name i
-> Const (Maybe (FileBrowser Name)) (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe (FileBrowser Name)
 -> Const (Maybe (FileBrowser Name)) (Maybe (FileBrowser Name)))
-> EditState Name
-> Const (Maybe (FileBrowser Name)) (EditState Name)
forall n (f :: * -> *).
Functor f =>
(Maybe (FileBrowser n) -> f (Maybe (FileBrowser n)))
-> EditState n -> f (EditState n)
esFileBrowser) MH (Maybe (FileBrowser Name))
-> (Maybe (FileBrowser Name) -> MH ()) -> MH ()
forall a b. MH a -> (a -> MH b) -> MH b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
        Maybe (FileBrowser Name)
Nothing -> do
            -- The widget has not been created yet.  This should
            -- normally not occur, because the ManageAttachments
            -- events should not fire when there is no FileBrowser
            -- Widget active to cause Brick to generate these events.
            -- This could therefore be implemented as an `error "BUG:
            -- ..."` handler, but the more benign approach is to
            -- simply create an available FileBrowser at this stage.
            ChannelId
cId <- Getting ChannelId ChatState ChannelId -> MH ChannelId
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((MessageInterface Name i
 -> Const ChannelId (MessageInterface Name i))
-> ChatState -> Const ChannelId ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i
  -> Const ChannelId (MessageInterface Name i))
 -> ChatState -> Const ChannelId ChatState)
-> ((ChannelId -> Const ChannelId ChannelId)
    -> MessageInterface Name i
    -> Const ChannelId (MessageInterface Name i))
-> Getting ChannelId ChatState ChannelId
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> Const ChannelId (EditState Name))
-> MessageInterface Name i
-> Const ChannelId (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> Const ChannelId (EditState Name))
 -> MessageInterface Name i
 -> Const ChannelId (MessageInterface Name i))
-> ((ChannelId -> Const ChannelId ChannelId)
    -> EditState Name -> Const ChannelId (EditState Name))
-> (ChannelId -> Const ChannelId ChannelId)
-> MessageInterface Name i
-> Const ChannelId (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(ChannelId -> Const ChannelId ChannelId)
-> EditState Name -> Const ChannelId (EditState Name)
forall n (f :: * -> *).
Functor f =>
(ChannelId -> f ChannelId) -> EditState n -> f (EditState n)
esChannelId)
            FileBrowser Name
new_b <- IO (FileBrowser Name) -> MH (FileBrowser Name)
forall a. IO a -> MH a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (FileBrowser Name) -> MH (FileBrowser Name))
-> IO (FileBrowser Name) -> MH (FileBrowser Name)
forall a b. (a -> b) -> a -> b
$ (FileInfo -> Bool)
-> Name -> Maybe FilePath -> IO (FileBrowser Name)
forall n.
(FileInfo -> Bool) -> n -> Maybe FilePath -> IO (FileBrowser n)
FB.newFileBrowser FileInfo -> Bool
FB.selectNonDirectories (ChannelId -> Name
AttachmentFileBrowser ChannelId
cId) Maybe FilePath
forall a. Maybe a
Nothing
            (MessageInterface Name i -> Identity (MessageInterface Name i))
-> ChatState -> Identity ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> Identity (MessageInterface Name i))
 -> ChatState -> Identity ChatState)
-> ((Maybe (FileBrowser Name)
     -> Identity (Maybe (FileBrowser Name)))
    -> MessageInterface Name i -> Identity (MessageInterface Name i))
-> (Maybe (FileBrowser Name)
    -> Identity (Maybe (FileBrowser Name)))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> Identity (EditState Name))
-> MessageInterface Name i -> Identity (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> Identity (EditState Name))
 -> MessageInterface Name i -> Identity (MessageInterface Name i))
-> ((Maybe (FileBrowser Name)
     -> Identity (Maybe (FileBrowser Name)))
    -> EditState Name -> Identity (EditState Name))
-> (Maybe (FileBrowser Name)
    -> Identity (Maybe (FileBrowser Name)))
-> MessageInterface Name i
-> Identity (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe (FileBrowser Name) -> Identity (Maybe (FileBrowser Name)))
-> EditState Name -> Identity (EditState Name)
forall n (f :: * -> *).
Functor f =>
(Maybe (FileBrowser n) -> f (Maybe (FileBrowser n)))
-> EditState n -> f (EditState n)
esFileBrowser ((Maybe (FileBrowser Name) -> Identity (Maybe (FileBrowser Name)))
 -> ChatState -> Identity ChatState)
-> FileBrowser Name -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a (Maybe b) -> b -> m ()
?= FileBrowser Name
new_b
            FileBrowser Name -> MH ()
f FileBrowser Name
new_b
        Just FileBrowser Name
b -> FileBrowser Name -> MH ()
f FileBrowser Name
b

openSelectedAttachment :: Lens' ChatState (MessageInterface Name i) -> MH ()
openSelectedAttachment :: forall i. Lens' ChatState (MessageInterface Name i) -> MH ()
openSelectedAttachment Lens' ChatState (MessageInterface Name i)
which = do
    Maybe (Int, AttachmentData)
cur <- Getting
  (Maybe (Int, AttachmentData))
  ChatState
  (Maybe (Int, AttachmentData))
-> MH (Maybe (Int, AttachmentData))
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((MessageInterface Name i
 -> Const (Maybe (Int, AttachmentData)) (MessageInterface Name i))
-> ChatState -> Const (Maybe (Int, AttachmentData)) ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i
  -> Const (Maybe (Int, AttachmentData)) (MessageInterface Name i))
 -> ChatState -> Const (Maybe (Int, AttachmentData)) ChatState)
-> ((Maybe (Int, AttachmentData)
     -> Const
          (Maybe (Int, AttachmentData)) (Maybe (Int, AttachmentData)))
    -> MessageInterface Name i
    -> Const (Maybe (Int, AttachmentData)) (MessageInterface Name i))
-> Getting
     (Maybe (Int, AttachmentData))
     ChatState
     (Maybe (Int, AttachmentData))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name
 -> Const (Maybe (Int, AttachmentData)) (EditState Name))
-> MessageInterface Name i
-> Const (Maybe (Int, AttachmentData)) (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name
  -> Const (Maybe (Int, AttachmentData)) (EditState Name))
 -> MessageInterface Name i
 -> Const (Maybe (Int, AttachmentData)) (MessageInterface Name i))
-> ((Maybe (Int, AttachmentData)
     -> Const
          (Maybe (Int, AttachmentData)) (Maybe (Int, AttachmentData)))
    -> EditState Name
    -> Const (Maybe (Int, AttachmentData)) (EditState Name))
-> (Maybe (Int, AttachmentData)
    -> Const
         (Maybe (Int, AttachmentData)) (Maybe (Int, AttachmentData)))
-> MessageInterface Name i
-> Const (Maybe (Int, AttachmentData)) (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(GenericList Name Vector AttachmentData
 -> Const
      (Maybe (Int, AttachmentData))
      (GenericList Name Vector AttachmentData))
-> EditState Name
-> Const (Maybe (Int, AttachmentData)) (EditState Name)
forall n (f :: * -> *).
Functor f =>
(List n AttachmentData -> f (List n AttachmentData))
-> EditState n -> f (EditState n)
esAttachmentList((GenericList Name Vector AttachmentData
  -> Const
       (Maybe (Int, AttachmentData))
       (GenericList Name Vector AttachmentData))
 -> EditState Name
 -> Const (Maybe (Int, AttachmentData)) (EditState Name))
-> ((Maybe (Int, AttachmentData)
     -> Const
          (Maybe (Int, AttachmentData)) (Maybe (Int, AttachmentData)))
    -> GenericList Name Vector AttachmentData
    -> Const
         (Maybe (Int, AttachmentData))
         (GenericList Name Vector AttachmentData))
-> (Maybe (Int, AttachmentData)
    -> Const
         (Maybe (Int, AttachmentData)) (Maybe (Int, AttachmentData)))
-> EditState Name
-> Const (Maybe (Int, AttachmentData)) (EditState Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(GenericList Name Vector AttachmentData
 -> Maybe (Int, AttachmentData))
-> SimpleGetter
     (GenericList Name Vector AttachmentData)
     (Maybe (Int, AttachmentData))
forall s a. (s -> a) -> SimpleGetter s a
to GenericList Name Vector AttachmentData
-> Maybe (Int, AttachmentData)
forall (t :: * -> *) e n.
(Splittable t, Traversable t, Semigroup (t e)) =>
GenericList n t e -> Maybe (Int, e)
L.listSelectedElement)
    case Maybe (Int, AttachmentData)
cur of
        Maybe (Int, AttachmentData)
Nothing -> () -> MH ()
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
        Just (Int
_, AttachmentData
entry) -> MH () -> MH ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (MH () -> MH ()) -> MH () -> MH ()
forall a b. (a -> b) -> a -> b
$ FilePath -> MH ()
openFilePath (FileInfo -> FilePath
FB.fileInfoFilePath (FileInfo -> FilePath) -> FileInfo -> FilePath
forall a b. (a -> b) -> a -> b
$
                                                AttachmentData -> FileInfo
attachmentDataFileInfo AttachmentData
entry)

openSelectedBrowserEntry :: Lens' ChatState (MessageInterface Name i) -> MH ()
openSelectedBrowserEntry :: forall i. Lens' ChatState (MessageInterface Name i) -> MH ()
openSelectedBrowserEntry Lens' ChatState (MessageInterface Name i)
which = Lens' ChatState (MessageInterface Name i)
-> (FileBrowser Name -> MH ()) -> MH ()
forall i.
Lens' ChatState (MessageInterface Name i)
-> (FileBrowser Name -> MH ()) -> MH ()
withFileBrowser (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which ((FileBrowser Name -> MH ()) -> MH ())
-> (FileBrowser Name -> MH ()) -> MH ()
forall a b. (a -> b) -> a -> b
$ \FileBrowser Name
b ->
    case FileBrowser Name -> Maybe FileInfo
forall n. FileBrowser n -> Maybe FileInfo
FB.fileBrowserCursor FileBrowser Name
b of
        Maybe FileInfo
Nothing -> () -> MH ()
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
        Just FileInfo
entry -> MH () -> MH ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (MH () -> MH ()) -> MH () -> MH ()
forall a b. (a -> b) -> a -> b
$ FilePath -> MH ()
openFilePath (FileInfo -> FilePath
FB.fileInfoFilePath FileInfo
entry)

onEventBrowseFile :: Lens' ChatState (MessageInterface Name i) -> V.Event -> MH Bool
onEventBrowseFile :: forall i.
Lens' ChatState (MessageInterface Name i) -> Event -> MH Bool
onEventBrowseFile Lens' ChatState (MessageInterface Name i)
which Event
e = do
    Lens' ChatState (MessageInterface Name i)
-> (FileBrowser Name -> MH ()) -> MH ()
forall i.
Lens' ChatState (MessageInterface Name i)
-> (FileBrowser Name -> MH ()) -> MH ()
withFileBrowser (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which ((FileBrowser Name -> MH ()) -> MH ())
-> (FileBrowser Name -> MH ()) -> MH ()
forall a b. (a -> b) -> a -> b
$ \FileBrowser Name
b -> do
        case FileBrowser Name -> Bool
forall n. FileBrowser n -> Bool
FB.fileBrowserIsSearching FileBrowser Name
b of
            Bool
False ->
                MH Bool -> MH ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (MH Bool -> MH ()) -> MH Bool -> MH ()
forall a b. (a -> b) -> a -> b
$ [Event -> MH Bool] -> Event -> MH Bool
handleEventWith [ (KeyConfig KeyEvent -> KeyDispatcher KeyEvent MH)
-> Event -> MH Bool
mhHandleKeyboardEvent (Lens' ChatState (MessageInterface Name i)
-> KeyConfig KeyEvent -> KeyDispatcher KeyEvent MH
forall i.
Lens' ChatState (MessageInterface Name i)
-> KeyConfig KeyEvent -> KeyDispatcher KeyEvent MH
attachmentBrowseKeybindings (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which)
                                       , \Event
_ -> Lens' ChatState (MessageInterface Name i) -> Event -> MH ()
forall i.
Lens' ChatState (MessageInterface Name i) -> Event -> MH ()
handleFileBrowserEvent (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which Event
e MH () -> MH Bool -> MH Bool
forall a b. MH a -> MH b -> MH b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Bool -> MH Bool
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
                                       ] Event
e
            Bool
True ->
                Lens' ChatState (MessageInterface Name i) -> Event -> MH ()
forall i.
Lens' ChatState (MessageInterface Name i) -> Event -> MH ()
handleFileBrowserEvent (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which Event
e

    -- n.b. the FileBrowser may have been updated above, so re-acquire it
    Lens' ChatState (MessageInterface Name i)
-> (FileBrowser Name -> MH ()) -> MH ()
forall i.
Lens' ChatState (MessageInterface Name i)
-> (FileBrowser Name -> MH ()) -> MH ()
withFileBrowser (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which ((FileBrowser Name -> MH ()) -> MH ())
-> (FileBrowser Name -> MH ()) -> MH ()
forall a b. (a -> b) -> a -> b
$ \FileBrowser Name
b -> do
        case FileBrowser Name -> Maybe IOException
forall n. FileBrowser n -> Maybe IOException
FB.fileBrowserException FileBrowser Name
b of
            Maybe IOException
Nothing -> () -> MH ()
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
            Just IOException
ex -> do
                LogCategory -> Text -> MH ()
mhLog LogCategory
LogError (Text -> MH ()) -> Text -> MH ()
forall a b. (a -> b) -> a -> b
$ FilePath -> Text
T.pack (FilePath -> Text) -> FilePath -> Text
forall a b. (a -> b) -> a -> b
$ FilePath
"FileBrowser exception: " FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> IOException -> FilePath
forall a. Show a => a -> FilePath
show IOException
ex

    Bool -> MH Bool
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True

cancelAttachmentBrowse :: Lens' ChatState (MessageInterface Name i) -> MH ()
cancelAttachmentBrowse :: forall i. Lens' ChatState (MessageInterface Name i) -> MH ()
cancelAttachmentBrowse Lens' ChatState (MessageInterface Name i)
which = do
    Vector AttachmentData
es <- Getting (Vector AttachmentData) ChatState (Vector AttachmentData)
-> MH (Vector AttachmentData)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((MessageInterface Name i
 -> Const (Vector AttachmentData) (MessageInterface Name i))
-> ChatState -> Const (Vector AttachmentData) ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i
  -> Const (Vector AttachmentData) (MessageInterface Name i))
 -> ChatState -> Const (Vector AttachmentData) ChatState)
-> ((Vector AttachmentData
     -> Const (Vector AttachmentData) (Vector AttachmentData))
    -> MessageInterface Name i
    -> Const (Vector AttachmentData) (MessageInterface Name i))
-> Getting
     (Vector AttachmentData) ChatState (Vector AttachmentData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> Const (Vector AttachmentData) (EditState Name))
-> MessageInterface Name i
-> Const (Vector AttachmentData) (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> Const (Vector AttachmentData) (EditState Name))
 -> MessageInterface Name i
 -> Const (Vector AttachmentData) (MessageInterface Name i))
-> ((Vector AttachmentData
     -> Const (Vector AttachmentData) (Vector AttachmentData))
    -> EditState Name
    -> Const (Vector AttachmentData) (EditState Name))
-> (Vector AttachmentData
    -> Const (Vector AttachmentData) (Vector AttachmentData))
-> MessageInterface Name i
-> Const (Vector AttachmentData) (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(GenericList Name Vector AttachmentData
 -> Const
      (Vector AttachmentData) (GenericList Name Vector AttachmentData))
-> EditState Name -> Const (Vector AttachmentData) (EditState Name)
forall n (f :: * -> *).
Functor f =>
(List n AttachmentData -> f (List n AttachmentData))
-> EditState n -> f (EditState n)
esAttachmentList((GenericList Name Vector AttachmentData
  -> Const
       (Vector AttachmentData) (GenericList Name Vector AttachmentData))
 -> EditState Name
 -> Const (Vector AttachmentData) (EditState Name))
-> ((Vector AttachmentData
     -> Const (Vector AttachmentData) (Vector AttachmentData))
    -> GenericList Name Vector AttachmentData
    -> Const
         (Vector AttachmentData) (GenericList Name Vector AttachmentData))
-> (Vector AttachmentData
    -> Const (Vector AttachmentData) (Vector AttachmentData))
-> EditState Name
-> Const (Vector AttachmentData) (EditState Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Vector AttachmentData
 -> Const (Vector AttachmentData) (Vector AttachmentData))
-> GenericList Name Vector AttachmentData
-> Const
     (Vector AttachmentData) (GenericList Name Vector AttachmentData)
forall n (t1 :: * -> *) e1 (t2 :: * -> *) e2 (f :: * -> *).
Functor f =>
(t1 e1 -> f (t2 e2))
-> GenericList n t1 e1 -> f (GenericList n t2 e2)
L.listElementsL)
    (MessageInterface Name i -> Identity (MessageInterface Name i))
-> ChatState -> Identity ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> Identity (MessageInterface Name i))
 -> ChatState -> Identity ChatState)
-> ((MessageInterfaceMode -> Identity MessageInterfaceMode)
    -> MessageInterface Name i -> Identity (MessageInterface Name i))
-> (MessageInterfaceMode -> Identity MessageInterfaceMode)
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(MessageInterfaceMode -> Identity MessageInterfaceMode)
-> MessageInterface Name i -> Identity (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(MessageInterfaceMode -> f MessageInterfaceMode)
-> MessageInterface n i -> f (MessageInterface n i)
miMode ((MessageInterfaceMode -> Identity MessageInterfaceMode)
 -> ChatState -> Identity ChatState)
-> MessageInterfaceMode -> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= case Vector AttachmentData -> Int
forall a. Vector a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Vector AttachmentData
es of
        Int
0 -> MessageInterfaceMode
Compose
        Int
_ -> MessageInterfaceMode
ManageAttachments

handleFileBrowserEvent :: Lens' ChatState (MessageInterface Name i) -> V.Event -> MH ()
handleFileBrowserEvent :: forall i.
Lens' ChatState (MessageInterface Name i) -> Event -> MH ()
handleFileBrowserEvent Lens' ChatState (MessageInterface Name i)
which Event
e = do
    Lens' ChatState (FileBrowser Name)
-> (Event -> EventM Name (FileBrowser Name) ()) -> Event -> MH ()
forall b e.
Lens' ChatState b -> (e -> EventM Name b ()) -> e -> MH ()
mhZoom ((MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> f (MessageInterface Name i))
 -> ChatState -> f ChatState)
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> MessageInterface Name i -> f (MessageInterface Name i))
-> (FileBrowser Name -> f (FileBrowser Name))
-> ChatState
-> f ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> f (EditState Name))
-> MessageInterface Name i -> f (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> f (EditState Name))
 -> MessageInterface Name i -> f (MessageInterface Name i))
-> ((FileBrowser Name -> f (FileBrowser Name))
    -> EditState Name -> f (EditState Name))
-> (FileBrowser Name -> f (FileBrowser Name))
-> MessageInterface Name i
-> f (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(FileBrowser Name -> f (FileBrowser Name))
-> EditState Name -> f (EditState Name)
forall n (f :: * -> *).
Functor f =>
(FileBrowser n -> f (FileBrowser n))
-> EditState n -> f (EditState n)
unsafeEsFileBrowser) Event -> EventM Name (FileBrowser Name) ()
forall n. Ord n => Event -> EventM n (FileBrowser n) ()
FB.handleFileBrowserEvent Event
e
    -- TODO: Check file browser exception state
    Lens' ChatState (MessageInterface Name i)
-> (FileBrowser Name -> MH ()) -> MH ()
forall i.
Lens' ChatState (MessageInterface Name i)
-> (FileBrowser Name -> MH ()) -> MH ()
withFileBrowser (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which ((FileBrowser Name -> MH ()) -> MH ())
-> (FileBrowser Name -> MH ()) -> MH ()
forall a b. (a -> b) -> a -> b
$ \FileBrowser Name
b ->
        Lens' ChatState (MessageInterface Name i) -> [FileInfo] -> MH ()
forall i.
Lens' ChatState (MessageInterface Name i) -> [FileInfo] -> MH ()
tryAddAttachment (MessageInterface Name i -> f (MessageInterface Name i))
-> ChatState -> f ChatState
Lens' ChatState (MessageInterface Name i)
which (FileBrowser Name -> [FileInfo]
forall n. FileBrowser n -> [FileInfo]
FB.fileBrowserSelection FileBrowser Name
b)

deleteSelectedAttachment :: Lens' ChatState (MessageInterface Name i) -> MH ()
deleteSelectedAttachment :: forall i. Lens' ChatState (MessageInterface Name i) -> MH ()
deleteSelectedAttachment Lens' ChatState (MessageInterface Name i)
which = do
    Vector AttachmentData
es <- Getting (Vector AttachmentData) ChatState (Vector AttachmentData)
-> MH (Vector AttachmentData)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((MessageInterface Name i
 -> Const (Vector AttachmentData) (MessageInterface Name i))
-> ChatState -> Const (Vector AttachmentData) ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i
  -> Const (Vector AttachmentData) (MessageInterface Name i))
 -> ChatState -> Const (Vector AttachmentData) ChatState)
-> ((Vector AttachmentData
     -> Const (Vector AttachmentData) (Vector AttachmentData))
    -> MessageInterface Name i
    -> Const (Vector AttachmentData) (MessageInterface Name i))
-> Getting
     (Vector AttachmentData) ChatState (Vector AttachmentData)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> Const (Vector AttachmentData) (EditState Name))
-> MessageInterface Name i
-> Const (Vector AttachmentData) (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> Const (Vector AttachmentData) (EditState Name))
 -> MessageInterface Name i
 -> Const (Vector AttachmentData) (MessageInterface Name i))
-> ((Vector AttachmentData
     -> Const (Vector AttachmentData) (Vector AttachmentData))
    -> EditState Name
    -> Const (Vector AttachmentData) (EditState Name))
-> (Vector AttachmentData
    -> Const (Vector AttachmentData) (Vector AttachmentData))
-> MessageInterface Name i
-> Const (Vector AttachmentData) (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(GenericList Name Vector AttachmentData
 -> Const
      (Vector AttachmentData) (GenericList Name Vector AttachmentData))
-> EditState Name -> Const (Vector AttachmentData) (EditState Name)
forall n (f :: * -> *).
Functor f =>
(List n AttachmentData -> f (List n AttachmentData))
-> EditState n -> f (EditState n)
esAttachmentList((GenericList Name Vector AttachmentData
  -> Const
       (Vector AttachmentData) (GenericList Name Vector AttachmentData))
 -> EditState Name
 -> Const (Vector AttachmentData) (EditState Name))
-> ((Vector AttachmentData
     -> Const (Vector AttachmentData) (Vector AttachmentData))
    -> GenericList Name Vector AttachmentData
    -> Const
         (Vector AttachmentData) (GenericList Name Vector AttachmentData))
-> (Vector AttachmentData
    -> Const (Vector AttachmentData) (Vector AttachmentData))
-> EditState Name
-> Const (Vector AttachmentData) (EditState Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Vector AttachmentData
 -> Const (Vector AttachmentData) (Vector AttachmentData))
-> GenericList Name Vector AttachmentData
-> Const
     (Vector AttachmentData) (GenericList Name Vector AttachmentData)
forall n (t1 :: * -> *) e1 (t2 :: * -> *) e2 (f :: * -> *).
Functor f =>
(t1 e1 -> f (t2 e2))
-> GenericList n t1 e1 -> f (GenericList n t2 e2)
L.listElementsL)
    Maybe (Int, AttachmentData)
mSel <- Getting
  (Maybe (Int, AttachmentData))
  ChatState
  (Maybe (Int, AttachmentData))
-> MH (Maybe (Int, AttachmentData))
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((MessageInterface Name i
 -> Const (Maybe (Int, AttachmentData)) (MessageInterface Name i))
-> ChatState -> Const (Maybe (Int, AttachmentData)) ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i
  -> Const (Maybe (Int, AttachmentData)) (MessageInterface Name i))
 -> ChatState -> Const (Maybe (Int, AttachmentData)) ChatState)
-> ((Maybe (Int, AttachmentData)
     -> Const
          (Maybe (Int, AttachmentData)) (Maybe (Int, AttachmentData)))
    -> MessageInterface Name i
    -> Const (Maybe (Int, AttachmentData)) (MessageInterface Name i))
-> Getting
     (Maybe (Int, AttachmentData))
     ChatState
     (Maybe (Int, AttachmentData))
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name
 -> Const (Maybe (Int, AttachmentData)) (EditState Name))
-> MessageInterface Name i
-> Const (Maybe (Int, AttachmentData)) (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name
  -> Const (Maybe (Int, AttachmentData)) (EditState Name))
 -> MessageInterface Name i
 -> Const (Maybe (Int, AttachmentData)) (MessageInterface Name i))
-> ((Maybe (Int, AttachmentData)
     -> Const
          (Maybe (Int, AttachmentData)) (Maybe (Int, AttachmentData)))
    -> EditState Name
    -> Const (Maybe (Int, AttachmentData)) (EditState Name))
-> (Maybe (Int, AttachmentData)
    -> Const
         (Maybe (Int, AttachmentData)) (Maybe (Int, AttachmentData)))
-> MessageInterface Name i
-> Const (Maybe (Int, AttachmentData)) (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(GenericList Name Vector AttachmentData
 -> Const
      (Maybe (Int, AttachmentData))
      (GenericList Name Vector AttachmentData))
-> EditState Name
-> Const (Maybe (Int, AttachmentData)) (EditState Name)
forall n (f :: * -> *).
Functor f =>
(List n AttachmentData -> f (List n AttachmentData))
-> EditState n -> f (EditState n)
esAttachmentList((GenericList Name Vector AttachmentData
  -> Const
       (Maybe (Int, AttachmentData))
       (GenericList Name Vector AttachmentData))
 -> EditState Name
 -> Const (Maybe (Int, AttachmentData)) (EditState Name))
-> ((Maybe (Int, AttachmentData)
     -> Const
          (Maybe (Int, AttachmentData)) (Maybe (Int, AttachmentData)))
    -> GenericList Name Vector AttachmentData
    -> Const
         (Maybe (Int, AttachmentData))
         (GenericList Name Vector AttachmentData))
-> (Maybe (Int, AttachmentData)
    -> Const
         (Maybe (Int, AttachmentData)) (Maybe (Int, AttachmentData)))
-> EditState Name
-> Const (Maybe (Int, AttachmentData)) (EditState Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(GenericList Name Vector AttachmentData
 -> Maybe (Int, AttachmentData))
-> SimpleGetter
     (GenericList Name Vector AttachmentData)
     (Maybe (Int, AttachmentData))
forall s a. (s -> a) -> SimpleGetter s a
to GenericList Name Vector AttachmentData
-> Maybe (Int, AttachmentData)
forall (t :: * -> *) e n.
(Splittable t, Traversable t, Semigroup (t e)) =>
GenericList n t e -> Maybe (Int, e)
L.listSelectedElement)
    case Maybe (Int, AttachmentData)
mSel of
        Maybe (Int, AttachmentData)
Nothing ->
            () -> MH ()
forall a. a -> MH a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
        Just (Int
pos, AttachmentData
_) -> do
            Maybe Int
oldIdx <- Getting (Maybe Int) ChatState (Maybe Int) -> MH (Maybe Int)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use ((MessageInterface Name i
 -> Const (Maybe Int) (MessageInterface Name i))
-> ChatState -> Const (Maybe Int) ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i
  -> Const (Maybe Int) (MessageInterface Name i))
 -> ChatState -> Const (Maybe Int) ChatState)
-> ((Maybe Int -> Const (Maybe Int) (Maybe Int))
    -> MessageInterface Name i
    -> Const (Maybe Int) (MessageInterface Name i))
-> Getting (Maybe Int) ChatState (Maybe Int)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> Const (Maybe Int) (EditState Name))
-> MessageInterface Name i
-> Const (Maybe Int) (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> Const (Maybe Int) (EditState Name))
 -> MessageInterface Name i
 -> Const (Maybe Int) (MessageInterface Name i))
-> ((Maybe Int -> Const (Maybe Int) (Maybe Int))
    -> EditState Name -> Const (Maybe Int) (EditState Name))
-> (Maybe Int -> Const (Maybe Int) (Maybe Int))
-> MessageInterface Name i
-> Const (Maybe Int) (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(GenericList Name Vector AttachmentData
 -> Const (Maybe Int) (GenericList Name Vector AttachmentData))
-> EditState Name -> Const (Maybe Int) (EditState Name)
forall n (f :: * -> *).
Functor f =>
(List n AttachmentData -> f (List n AttachmentData))
-> EditState n -> f (EditState n)
esAttachmentList((GenericList Name Vector AttachmentData
  -> Const (Maybe Int) (GenericList Name Vector AttachmentData))
 -> EditState Name -> Const (Maybe Int) (EditState Name))
-> ((Maybe Int -> Const (Maybe Int) (Maybe Int))
    -> GenericList Name Vector AttachmentData
    -> Const (Maybe Int) (GenericList Name Vector AttachmentData))
-> (Maybe Int -> Const (Maybe Int) (Maybe Int))
-> EditState Name
-> Const (Maybe Int) (EditState Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(Maybe Int -> Const (Maybe Int) (Maybe Int))
-> GenericList Name Vector AttachmentData
-> Const (Maybe Int) (GenericList Name Vector AttachmentData)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
L.listSelectedL)
            let idx :: Maybe Int
idx = if Vector AttachmentData -> Int
forall a. Vector a -> Int
Vector.length Vector AttachmentData
es Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Int
1
                      then Maybe Int
forall a. Maybe a
Nothing
                      else case Maybe Int
oldIdx of
                          Maybe Int
Nothing -> Int -> Maybe Int
forall a. a -> Maybe a
Just Int
0
                          Just Int
old -> if Int
pos Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Int
old
                                      then Int -> Maybe Int
forall a. a -> Maybe a
Just (Int -> Maybe Int) -> Int -> Maybe Int
forall a b. (a -> b) -> a -> b
$ Int
pos Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1
                                      else Int -> Maybe Int
forall a. a -> Maybe a
Just Int
pos
            (MessageInterface Name i -> Identity (MessageInterface Name i))
-> ChatState -> Identity ChatState
Lens' ChatState (MessageInterface Name i)
which((MessageInterface Name i -> Identity (MessageInterface Name i))
 -> ChatState -> Identity ChatState)
-> ((GenericList Name Vector AttachmentData
     -> Identity (GenericList Name Vector AttachmentData))
    -> MessageInterface Name i -> Identity (MessageInterface Name i))
-> (GenericList Name Vector AttachmentData
    -> Identity (GenericList Name Vector AttachmentData))
-> ChatState
-> Identity ChatState
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(EditState Name -> Identity (EditState Name))
-> MessageInterface Name i -> Identity (MessageInterface Name i)
forall n i (f :: * -> *).
Functor f =>
(EditState n -> f (EditState n))
-> MessageInterface n i -> f (MessageInterface n i)
miEditor((EditState Name -> Identity (EditState Name))
 -> MessageInterface Name i -> Identity (MessageInterface Name i))
-> ((GenericList Name Vector AttachmentData
     -> Identity (GenericList Name Vector AttachmentData))
    -> EditState Name -> Identity (EditState Name))
-> (GenericList Name Vector AttachmentData
    -> Identity (GenericList Name Vector AttachmentData))
-> MessageInterface Name i
-> Identity (MessageInterface Name i)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.(GenericList Name Vector AttachmentData
 -> Identity (GenericList Name Vector AttachmentData))
-> EditState Name -> Identity (EditState Name)
forall n (f :: * -> *).
Functor f =>
(List n AttachmentData -> f (List n AttachmentData))
-> EditState n -> f (EditState n)
esAttachmentList ((GenericList Name Vector AttachmentData
  -> Identity (GenericList Name Vector AttachmentData))
 -> ChatState -> Identity ChatState)
-> (GenericList Name Vector AttachmentData
    -> GenericList Name Vector AttachmentData)
-> MH ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= Vector AttachmentData
-> Maybe Int
-> GenericList Name Vector AttachmentData
-> GenericList Name Vector AttachmentData
forall (t :: * -> *) e n.
(Foldable t, Splittable t) =>
t e -> Maybe Int -> GenericList n t e -> GenericList n t e
L.listReplace (Int -> Vector AttachmentData -> Vector AttachmentData
forall a. Int -> Vector a -> Vector a
deleteAt Int
pos Vector AttachmentData
es) Maybe Int
idx

deleteAt :: Int -> Vector.Vector a -> Vector.Vector a
deleteAt :: forall a. Int -> Vector a -> Vector a
deleteAt Int
p Vector a
as | Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
0 Bool -> Bool -> Bool
|| Int
p Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Vector a -> Int
forall a. Vector a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length Vector a
as = Vector a
as
              | Bool
otherwise = Int -> Vector a -> Vector a
forall a. Int -> Vector a -> Vector a
Vector.take Int
p Vector a
as Vector a -> Vector a -> Vector a
forall a. Semigroup a => a -> a -> a
<> Int -> Vector a -> Vector a
forall a. Int -> Vector a -> Vector a
Vector.drop (Int
p Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
1) Vector a
as