Skip to content

Commit 9bc64ad

Browse files
popupSaveBeforeExit 🤷
1 parent 6ac50f6 commit 9bc64ad

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/Potato/Flow/Vty/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,5 +395,5 @@ mainPFWidgetWithBypass MainPFWidgetConfig {..} bypassEvent = mdo
395395

396396

397397
-- handle escape event
398-
-- TODO we want to prompt for save first
398+
-- TODO we want to prompt for save first, use popupSaveBeforeExit
399399
return $ leftmost [_appKbCmd_quit, _menuButtonsWidget_quitEv . _leftWidget_menuButtonsW $ leftW]

src/Potato/Flow/Vty/SaveAsWindow.hs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
-- TODO rename this file to PopupDialogs or something
12
{-# LANGUAGE RecordWildCards #-}
23
{-# LANGUAGE RecursiveDo #-}
34

@@ -41,7 +42,6 @@ data SaveAsWindowConfig t = SaveAsWindowConfig {
4142
_saveAsWindowConfig_saveAs :: Event t FP.FilePath -- ^ Event to launch the popup window to save file as Text is previous file name or empty string
4243
}
4344

44-
-- UNTESTED
4545
popupSaveAsWindow :: forall t m. (MonadWidget t m, HasPotato t m)
4646
=> SaveAsWindowConfig t
4747
-> m (Event t FP.FilePath, Dynamic t Bool) -- ^ (file to save to, popup state)
@@ -72,3 +72,31 @@ popupSaveAsWindow SaveAsWindowConfig {..} = do
7272
return (cancelEv, saveAsFileEv)
7373
fmapfn w = \escEv clickOutsideEv -> fmap (\(cancelEv, outputEv) -> (leftmost [escEv, cancelEv, void outputEv], outputEv)) w
7474
popupPane def $ (fmap fmapfn popupSaveAsEv)
75+
76+
77+
data SaveBeforeExitConfig t = SaveBeforeExitConfig {
78+
_saveBeforeExitConfig_exitWithChanges :: Event t ()
79+
}
80+
data SaveBeforeExitOutput t = SaveBeforeExitOutput {
81+
_saveBeforeExitOutput_save :: Event t ()
82+
, _saveBeforeExitOutput_saveAs :: Event t ()
83+
}
84+
85+
popupSaveBeforeExit :: forall t m. (MonadWidget t m, HasPotato t m)
86+
=> SaveBeforeExitConfig t
87+
-> m (SaveBeforeExitOutput t, Dynamic t Bool)
88+
popupSaveBeforeExit SaveBeforeExitConfig {..} = do
89+
-- TODO style everything
90+
let
91+
popupSaveBeforeExitEv = ffor _saveBeforeExitConfig_exitWithChanges $ \f0 -> mdo
92+
boxTitle (constant def) "You have unsaved changes. Would you like to save?" $ do
93+
initManager_ $ col $ mdo
94+
(cancelEv, saveButtonEv, saveAsButtonEv) <- (tile . fixed) 3 $ row $ do
95+
cancelEv' <- (tile . stretch) 10 $ textButton def "cancel"
96+
saveEv' <- (tile . stretch) 10 $ textButton def "save"
97+
saveAsEv' <- (tile . stretch) 10 $ textButton def "save as"
98+
return (cancelEv', saveEv', saveAsEv')
99+
return (cancelEv, align saveButtonEv saveAsButtonEv)
100+
fmapfn w = \escEv clickOutsideEv -> fmap (\(cancelEv, outputEv) -> (leftmost [escEv, cancelEv, void outputEv], outputEv)) w
101+
(outputEv, stateDyn) <- popupPane def $ (fmap fmapfn popupSaveBeforeExitEv)
102+
return (uncurry SaveBeforeExitOutput (fanThese outputEv), stateDyn)

0 commit comments

Comments
 (0)