wxhnotepad 1.0.0 → 1.1.0
raw patch · 5 files changed
+57/−76 lines, 5 files
Files
- src/Step3.hs +19/−26
- src/Step4.hs +12/−16
- src/Step5.hs +13/−16
- src/Step6.hs +12/−17
- wxhnotepad.cabal +1/−1
src/Step3.hs view
@@ -7,7 +7,7 @@ data GUIContext = GUICtx { guiWin :: Frame (), guiEditor :: TextCtrl (), guiFile :: Var (Maybe FilePath),- guiTimer :: Var (TimerEx ()), -- ^ A timer to detect user actions+ guiTimer :: TimerEx (), -- ^ A timer to detect user actions guiPast :: Var [String], -- ^ For Undo history guiFuture :: Var [String] -- ^ For Redo history }@@ -43,15 +43,16 @@ -- We create a timer to detect user actions. This way we'll not undo/redo -- every character- refreshTimer <- timer win [interval := 1000000, -- 1000 secs. means a *lot* of time- on command := return ()] -- just start over- varTimer <- varCreate refreshTimer-+ refreshTimer <- timer win []+ -- We define the context to use it on every event handling function past <- varCreate [] future <- varCreate []- let guiCtx = GUICtx win editor filePath varTimer past future+ let guiCtx = GUICtx win editor filePath refreshTimer past future + -- We set the command associated to the timer (but we didn't start it yet)+ timerOnCommand refreshTimer $ updatePast guiCtx + -- We associate the events on the editor with commands that populate undo/redo history set editor [on keyboard := \_ -> restartTimer guiCtx >> propagateEvent] -- and we start populating the history because there's text on the editor...@@ -185,27 +186,19 @@ varSet past [] varSet future [] -restartTimer guiCtx@GUICtx{guiWin = win, guiTimer = varTimer} =- do- -- The user did something, we start a 1sec timer that will modify history+restartTimer guiCtx@GUICtx{guiWin = win, guiTimer = refreshTimer} =+ -- The user did something, we start our timer with a 1sec interval and+ -- a one-shot type so it will run just once and then it will modify history -- if the user doesn't do anything in that sec. If the user does another -- thing, then the timer will be restarted again and so on so far until -- the first sec of inactivity- -- Note by FernandoBenavides:- -- I really don't know if this can't be done with just one timer- -- I didn't find something like "timerRestart ..."- newRefreshTimer <- timer win [interval := 1000,- on command := updatePast guiCtx]- refreshTimer <- varSwap varTimer newRefreshTimer- timerOnCommand refreshTimer $ return ()--killTimer GUICtx{guiWin = win, guiTimer = varTimer} = do- -- We kill the timer till there's new notices- -- Note by FernandoBenavides:- -- I really don't know if this can't be done with just one timer- -- I didn't find something like "timerRestart ..."- newRefreshTimer <- timer win [interval := 1000000,- on command := return ()]- refreshTimer <- varSwap varTimer newRefreshTimer- timerOnCommand refreshTimer $ return ()+ started <- timerStart refreshTimer 1000 True+ if started+ then return ()+ else do+ errorDialog win "Error" "Can't start more timers"+ wxcAppExit++-- We kill the timer till there's new notices+killTimer GUICtx{guiTimer = refreshTimer} = timerStop refreshTimer
src/Step4.hs view
@@ -7,7 +7,7 @@ data GUIContext = GUICtx { guiWin :: Frame (), guiEditor :: TextCtrl (), guiFile :: Var (Maybe FilePath),- guiTimer :: Var (TimerEx ()),+ guiTimer :: TimerEx (), guiPast :: Var [String], guiFuture :: Var [String] }@@ -30,14 +30,13 @@ "Besides, we need to adapt our Undo/Redo " ++ "implementation to these functions.\n"] filePath <- varCreate Nothing- refreshTimer <- timer win [interval := 1000000,- on command := return ()]- varTimer <- varCreate refreshTimer+ refreshTimer <- timer win [] past <- varCreate [] future <- varCreate []- let guiCtx = GUICtx win editor filePath varTimer past future+ let guiCtx = GUICtx win editor filePath refreshTimer past future set editor [on keyboard := \_ -> restartTimer guiCtx >> propagateEvent]+ timerOnCommand refreshTimer $ updatePast guiCtx updatePast guiCtx -- We create a menu for the window with the same items from steps 2 & 3@@ -163,19 +162,16 @@ varSet past [] varSet future [] -restartTimer guiCtx@GUICtx{guiWin = win, guiTimer = varTimer} =+restartTimer guiCtx@GUICtx{guiWin = win, guiTimer = refreshTimer} = do- newRefreshTimer <- timer win [interval := 1000,- on command := updatePast guiCtx]- refreshTimer <- varSwap varTimer newRefreshTimer- timerOnCommand refreshTimer $ return ()+ started <- timerStart refreshTimer 1000 True+ if started+ then return ()+ else do+ errorDialog win "Error" "Can't start more timers"+ wxcAppExit -killTimer GUICtx{guiWin = win, guiTimer = varTimer} =- do- newRefreshTimer <- timer win [interval := 1000000,- on command := return ()]- refreshTimer <- varSwap varTimer newRefreshTimer- timerOnCommand refreshTimer $ return ()+killTimer GUICtx{guiTimer = refreshTimer} = timerStop refreshTimer -- We just copy the selected text copy GUICtx{guiEditor = editor} = textCtrlCopy editor
src/Step5.hs view
@@ -18,7 +18,7 @@ data GUIContext = GUICtx { guiWin :: Frame (), guiEditor :: TextCtrl (), guiFile :: Var (Maybe FilePath),- guiTimer :: Var (TimerEx ()),+ guiTimer :: TimerEx (), guiPast :: Var [String], guiFuture :: Var [String], guiSearch :: FindReplaceData () -- ^ Needed to hold the what the user is looking for@@ -50,17 +50,17 @@ "If you find it, please post it on the " ++ "wxhaskell-users mailing list :)"] filePath <- varCreate Nothing- refreshTimer <- timer win [interval := 1000000,- on command := return ()]- varTimer <- varCreate refreshTimer+ refreshTimer <- timer win []+ past <- varCreate [] future <- varCreate [] -- We create a FindReplaceData that will hold the information about the -- last search search <- findReplaceDataCreate wxFR_DOWN- let guiCtx = GUICtx win editor filePath varTimer past future search+ let guiCtx = GUICtx win editor filePath refreshTimer past future search set editor [on keyboard := \_ -> restartTimer guiCtx >> propagateEvent]+ timerOnCommand refreshTimer $ updatePast guiCtx updatePast guiCtx -- We create a menu for the window with the same items from previous steps@@ -196,19 +196,16 @@ varSet past [] varSet future [] -restartTimer guiCtx@GUICtx{guiWin = win, guiTimer = varTimer} =+restartTimer guiCtx@GUICtx{guiWin = win, guiTimer = refreshTimer} = do- newRefreshTimer <- timer win [interval := 1000,- on command := updatePast guiCtx]- refreshTimer <- varSwap varTimer newRefreshTimer- timerOnCommand refreshTimer $ return ()+ started <- timerStart refreshTimer 1000 True+ if started+ then return ()+ else do+ errorDialog win "Error" "Can't start more timers"+ wxcAppExit -killTimer GUICtx{guiWin = win, guiTimer = varTimer} =- do- newRefreshTimer <- timer win [interval := 1000000,- on command := return ()]- refreshTimer <- varSwap varTimer newRefreshTimer- timerOnCommand refreshTimer $ return ()+killTimer GUICtx{guiTimer = refreshTimer} = timerStop refreshTimer copy GUICtx{guiEditor = editor} = textCtrlCopy editor
src/Step6.hs view
@@ -18,7 +18,7 @@ data GUIContext = GUICtx { guiWin :: Frame (), guiEditor :: TextCtrl (), guiFile :: Var (Maybe FilePath),- guiTimer :: Var (TimerEx ()),+ guiTimer :: TimerEx (), guiPast :: Var [String], guiFuture :: Var [String], guiSearch :: FindReplaceData (),@@ -57,9 +57,7 @@ "your homework is to add smart things to " ++ "it, like a Line/Coulmn position marker."] filePath <- varCreate Nothing- refreshTimer <- timer win [interval := 1000000,- on command := return ()]- varTimer <- varCreate refreshTimer+ refreshTimer <- timer win [] past <- varCreate [] future <- varCreate [] search <- findReplaceDataCreate wxFR_DOWN@@ -69,7 +67,7 @@ -- The window statusbar is a list of status fields, we use just one set win [statusBar := [status]] - let guiCtx = GUICtx win editor filePath varTimer past future search status+ let guiCtx = GUICtx win editor filePath refreshTimer past future search status set editor [on keyboard := \_ -> restartTimer guiCtx >> propagateEvent, -- We associate the right click on the editor to a context menu launcher@@ -77,6 +75,7 @@ MouseRightDown _ _ -> contextMenu guiCtx _ -> propagateEvent] + timerOnCommand refreshTimer $ updatePast guiCtx updatePast guiCtx mnuFile <- menuPane [text := "File"]@@ -270,20 +269,16 @@ varSet past [] varSet future [] -restartTimer guiCtx@GUICtx{guiWin = win, guiTimer = varTimer, guiStatus = status} =+restartTimer guiCtx@GUICtx{guiWin = win, guiTimer = refreshTimer} = do- newRefreshTimer <- timer win [interval := 1000,- on command := updatePast guiCtx]- refreshTimer <- varSwap varTimer newRefreshTimer- timerOnCommand refreshTimer $ return ()- set status [text := ""]+ started <- timerStart refreshTimer 1000 True+ if started+ then return ()+ else do+ errorDialog win "Error" "Can't start more timers"+ wxcAppExit -killTimer GUICtx{guiWin = win, guiTimer = varTimer} =- do- newRefreshTimer <- timer win [interval := 1000000,- on command := return ()]- refreshTimer <- varSwap varTimer newRefreshTimer- timerOnCommand refreshTimer $ return ()+killTimer GUICtx{guiTimer = refreshTimer} = timerStop refreshTimer copy GUICtx{guiEditor = editor} = textCtrlCopy editor
wxhnotepad.cabal view
@@ -1,5 +1,5 @@ name: wxhnotepad-version: 1.0.0+version: 1.1.0 cabal-version: >=1.6 build-type: Custom license: BSD3