module Termonad.Window where
import Termonad.Prelude
import Control.Lens ((^.), (^..), set, view, ix)
import Data.FocusList (focusList, moveFromToFL, updateFocusFL)
import Data.Sequence (findIndexR)
import qualified Data.Text as Text
import GI.Gdk (castTo, managedForeignPtr)
import GI.Gio
( actionMapAddAction
, onSimpleActionActivate
, simpleActionNew
)
import GI.Gtk
( Application
, ApplicationWindow
, Notebook
, PositionType(PositionTypeRight)
, ResponseType(ResponseTypeNo, ResponseTypeYes)
, ScrolledWindow(ScrolledWindow)
, Widget
, aboutDialogNew
, applicationSetAccelsForAction
, containerAdd
, dialogAddButton
, dialogGetContentArea
, dialogNew
, dialogResponse
, dialogRun
, entryGetText
, entryNew
, gridAttachNextTo
, gridNew
, labelNew
, onEntryActivate
, onNotebookPageReordered
, onNotebookSwitchPage
, setWidgetMargin
, widgetDestroy
, widgetGrabFocus
, widgetShow
, windowSetTransientFor
)
import GI.Pango (FontDescription)
import GI.Vte
( catchRegexError
, regexNewForSearch
, terminalCopyClipboard
, terminalPasteClipboard
, terminalSearchFindNext
, terminalSearchFindPrevious
, terminalSearchSetRegex
, terminalSearchSetWrapAround
, terminalSetFont
)
import Termonad.Keys (handleKeyPress)
import Termonad.Lenses
( lensTMNotebookTabs
, lensTMNotebookTabTerm
, lensTMStateFontDesc
, lensTerm
, lensTMStateWindows
, lensTMWindowNotebook
)
import Termonad.Term
( createTerm
, relabelTabs
, termNextPage
, termPrevPage
, termExitFocused
)
import Termonad.Types
( FontSize
, TMNotebookTab
, TMState
, TMWindowId
, fontSizeFromFontDescription
, getFocusedTermFromState
, getTMNotebookFromTMState
, getTMNotebookFromTMState'
, getTMWindowFromTMState
, setFontDescSize
, tmNotebookTabTermContainer
, tmNotebookTabs
, tmWindowAppWin
)
modifyFontSizeForAllTerms :: (FontSize -> FontSize) -> TMState -> TMWindowId -> IO ()
modifyFontSizeForAllTerms :: (FontSize -> FontSize) -> TMState -> TMWindowId -> IO ()
modifyFontSizeForAllTerms FontSize -> FontSize
modFontSizeFunc TMState
mvarTMState TMWindowId
tmWinId = do
TMState'
tmState <- TMState -> IO TMState'
forall a. MVar a -> IO a
readMVar TMState
mvarTMState
let fontDesc :: FontDescription
fontDesc = TMState'
tmState TMState'
-> Getting FontDescription TMState' FontDescription
-> FontDescription
forall s a. s -> Getting a s a -> a
^. Getting FontDescription TMState' FontDescription
Lens' TMState' FontDescription
lensTMStateFontDesc
(FontSize -> FontSize) -> FontDescription -> IO ()
adjustFontDescSize FontSize -> FontSize
modFontSizeFunc FontDescription
fontDesc
let terms :: [Terminal]
terms =
TMState'
tmState TMState'
-> Getting (Endo [Terminal]) TMState' Terminal -> [Terminal]
forall s a. s -> Getting (Endo [a]) s a -> [a]
^..
(IdMap TMWindow -> Const (Endo [Terminal]) (IdMap TMWindow))
-> TMState' -> Const (Endo [Terminal]) TMState'
Lens' TMState' (IdMap TMWindow)
lensTMStateWindows ((IdMap TMWindow -> Const (Endo [Terminal]) (IdMap TMWindow))
-> TMState' -> Const (Endo [Terminal]) TMState')
-> ((Terminal -> Const (Endo [Terminal]) Terminal)
-> IdMap TMWindow -> Const (Endo [Terminal]) (IdMap TMWindow))
-> Getting (Endo [Terminal]) TMState' Terminal
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
Index (IdMap TMWindow)
-> Traversal' (IdMap TMWindow) (IxValue (IdMap TMWindow))
forall m. Ixed m => Index m -> Traversal' m (IxValue m)
ix Index (IdMap TMWindow)
TMWindowId
tmWinId ((TMWindow -> Const (Endo [Terminal]) TMWindow)
-> IdMap TMWindow -> Const (Endo [Terminal]) (IdMap TMWindow))
-> ((Terminal -> Const (Endo [Terminal]) Terminal)
-> TMWindow -> Const (Endo [Terminal]) TMWindow)
-> (Terminal -> Const (Endo [Terminal]) Terminal)
-> IdMap TMWindow
-> Const (Endo [Terminal]) (IdMap TMWindow)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(TMNotebook -> Const (Endo [Terminal]) TMNotebook)
-> TMWindow -> Const (Endo [Terminal]) TMWindow
Lens' TMWindow TMNotebook
lensTMWindowNotebook ((TMNotebook -> Const (Endo [Terminal]) TMNotebook)
-> TMWindow -> Const (Endo [Terminal]) TMWindow)
-> ((Terminal -> Const (Endo [Terminal]) Terminal)
-> TMNotebook -> Const (Endo [Terminal]) TMNotebook)
-> (Terminal -> Const (Endo [Terminal]) Terminal)
-> TMWindow
-> Const (Endo [Terminal]) TMWindow
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(FocusList TMNotebookTab
-> Const (Endo [Terminal]) (FocusList TMNotebookTab))
-> TMNotebook -> Const (Endo [Terminal]) TMNotebook
Lens' TMNotebook (FocusList TMNotebookTab)
lensTMNotebookTabs ((FocusList TMNotebookTab
-> Const (Endo [Terminal]) (FocusList TMNotebookTab))
-> TMNotebook -> Const (Endo [Terminal]) TMNotebook)
-> ((Terminal -> Const (Endo [Terminal]) Terminal)
-> FocusList TMNotebookTab
-> Const (Endo [Terminal]) (FocusList TMNotebookTab))
-> (Terminal -> Const (Endo [Terminal]) Terminal)
-> TMNotebook
-> Const (Endo [Terminal]) TMNotebook
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(TMNotebookTab -> Const (Endo [Terminal]) TMNotebookTab)
-> FocusList TMNotebookTab
-> Const (Endo [Terminal]) (FocusList TMNotebookTab)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> FocusList a -> f (FocusList b)
traverse ((TMNotebookTab -> Const (Endo [Terminal]) TMNotebookTab)
-> FocusList TMNotebookTab
-> Const (Endo [Terminal]) (FocusList TMNotebookTab))
-> ((Terminal -> Const (Endo [Terminal]) Terminal)
-> TMNotebookTab -> Const (Endo [Terminal]) TMNotebookTab)
-> (Terminal -> Const (Endo [Terminal]) Terminal)
-> FocusList TMNotebookTab
-> Const (Endo [Terminal]) (FocusList TMNotebookTab)
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(TMTerm -> Const (Endo [Terminal]) TMTerm)
-> TMNotebookTab -> Const (Endo [Terminal]) TMNotebookTab
Lens' TMNotebookTab TMTerm
lensTMNotebookTabTerm ((TMTerm -> Const (Endo [Terminal]) TMTerm)
-> TMNotebookTab -> Const (Endo [Terminal]) TMNotebookTab)
-> ((Terminal -> Const (Endo [Terminal]) Terminal)
-> TMTerm -> Const (Endo [Terminal]) TMTerm)
-> (Terminal -> Const (Endo [Terminal]) Terminal)
-> TMNotebookTab
-> Const (Endo [Terminal]) TMNotebookTab
forall b c a. (b -> c) -> (a -> b) -> a -> c
.
(Terminal -> Const (Endo [Terminal]) Terminal)
-> TMTerm -> Const (Endo [Terminal]) TMTerm
Lens' TMTerm Terminal
lensTerm
(Terminal -> IO ()) -> [Terminal] -> IO ()
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\Terminal
vteTerm -> Terminal -> Maybe FontDescription -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsTerminal a) =>
a -> Maybe FontDescription -> m ()
terminalSetFont Terminal
vteTerm (FontDescription -> Maybe FontDescription
forall a. a -> Maybe a
Just FontDescription
fontDesc)) [Terminal]
terms
where
adjustFontDescSize :: (FontSize -> FontSize) -> FontDescription -> IO ()
adjustFontDescSize :: (FontSize -> FontSize) -> FontDescription -> IO ()
adjustFontDescSize FontSize -> FontSize
f FontDescription
fontDesc = do
FontSize
currFontSz <- FontDescription -> IO FontSize
fontSizeFromFontDescription FontDescription
fontDesc
let newFontSz :: FontSize
newFontSz = FontSize -> FontSize
f FontSize
currFontSz
FontDescription -> FontSize -> IO ()
setFontDescSize FontDescription
fontDesc FontSize
newFontSz
notebookPageReorderedCallback
:: TMState
-> TMWindowId
-> Widget
-> Word32
-> IO ()
TMState
mvarTMState TMWindowId
tmWinId Widget
childWidg Word32
pageNum = do
Maybe ScrolledWindow
maybeScrollWin <- (ManagedPtr ScrolledWindow -> ScrolledWindow)
-> Widget -> IO (Maybe ScrolledWindow)
forall o o'.
(HasCallStack, ManagedPtrNewtype o, TypedObject o,
ManagedPtrNewtype o', TypedObject o', GObject o') =>
(ManagedPtr o' -> o') -> o -> IO (Maybe o')
castTo ManagedPtr ScrolledWindow -> ScrolledWindow
ScrolledWindow Widget
childWidg
case Maybe ScrolledWindow
maybeScrollWin of
Maybe ScrolledWindow
Nothing ->
String -> IO ()
forall a. String -> IO a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$
String
"In setupTermonad, in callback for onNotebookPageReordered, " String -> String -> String
forall a. Semigroup a => a -> a -> a
<>
String
"child widget is not a ScrolledWindow.\n" String -> String -> String
forall a. Semigroup a => a -> a -> a
<>
String
"Don't know how to continue.\n"
Just ScrolledWindow
scrollWin -> do
TMNotebook
tmNote <- TMState -> TMWindowId -> IO TMNotebook
getTMNotebookFromTMState TMState
mvarTMState TMWindowId
tmWinId
let fl :: FocusList TMNotebookTab
fl = Getting
(FocusList TMNotebookTab) TMNotebook (FocusList TMNotebookTab)
-> TMNotebook -> FocusList TMNotebookTab
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting
(FocusList TMNotebookTab) TMNotebook (FocusList TMNotebookTab)
Lens' TMNotebook (FocusList TMNotebookTab)
lensTMNotebookTabs TMNotebook
tmNote
let maybeOldPosition :: Maybe Int
maybeOldPosition =
(TMNotebookTab -> Bool) -> Seq TMNotebookTab -> Maybe Int
forall a. (a -> Bool) -> Seq a -> Maybe Int
findIndexR (ScrolledWindow -> TMNotebookTab -> Bool
compareScrolledWinAndTab ScrolledWindow
scrollWin) (FocusList TMNotebookTab -> Seq TMNotebookTab
forall a. FocusList a -> Seq a
focusList FocusList TMNotebookTab
fl)
case Maybe Int
maybeOldPosition of
Maybe Int
Nothing ->
String -> IO ()
forall a. String -> IO a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$
String
"In setupTermonad, in callback for onNotebookPageReordered, " String -> String -> String
forall a. Semigroup a => a -> a -> a
<>
String
"the ScrolledWindow is not already in the FocusList.\n" String -> String -> String
forall a. Semigroup a => a -> a -> a
<>
String
"Don't know how to continue.\n"
Just Int
oldPos -> do
TMState -> TMWindowId -> Int -> Int -> IO ()
updateFLTabPos TMState
mvarTMState TMWindowId
tmWinId Int
oldPos (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
pageNum)
TMNotebook
tmNote' <- TMState -> TMWindowId -> IO TMNotebook
getTMNotebookFromTMState TMState
mvarTMState TMWindowId
tmWinId
TMNotebook -> IO ()
relabelTabs TMNotebook
tmNote'
where
compareScrolledWinAndTab :: ScrolledWindow -> TMNotebookTab -> Bool
compareScrolledWinAndTab :: ScrolledWindow -> TMNotebookTab -> Bool
compareScrolledWinAndTab ScrolledWindow
scrollWin TMNotebookTab
flTab =
let ScrolledWindow ManagedPtr ScrolledWindow
managedPtrFLTab = TMNotebookTab -> ScrolledWindow
tmNotebookTabTermContainer TMNotebookTab
flTab
foreignPtrFLTab :: ForeignPtr ScrolledWindow
foreignPtrFLTab = ManagedPtr ScrolledWindow -> ForeignPtr ScrolledWindow
forall a. ManagedPtr a -> ForeignPtr a
managedForeignPtr ManagedPtr ScrolledWindow
managedPtrFLTab
ScrolledWindow ManagedPtr ScrolledWindow
managedPtrScrollWin = ScrolledWindow
scrollWin
foreignPtrScrollWin :: ForeignPtr ScrolledWindow
foreignPtrScrollWin = ManagedPtr ScrolledWindow -> ForeignPtr ScrolledWindow
forall a. ManagedPtr a -> ForeignPtr a
managedForeignPtr ManagedPtr ScrolledWindow
managedPtrScrollWin
in ForeignPtr ScrolledWindow
foreignPtrFLTab ForeignPtr ScrolledWindow -> ForeignPtr ScrolledWindow -> Bool
forall a. Eq a => a -> a -> Bool
== ForeignPtr ScrolledWindow
foreignPtrScrollWin
updateFLTabPos
:: TMState
-> TMWindowId
-> Int
-> Int
-> IO ()
updateFLTabPos :: TMState -> TMWindowId -> Int -> Int -> IO ()
updateFLTabPos TMState
mvarTMState TMWindowId
tmWinId Int
oldPos Int
newPos =
TMState -> (TMState' -> IO TMState') -> IO ()
forall a. MVar a -> (a -> IO a) -> IO ()
modifyMVar_ TMState
mvarTMState ((TMState' -> IO TMState') -> IO ())
-> (TMState' -> IO TMState') -> IO ()
forall a b. (a -> b) -> a -> b
$ \TMState'
tmState -> do
TMNotebook
note <- TMState' -> TMWindowId -> IO TMNotebook
getTMNotebookFromTMState' TMState'
tmState TMWindowId
tmWinId
let tabs :: FocusList TMNotebookTab
tabs = TMNotebook -> FocusList TMNotebookTab
tmNotebookTabs TMNotebook
note
maybeNewTabs :: Maybe (FocusList TMNotebookTab)
maybeNewTabs = Int
-> Int
-> FocusList TMNotebookTab
-> Maybe (FocusList TMNotebookTab)
forall a.
Show a =>
Int -> Int -> FocusList a -> Maybe (FocusList a)
moveFromToFL Int
oldPos Int
newPos FocusList TMNotebookTab
tabs
case Maybe (FocusList TMNotebookTab)
maybeNewTabs of
Maybe (FocusList TMNotebookTab)
Nothing -> do
String -> IO ()
putStrLn (String -> IO ()) -> String -> IO ()
forall a b. (a -> b) -> a -> b
$
String
"in updateFLTabPos, Strange error: couldn't move tabs.\n" String -> String -> String
forall a. Semigroup a => a -> a -> a
<>
String
"old pos: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
oldPos String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"\n" String -> String -> String
forall a. Semigroup a => a -> a -> a
<>
String
"new pos: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Int -> String
forall a. Show a => a -> String
show Int
newPos String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"\n" String -> String -> String
forall a. Semigroup a => a -> a -> a
<>
String
"tabs: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> FocusList TMNotebookTab -> String
forall a. Show a => a -> String
show FocusList TMNotebookTab
tabs String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"\n" String -> String -> String
forall a. Semigroup a => a -> a -> a
<>
String
"maybeNewTabs: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> Maybe (FocusList TMNotebookTab) -> String
forall a. Show a => a -> String
show Maybe (FocusList TMNotebookTab)
maybeNewTabs String -> String -> String
forall a. Semigroup a => a -> a -> a
<> String
"\n" String -> String -> String
forall a. Semigroup a => a -> a -> a
<>
String
"tmState: " String -> String -> String
forall a. Semigroup a => a -> a -> a
<> TMState' -> String
forall a. Show a => a -> String
show TMState'
tmState
TMState' -> IO TMState'
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure TMState'
tmState
Just FocusList TMNotebookTab
newTabs ->
TMState' -> IO TMState'
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TMState' -> IO TMState') -> TMState' -> IO TMState'
forall a b. (a -> b) -> a -> b
$
ASetter
TMState'
TMState'
(FocusList TMNotebookTab)
(FocusList TMNotebookTab)
-> FocusList TMNotebookTab -> TMState' -> TMState'
forall s t a b. ASetter s t a b -> b -> s -> t
set
((IdMap TMWindow -> Identity (IdMap TMWindow))
-> TMState' -> Identity TMState'
Lens' TMState' (IdMap TMWindow)
lensTMStateWindows ((IdMap TMWindow -> Identity (IdMap TMWindow))
-> TMState' -> Identity TMState')
-> ((FocusList TMNotebookTab -> Identity (FocusList TMNotebookTab))
-> IdMap TMWindow -> Identity (IdMap TMWindow))
-> ASetter
TMState'
TMState'
(FocusList TMNotebookTab)
(FocusList TMNotebookTab)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index (IdMap TMWindow)
-> Traversal' (IdMap TMWindow) (IxValue (IdMap TMWindow))
forall m. Ixed m => Index m -> Traversal' m (IxValue m)
ix Index (IdMap TMWindow)
TMWindowId
tmWinId ((TMWindow -> Identity TMWindow)
-> IdMap TMWindow -> Identity (IdMap TMWindow))
-> ((FocusList TMNotebookTab -> Identity (FocusList TMNotebookTab))
-> TMWindow -> Identity TMWindow)
-> (FocusList TMNotebookTab -> Identity (FocusList TMNotebookTab))
-> IdMap TMWindow
-> Identity (IdMap TMWindow)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TMNotebook -> Identity TMNotebook)
-> TMWindow -> Identity TMWindow
Lens' TMWindow TMNotebook
lensTMWindowNotebook ((TMNotebook -> Identity TMNotebook)
-> TMWindow -> Identity TMWindow)
-> ((FocusList TMNotebookTab -> Identity (FocusList TMNotebookTab))
-> TMNotebook -> Identity TMNotebook)
-> (FocusList TMNotebookTab -> Identity (FocusList TMNotebookTab))
-> TMWindow
-> Identity TMWindow
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocusList TMNotebookTab -> Identity (FocusList TMNotebookTab))
-> TMNotebook -> Identity TMNotebook
Lens' TMNotebook (FocusList TMNotebookTab)
lensTMNotebookTabs)
FocusList TMNotebookTab
newTabs
TMState'
tmState
showAboutDialog :: ApplicationWindow -> IO ()
showAboutDialog :: ApplicationWindow -> IO ()
showAboutDialog ApplicationWindow
win = do
AboutDialog
aboutDialog <- IO AboutDialog
forall (m :: * -> *). (HasCallStack, MonadIO m) => m AboutDialog
aboutDialogNew
AboutDialog -> Maybe ApplicationWindow -> IO ()
forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsWindow a, IsWindow b) =>
a -> Maybe b -> m ()
windowSetTransientFor AboutDialog
aboutDialog (ApplicationWindow -> Maybe ApplicationWindow
forall a. a -> Maybe a
Just ApplicationWindow
win)
IO Int32 -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO Int32 -> IO ()) -> IO Int32 -> IO ()
forall a b. (a -> b) -> a -> b
$ AboutDialog -> IO Int32
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsDialog a) =>
a -> m Int32
dialogRun AboutDialog
aboutDialog
AboutDialog -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsWidget a) =>
a -> m ()
widgetDestroy AboutDialog
aboutDialog
showFindDialog :: ApplicationWindow -> IO (Maybe Text)
showFindDialog :: ApplicationWindow -> IO (Maybe Text)
showFindDialog ApplicationWindow
win = do
Dialog
dialog <- IO Dialog
forall (m :: * -> *). (HasCallStack, MonadIO m) => m Dialog
dialogNew
Box
box <- Dialog -> IO Box
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsDialog a) =>
a -> m Box
dialogGetContentArea Dialog
dialog
Grid
grid <- IO Grid
forall (m :: * -> *). (HasCallStack, MonadIO m) => m Grid
gridNew
Label
searchForLabel <- Maybe Text -> IO Label
forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Maybe Text -> m Label
labelNew (Text -> Maybe Text
forall a. a -> Maybe a
Just Text
"Search for regex:")
Grid -> Label -> IO ()
forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsContainer a, IsWidget b) =>
a -> b -> m ()
containerAdd Grid
grid Label
searchForLabel
Label -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsWidget a) =>
a -> m ()
widgetShow Label
searchForLabel
Label -> Int32 -> IO ()
forall (m :: * -> *) o.
(MonadIO m, IsWidget o) =>
o -> Int32 -> m ()
setWidgetMargin Label
searchForLabel Int32
10
Entry
searchEntry <- IO Entry
forall (m :: * -> *). (HasCallStack, MonadIO m) => m Entry
entryNew
Grid
-> Entry -> Maybe Label -> PositionType -> Int32 -> Int32 -> IO ()
forall (m :: * -> *) a b c.
(HasCallStack, MonadIO m, IsGrid a, IsWidget b, IsWidget c) =>
a -> b -> Maybe c -> PositionType -> Int32 -> Int32 -> m ()
gridAttachNextTo Grid
grid Entry
searchEntry (Label -> Maybe Label
forall a. a -> Maybe a
Just Label
searchForLabel) PositionType
PositionTypeRight Int32
1 Int32
1
Entry -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsWidget a) =>
a -> m ()
widgetShow Entry
searchEntry
Entry -> Int32 -> IO ()
forall (m :: * -> *) o.
(MonadIO m, IsWidget o) =>
o -> Int32 -> m ()
setWidgetMargin Entry
searchEntry Int32
10
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
$
Entry -> ((?self::Entry) => IO ()) -> IO SignalHandlerId
forall a (m :: * -> *).
(IsEntry a, MonadIO m) =>
a -> ((?self::a) => IO ()) -> m SignalHandlerId
onEntryActivate Entry
searchEntry (((?self::Entry) => IO ()) -> IO SignalHandlerId)
-> ((?self::Entry) => IO ()) -> IO SignalHandlerId
forall a b. (a -> b) -> a -> b
$
Dialog -> Int32 -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsDialog a) =>
a -> Int32 -> m ()
dialogResponse Dialog
dialog (Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ResponseType -> Int
forall a. Enum a => a -> Int
fromEnum ResponseType
ResponseTypeYes))
IO Widget -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO Widget -> IO ()) -> IO Widget -> IO ()
forall a b. (a -> b) -> a -> b
$
Dialog -> Text -> Int32 -> IO Widget
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsDialog a) =>
a -> Text -> Int32 -> m Widget
dialogAddButton
Dialog
dialog
Text
"Close"
(Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ResponseType -> Int
forall a. Enum a => a -> Int
fromEnum ResponseType
ResponseTypeNo))
IO Widget -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO Widget -> IO ()) -> IO Widget -> IO ()
forall a b. (a -> b) -> a -> b
$
Dialog -> Text -> Int32 -> IO Widget
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsDialog a) =>
a -> Text -> Int32 -> m Widget
dialogAddButton
Dialog
dialog
Text
"Find"
(Int -> Int32
forall a b. (Integral a, Num b) => a -> b
fromIntegral (ResponseType -> Int
forall a. Enum a => a -> Int
fromEnum ResponseType
ResponseTypeYes))
Box -> Grid -> IO ()
forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsContainer a, IsWidget b) =>
a -> b -> m ()
containerAdd Box
box Grid
grid
Grid -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsWidget a) =>
a -> m ()
widgetShow Grid
grid
Dialog -> Maybe ApplicationWindow -> IO ()
forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsWindow a, IsWindow b) =>
a -> Maybe b -> m ()
windowSetTransientFor Dialog
dialog (ApplicationWindow -> Maybe ApplicationWindow
forall a. a -> Maybe a
Just ApplicationWindow
win)
Int32
res <- Dialog -> IO Int32
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsDialog a) =>
a -> m Int32
dialogRun Dialog
dialog
Text
searchString <- Entry -> IO Text
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsEntry a) =>
a -> m Text
entryGetText Entry
searchEntry
let maybeSearchString :: Maybe Text
maybeSearchString =
case Int -> ResponseType
forall a. Enum a => Int -> a
toEnum (Int32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int32
res) of
ResponseType
ResponseTypeYes -> Text -> Maybe Text
forall a. a -> Maybe a
Just Text
searchString
ResponseType
_ -> Maybe Text
forall a. Maybe a
Nothing
Dialog -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsWidget a) =>
a -> m ()
widgetDestroy Dialog
dialog
Maybe Text -> IO (Maybe Text)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Maybe Text
maybeSearchString
doFind :: TMState -> TMWindowId -> IO ()
doFind :: TMState -> TMWindowId -> IO ()
doFind TMState
mvarTMState TMWindowId
tmWinId = do
TMWindow
tmWin <- TMState -> TMWindowId -> IO TMWindow
getTMWindowFromTMState TMState
mvarTMState TMWindowId
tmWinId
let win :: ApplicationWindow
win = TMWindow -> ApplicationWindow
tmWindowAppWin TMWindow
tmWin
Maybe Text
maybeSearchString <- ApplicationWindow -> IO (Maybe Text)
showFindDialog ApplicationWindow
win
Maybe Terminal
maybeTerminal <- TMState -> TMWindowId -> IO (Maybe Terminal)
getFocusedTermFromState TMState
mvarTMState TMWindowId
tmWinId
case (Maybe Text
maybeSearchString, Maybe Terminal
maybeTerminal) of
(Just Text
searchString, Just Terminal
terminal) -> do
let pcreFlags :: Word32
pcreFlags = Word32
0
let newRegex :: IO Regex
newRegex =
Text -> Int64 -> Word32 -> IO Regex
forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Int64 -> Word32 -> m Regex
regexNewForSearch
Text
searchString
(Int -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Int64) -> Int -> Int64
forall a b. (a -> b) -> a -> b
$ Text -> Int
Text.length Text
searchString)
Word32
pcreFlags
Either Text Regex
eitherRegex <-
IO (Either Text Regex)
-> (RegexError -> Text -> IO (Either Text Regex))
-> IO (Either Text Regex)
forall a. IO a -> (RegexError -> Text -> IO a) -> IO a
catchRegexError
((Regex -> Either Text Regex) -> IO Regex -> IO (Either Text Regex)
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Regex -> Either Text Regex
forall a b. b -> Either a b
Right IO Regex
newRegex)
(\RegexError
_ Text
errMsg -> Either Text Regex -> IO (Either Text Regex)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Text -> Either Text Regex
forall a b. a -> Either a b
Left Text
errMsg))
case Either Text Regex
eitherRegex of
Left Text
errMsg -> do
let msg :: Text
msg = Text
"error when creating regex: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
errMsg
Handle -> Text -> IO ()
forall (m :: * -> *). MonadIO m => Handle -> Text -> m ()
hPutStrLn Handle
stderr Text
msg
Right Regex
regex -> do
Terminal -> Maybe Regex -> Word32 -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsTerminal a) =>
a -> Maybe Regex -> Word32 -> m ()
terminalSearchSetRegex Terminal
terminal (Regex -> Maybe Regex
forall a. a -> Maybe a
Just Regex
regex) Word32
pcreFlags
Terminal -> Bool -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsTerminal a) =>
a -> Bool -> m ()
terminalSearchSetWrapAround Terminal
terminal Bool
True
Bool
_matchFound <- Terminal -> IO Bool
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsTerminal a) =>
a -> m Bool
terminalSearchFindPrevious Terminal
terminal
() -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
(Maybe Text, Maybe Terminal)
_ -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
findAbove :: TMState -> TMWindowId -> IO ()
findAbove :: TMState -> TMWindowId -> IO ()
findAbove TMState
mvarTMState TMWindowId
tmWinId = do
Maybe Terminal
maybeTerminal <- TMState -> TMWindowId -> IO (Maybe Terminal)
getFocusedTermFromState TMState
mvarTMState TMWindowId
tmWinId
case Maybe Terminal
maybeTerminal of
Maybe Terminal
Nothing -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Just Terminal
terminal -> do
Bool
_matchFound <- Terminal -> IO Bool
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsTerminal a) =>
a -> m Bool
terminalSearchFindPrevious Terminal
terminal
() -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
findBelow :: TMState -> TMWindowId -> IO ()
findBelow :: TMState -> TMWindowId -> IO ()
findBelow TMState
mvarTMState TMWindowId
tmWinId = do
Maybe Terminal
maybeTerminal <- TMState -> TMWindowId -> IO (Maybe Terminal)
getFocusedTermFromState TMState
mvarTMState TMWindowId
tmWinId
case Maybe Terminal
maybeTerminal of
Maybe Terminal
Nothing -> () -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Just Terminal
terminal -> do
Bool
_matchFound <- Terminal -> IO Bool
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsTerminal a) =>
a -> m Bool
terminalSearchFindNext Terminal
terminal
() -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
setupWindowCallbacks :: TMState -> Application -> ApplicationWindow -> Notebook -> TMWindowId -> IO ()
setupWindowCallbacks :: TMState
-> Application
-> ApplicationWindow
-> Notebook
-> TMWindowId
-> IO ()
setupWindowCallbacks TMState
mvarTMState Application
app ApplicationWindow
win Notebook
note TMWindowId
tmWinId = do
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
$ Notebook
-> ((?self::Notebook) => Widget -> Word32 -> IO ())
-> IO SignalHandlerId
forall a (m :: * -> *).
(IsNotebook a, MonadIO m) =>
a -> ((?self::a) => Widget -> Word32 -> IO ()) -> m SignalHandlerId
onNotebookSwitchPage Notebook
note (((?self::Notebook) => Widget -> Word32 -> IO ())
-> IO SignalHandlerId)
-> ((?self::Notebook) => Widget -> Word32 -> IO ())
-> IO SignalHandlerId
forall a b. (a -> b) -> a -> b
$ \Widget
_ Word32
pageNum -> do
TMState -> (TMState' -> IO TMState') -> IO ()
forall a. MVar a -> (a -> IO a) -> IO ()
modifyMVar_ TMState
mvarTMState ((TMState' -> IO TMState') -> IO ())
-> (TMState' -> IO TMState') -> IO ()
forall a b. (a -> b) -> a -> b
$ \TMState'
tmState -> do
TMNotebook
tmNote <- TMState' -> TMWindowId -> IO TMNotebook
getTMNotebookFromTMState' TMState'
tmState TMWindowId
tmWinId
let tabs :: FocusList TMNotebookTab
tabs = TMNotebook -> FocusList TMNotebookTab
tmNotebookTabs TMNotebook
tmNote
maybeNewTabs :: Maybe (TMNotebookTab, FocusList TMNotebookTab)
maybeNewTabs = Int
-> FocusList TMNotebookTab
-> Maybe (TMNotebookTab, FocusList TMNotebookTab)
forall a. Int -> FocusList a -> Maybe (a, FocusList a)
updateFocusFL (Word32 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word32
pageNum) FocusList TMNotebookTab
tabs
case Maybe (TMNotebookTab, FocusList TMNotebookTab)
maybeNewTabs of
Maybe (TMNotebookTab, FocusList TMNotebookTab)
Nothing -> TMState' -> IO TMState'
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure TMState'
tmState
Just (TMNotebookTab
tab, FocusList TMNotebookTab
newTabs) -> do
Terminal -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsWidget a) =>
a -> m ()
widgetGrabFocus (Terminal -> IO ()) -> Terminal -> IO ()
forall a b. (a -> b) -> a -> b
$ TMNotebookTab
tab TMNotebookTab
-> Getting Terminal TMNotebookTab Terminal -> Terminal
forall s a. s -> Getting a s a -> a
^. (TMTerm -> Const Terminal TMTerm)
-> TMNotebookTab -> Const Terminal TMNotebookTab
Lens' TMNotebookTab TMTerm
lensTMNotebookTabTerm ((TMTerm -> Const Terminal TMTerm)
-> TMNotebookTab -> Const Terminal TMNotebookTab)
-> ((Terminal -> Const Terminal Terminal)
-> TMTerm -> Const Terminal TMTerm)
-> Getting Terminal TMNotebookTab Terminal
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Terminal -> Const Terminal Terminal)
-> TMTerm -> Const Terminal TMTerm
Lens' TMTerm Terminal
lensTerm
TMState' -> IO TMState'
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (TMState' -> IO TMState') -> TMState' -> IO TMState'
forall a b. (a -> b) -> a -> b
$
ASetter
TMState'
TMState'
(FocusList TMNotebookTab)
(FocusList TMNotebookTab)
-> FocusList TMNotebookTab -> TMState' -> TMState'
forall s t a b. ASetter s t a b -> b -> s -> t
set
((IdMap TMWindow -> Identity (IdMap TMWindow))
-> TMState' -> Identity TMState'
Lens' TMState' (IdMap TMWindow)
lensTMStateWindows ((IdMap TMWindow -> Identity (IdMap TMWindow))
-> TMState' -> Identity TMState')
-> ((FocusList TMNotebookTab -> Identity (FocusList TMNotebookTab))
-> IdMap TMWindow -> Identity (IdMap TMWindow))
-> ASetter
TMState'
TMState'
(FocusList TMNotebookTab)
(FocusList TMNotebookTab)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index (IdMap TMWindow)
-> Traversal' (IdMap TMWindow) (IxValue (IdMap TMWindow))
forall m. Ixed m => Index m -> Traversal' m (IxValue m)
ix Index (IdMap TMWindow)
TMWindowId
tmWinId ((TMWindow -> Identity TMWindow)
-> IdMap TMWindow -> Identity (IdMap TMWindow))
-> ((FocusList TMNotebookTab -> Identity (FocusList TMNotebookTab))
-> TMWindow -> Identity TMWindow)
-> (FocusList TMNotebookTab -> Identity (FocusList TMNotebookTab))
-> IdMap TMWindow
-> Identity (IdMap TMWindow)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TMNotebook -> Identity TMNotebook)
-> TMWindow -> Identity TMWindow
Lens' TMWindow TMNotebook
lensTMWindowNotebook ((TMNotebook -> Identity TMNotebook)
-> TMWindow -> Identity TMWindow)
-> ((FocusList TMNotebookTab -> Identity (FocusList TMNotebookTab))
-> TMNotebook -> Identity TMNotebook)
-> (FocusList TMNotebookTab -> Identity (FocusList TMNotebookTab))
-> TMWindow
-> Identity TMWindow
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocusList TMNotebookTab -> Identity (FocusList TMNotebookTab))
-> TMNotebook -> Identity TMNotebook
Lens' TMNotebook (FocusList TMNotebookTab)
lensTMNotebookTabs)
FocusList TMNotebookTab
newTabs
TMState'
tmState
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
$ Notebook
-> ((?self::Notebook) => Widget -> Word32 -> IO ())
-> IO SignalHandlerId
forall a (m :: * -> *).
(IsNotebook a, MonadIO m) =>
a -> ((?self::a) => Widget -> Word32 -> IO ()) -> m SignalHandlerId
onNotebookPageReordered Notebook
note (((?self::Notebook) => Widget -> Word32 -> IO ())
-> IO SignalHandlerId)
-> ((?self::Notebook) => Widget -> Word32 -> IO ())
-> IO SignalHandlerId
forall a b. (a -> b) -> a -> b
$ \Widget
childWidg Word32
pageNum ->
TMState -> TMWindowId -> Widget -> Word32 -> IO ()
notebookPageReorderedCallback TMState
mvarTMState TMWindowId
tmWinId Widget
childWidg Word32
pageNum
SimpleAction
newTabAction <- Text -> Maybe VariantType -> IO SimpleAction
forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Maybe VariantType -> m SimpleAction
simpleActionNew Text
"newtab" Maybe VariantType
forall a. Maybe a
Nothing
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
$ SimpleAction
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a (m :: * -> *).
(IsSimpleAction a, MonadIO m) =>
a
-> ((?self::a) => SimpleActionActivateCallback)
-> m SignalHandlerId
onSimpleActionActivate SimpleAction
newTabAction (((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId)
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a b. (a -> b) -> a -> b
$ \Maybe GVariant
_ ->
IO TMTerm -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO TMTerm -> IO ()) -> IO TMTerm -> IO ()
forall a b. (a -> b) -> a -> b
$ (TMState -> TMWindowId -> EventKey -> IO Bool)
-> TMState -> TMWindowId -> IO TMTerm
createTerm TMState -> TMWindowId -> EventKey -> IO Bool
handleKeyPress TMState
mvarTMState TMWindowId
tmWinId
ApplicationWindow -> SimpleAction -> IO ()
forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsActionMap a, IsAction b) =>
a -> b -> m ()
actionMapAddAction ApplicationWindow
win SimpleAction
newTabAction
Application -> Text -> [Text] -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsApplication a) =>
a -> Text -> [Text] -> m ()
applicationSetAccelsForAction Application
app Text
"win.newtab" [Text
Item [Text]
"<Shift><Ctrl>T"]
SimpleAction
nextPageAction <- Text -> Maybe VariantType -> IO SimpleAction
forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Maybe VariantType -> m SimpleAction
simpleActionNew Text
"nextpage" Maybe VariantType
forall a. Maybe a
Nothing
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
$ SimpleAction
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a (m :: * -> *).
(IsSimpleAction a, MonadIO m) =>
a
-> ((?self::a) => SimpleActionActivateCallback)
-> m SignalHandlerId
onSimpleActionActivate SimpleAction
nextPageAction (((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId)
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a b. (a -> b) -> a -> b
$ \Maybe GVariant
_ ->
TMState -> TMWindowId -> IO ()
termNextPage TMState
mvarTMState TMWindowId
tmWinId
ApplicationWindow -> SimpleAction -> IO ()
forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsActionMap a, IsAction b) =>
a -> b -> m ()
actionMapAddAction ApplicationWindow
win SimpleAction
nextPageAction
Application -> Text -> [Text] -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsApplication a) =>
a -> Text -> [Text] -> m ()
applicationSetAccelsForAction Application
app Text
"win.nextpage" [Text
Item [Text]
"<Ctrl>Page_Down"]
SimpleAction
prevPageAction <- Text -> Maybe VariantType -> IO SimpleAction
forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Maybe VariantType -> m SimpleAction
simpleActionNew Text
"prevpage" Maybe VariantType
forall a. Maybe a
Nothing
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
$ SimpleAction
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a (m :: * -> *).
(IsSimpleAction a, MonadIO m) =>
a
-> ((?self::a) => SimpleActionActivateCallback)
-> m SignalHandlerId
onSimpleActionActivate SimpleAction
prevPageAction (((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId)
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a b. (a -> b) -> a -> b
$ \Maybe GVariant
_ ->
TMState -> TMWindowId -> IO ()
termPrevPage TMState
mvarTMState TMWindowId
tmWinId
ApplicationWindow -> SimpleAction -> IO ()
forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsActionMap a, IsAction b) =>
a -> b -> m ()
actionMapAddAction ApplicationWindow
win SimpleAction
prevPageAction
Application -> Text -> [Text] -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsApplication a) =>
a -> Text -> [Text] -> m ()
applicationSetAccelsForAction Application
app Text
"win.prevpage" [Text
Item [Text]
"<Ctrl>Page_Up"]
SimpleAction
closeTabAction <- Text -> Maybe VariantType -> IO SimpleAction
forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Maybe VariantType -> m SimpleAction
simpleActionNew Text
"closetab" Maybe VariantType
forall a. Maybe a
Nothing
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
$ SimpleAction
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a (m :: * -> *).
(IsSimpleAction a, MonadIO m) =>
a
-> ((?self::a) => SimpleActionActivateCallback)
-> m SignalHandlerId
onSimpleActionActivate SimpleAction
closeTabAction (((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId)
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a b. (a -> b) -> a -> b
$ \Maybe GVariant
_ ->
TMState -> TMWindowId -> IO ()
termExitFocused TMState
mvarTMState TMWindowId
tmWinId
ApplicationWindow -> SimpleAction -> IO ()
forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsActionMap a, IsAction b) =>
a -> b -> m ()
actionMapAddAction ApplicationWindow
win SimpleAction
closeTabAction
Application -> Text -> [Text] -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsApplication a) =>
a -> Text -> [Text] -> m ()
applicationSetAccelsForAction Application
app Text
"win.closetab" [Text
Item [Text]
"<Shift><Ctrl>W"]
SimpleAction
copyAction <- Text -> Maybe VariantType -> IO SimpleAction
forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Maybe VariantType -> m SimpleAction
simpleActionNew Text
"copy" Maybe VariantType
forall a. Maybe a
Nothing
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
$ SimpleAction
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a (m :: * -> *).
(IsSimpleAction a, MonadIO m) =>
a
-> ((?self::a) => SimpleActionActivateCallback)
-> m SignalHandlerId
onSimpleActionActivate SimpleAction
copyAction (((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId)
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a b. (a -> b) -> a -> b
$ \Maybe GVariant
_ -> do
Maybe Terminal
maybeTerm <- TMState -> TMWindowId -> IO (Maybe Terminal)
getFocusedTermFromState TMState
mvarTMState TMWindowId
tmWinId
IO () -> (Terminal -> IO ()) -> Maybe Terminal -> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) Terminal -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsTerminal a) =>
a -> m ()
terminalCopyClipboard Maybe Terminal
maybeTerm
ApplicationWindow -> SimpleAction -> IO ()
forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsActionMap a, IsAction b) =>
a -> b -> m ()
actionMapAddAction ApplicationWindow
win SimpleAction
copyAction
Application -> Text -> [Text] -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsApplication a) =>
a -> Text -> [Text] -> m ()
applicationSetAccelsForAction Application
app Text
"win.copy" [Text
Item [Text]
"<Shift><Ctrl>C"]
SimpleAction
pasteAction <- Text -> Maybe VariantType -> IO SimpleAction
forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Maybe VariantType -> m SimpleAction
simpleActionNew Text
"paste" Maybe VariantType
forall a. Maybe a
Nothing
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
$ SimpleAction
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a (m :: * -> *).
(IsSimpleAction a, MonadIO m) =>
a
-> ((?self::a) => SimpleActionActivateCallback)
-> m SignalHandlerId
onSimpleActionActivate SimpleAction
pasteAction (((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId)
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a b. (a -> b) -> a -> b
$ \Maybe GVariant
_ -> do
Maybe Terminal
maybeTerm <- TMState -> TMWindowId -> IO (Maybe Terminal)
getFocusedTermFromState TMState
mvarTMState TMWindowId
tmWinId
IO () -> (Terminal -> IO ()) -> Maybe Terminal -> IO ()
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (() -> IO ()
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()) Terminal -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsTerminal a) =>
a -> m ()
terminalPasteClipboard Maybe Terminal
maybeTerm
ApplicationWindow -> SimpleAction -> IO ()
forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsActionMap a, IsAction b) =>
a -> b -> m ()
actionMapAddAction ApplicationWindow
win SimpleAction
pasteAction
Application -> Text -> [Text] -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsApplication a) =>
a -> Text -> [Text] -> m ()
applicationSetAccelsForAction Application
app Text
"win.paste" [Text
Item [Text]
"<Shift><Ctrl>V"]
SimpleAction
findAction <- Text -> Maybe VariantType -> IO SimpleAction
forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Maybe VariantType -> m SimpleAction
simpleActionNew Text
"find" Maybe VariantType
forall a. Maybe a
Nothing
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
$ SimpleAction
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a (m :: * -> *).
(IsSimpleAction a, MonadIO m) =>
a
-> ((?self::a) => SimpleActionActivateCallback)
-> m SignalHandlerId
onSimpleActionActivate SimpleAction
findAction (((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId)
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a b. (a -> b) -> a -> b
$ \Maybe GVariant
_ -> TMState -> TMWindowId -> IO ()
doFind TMState
mvarTMState TMWindowId
tmWinId
ApplicationWindow -> SimpleAction -> IO ()
forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsActionMap a, IsAction b) =>
a -> b -> m ()
actionMapAddAction ApplicationWindow
win SimpleAction
findAction
Application -> Text -> [Text] -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsApplication a) =>
a -> Text -> [Text] -> m ()
applicationSetAccelsForAction Application
app Text
"win.find" [Text
Item [Text]
"<Shift><Ctrl>F"]
SimpleAction
findAboveAction <- Text -> Maybe VariantType -> IO SimpleAction
forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Maybe VariantType -> m SimpleAction
simpleActionNew Text
"findabove" Maybe VariantType
forall a. Maybe a
Nothing
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
$ SimpleAction
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a (m :: * -> *).
(IsSimpleAction a, MonadIO m) =>
a
-> ((?self::a) => SimpleActionActivateCallback)
-> m SignalHandlerId
onSimpleActionActivate SimpleAction
findAboveAction (((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId)
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a b. (a -> b) -> a -> b
$ \Maybe GVariant
_ -> TMState -> TMWindowId -> IO ()
findAbove TMState
mvarTMState TMWindowId
tmWinId
ApplicationWindow -> SimpleAction -> IO ()
forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsActionMap a, IsAction b) =>
a -> b -> m ()
actionMapAddAction ApplicationWindow
win SimpleAction
findAboveAction
Application -> Text -> [Text] -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsApplication a) =>
a -> Text -> [Text] -> m ()
applicationSetAccelsForAction Application
app Text
"win.findabove" [Text
Item [Text]
"<Shift><Ctrl>P"]
SimpleAction
findBelowAction <- Text -> Maybe VariantType -> IO SimpleAction
forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
Text -> Maybe VariantType -> m SimpleAction
simpleActionNew Text
"findbelow" Maybe VariantType
forall a. Maybe a
Nothing
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
$ SimpleAction
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a (m :: * -> *).
(IsSimpleAction a, MonadIO m) =>
a
-> ((?self::a) => SimpleActionActivateCallback)
-> m SignalHandlerId
onSimpleActionActivate SimpleAction
findBelowAction (((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId)
-> ((?self::SimpleAction) => SimpleActionActivateCallback)
-> IO SignalHandlerId
forall a b. (a -> b) -> a -> b
$ \Maybe GVariant
_ -> TMState -> TMWindowId -> IO ()
findBelow TMState
mvarTMState TMWindowId
tmWinId
ApplicationWindow -> SimpleAction -> IO ()
forall (m :: * -> *) a b.
(HasCallStack, MonadIO m, IsActionMap a, IsAction b) =>
a -> b -> m ()
actionMapAddAction ApplicationWindow
win SimpleAction
findBelowAction
Application -> Text -> [Text] -> IO ()
forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsApplication a) =>
a -> Text -> [Text] -> m ()
applicationSetAccelsForAction Application
app Text
"win.findbelow" [Text
Item [Text]
"<Shift><Ctrl>I"]