From e3a455fc3791539275fdb6aff003ffa8460f8850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Thu, 5 Sep 2013 20:34:56 -0300 Subject: rename scrolling functions --- src/Lazymail/Handlers.hs | 69 +++++++++++++++++++++++++++++++++++++++--------- src/Lazymail/Screen.hs | 8 +++--- src/Lazymail/State.hs | 45 ------------------------------- 3 files changed, 61 insertions(+), 61 deletions(-) (limited to 'src') diff --git a/src/Lazymail/Handlers.hs b/src/Lazymail/Handlers.hs index b0b1165..bd1d27a 100644 --- a/src/Lazymail/Handlers.hs +++ b/src/Lazymail/Handlers.hs @@ -84,7 +84,7 @@ changeMode MaildirMode = do freeOldHandlers st = mapM (hClose . emailHandle) $ selectedEmails . indexState $ st {- Boilerplate code -} -incSelectedRow IndexMode = do +scrollDown IndexMode = do st <- get let inSt = indexState st let selRow = selectedRowIn inSt @@ -101,7 +101,7 @@ incSelectedRow IndexMode = do else -- Move the selected row put $ incrementSelectedRow st -incSelectedRow MaildirMode = do +scrollDown MaildirMode = do st <- get let mdSt = maildirState st let selRow = selectedRowMD mdSt @@ -119,7 +119,7 @@ incSelectedRow MaildirMode = do put $ incrementSelectedRow st {- Down-scrolling in Email mode -} -incSelectedRow EmailMode = do +scrollDown EmailMode = do st <- get let est = emailState st let cur = scrollRowEm est @@ -130,10 +130,10 @@ incSelectedRow EmailMode = do when ((totalRows - scrRows + (bodyStartRow est) - 1) > (scrollRowEm est)) $ put $ st { emailState = est' } -incSelectedRow _ = (=<<) put $ get >>= \st -> return $ incrementSelectedRow st +scrollDown _ = (=<<) put $ get >>= \st -> return $ incrementSelectedRow st {- More boilerplate code -} -decSelectedRow IndexMode = do +scrollUp IndexMode = do st <- get let inSt = indexState st let selRow = selectedRowIn inSt @@ -148,7 +148,7 @@ decSelectedRow IndexMode = do else put $ decrementSelectedRow st -decSelectedRow MaildirMode = do +scrollUp MaildirMode = do st <- get let mdSt = maildirState st let selRow = selectedRowMD mdSt @@ -163,7 +163,7 @@ decSelectedRow MaildirMode = do else put $ decrementSelectedRow st -decSelectedRow EmailMode = do +scrollUp EmailMode = do st <- get let est = emailState st let cur = scrollRowEm est @@ -174,7 +174,52 @@ decSelectedRow EmailMode = do when (cur > 0) $ put $ st { emailState = est' } -decSelectedRow _ = (=<<) put $ get >>= \st -> return $ decrementSelectedRow st +scrollUp _ = (=<<) put $ get >>= \st -> return $ decrementSelectedRow st + +incrementSelectedRow st | (selectedRow st) < limit = + case (mode st) of + MaildirMode -> + let + sr = (selectedRowMD . maildirState) st + maildirState' = (maildirState st) { selectedRowMD = sr + 1 } + in + st { maildirState = maildirState' } + IndexMode -> + let + sr = (selectedRowIn . indexState) st + indexState' = (indexState st) { selectedRowIn = sr + 1 } + in + st { indexState = indexState' } + _ -> st + | otherwise = st + where + scrRows = screenRows st + curInLen = length $ selectedEmails . indexState $ st + curMDLen = length $ detectedMDs . maildirState $ st + limit' = case (mode st) of + MaildirMode -> if curMDLen < scrRows then curMDLen - 1 else scrRows + IndexMode -> if curInLen < scrRows then curInLen - 1 else scrRows + limit = if (statusBar st) && (limit' == scrRows) + then fromIntegral $ limit' - 2 + else fromIntegral limit' + +decrementSelectedRow st | (selectedRow st) > 0 = + case (mode st) of + MaildirMode -> + let + sr = (selectedRowMD . maildirState) st + maildirState' = (maildirState st) { selectedRowMD = sr - 1 } + in + st { maildirState = maildirState' } + IndexMode -> + let + sr = (selectedRowIn . indexState) st + indexState' = (indexState st) { selectedRowIn = sr - 1 } + in + st { indexState = indexState' } + _ -> st + | otherwise = st + {- Given a list, it returns the elements that will be in the next screen refresh - TODO: find a better name -} @@ -211,19 +256,19 @@ triggerIndexUpdate = do st <- get let ist = indexState st put $ st { indexState = (ist { triggerUpdateIn = True }) } - + solveIndexUpdate :: LazymailCurses () solveIndexUpdate = do st <- get let ist = indexState st - put $ st { indexState = (ist { triggerUpdateIn = False }) } - + put $ st { indexState = (ist { triggerUpdateIn = False }) } + triggerMaildirUpdate :: LazymailCurses () triggerMaildirUpdate = do st <- get let mst = maildirState st put $ st { maildirState = (mst { triggerUpdateMD = True }) } - + solveMaildirUpdate :: LazymailCurses () solveMaildirUpdate = do st <- get diff --git a/src/Lazymail/Screen.hs b/src/Lazymail/Screen.hs index 699f84e..d6937dd 100644 --- a/src/Lazymail/Screen.hs +++ b/src/Lazymail/Screen.hs @@ -231,11 +231,11 @@ handleEvent = loop where case ev' of EventCharacter 'q' -> EH.previousMode (mode st) - EventSpecialKey KeyUpArrow -> EH.decSelectedRow (mode st) - EventCharacter 'k' -> EH.decSelectedRow (mode st) + EventSpecialKey KeyUpArrow -> EH.scrollUp (mode st) + EventCharacter 'k' -> EH.scrollUp (mode st) - EventSpecialKey KeyDownArrow -> EH.incSelectedRow (mode st) - EventCharacter 'j' -> EH.incSelectedRow (mode st) + EventSpecialKey KeyDownArrow -> EH.scrollDown (mode st) + EventCharacter 'j' -> EH.scrollDown (mode st) EventCharacter '\n' -> EH.changeMode (mode st) EventSpecialKey KeyRightArrow -> EH.changeMode (mode st) diff --git a/src/Lazymail/State.hs b/src/Lazymail/State.hs index 06353da..1323118 100644 --- a/src/Lazymail/State.hs +++ b/src/Lazymail/State.hs @@ -75,51 +75,6 @@ scrRowsAsInteger st = toInteger $ screenRows st curRowAsInteger st = toInteger $ currentRow st colPadAsInteger st = toInteger $ columnPadding st - -incrementSelectedRow st | (selectedRow st) < limit = - case (mode st) of - MaildirMode -> - let - sr = (selectedRowMD . maildirState) st - maildirState' = (maildirState st) { selectedRowMD = sr + 1 } - in - st { maildirState = maildirState' } - IndexMode -> - let - sr = (selectedRowIn . indexState) st - indexState' = (indexState st) { selectedRowIn = sr + 1 } - in - st { indexState = indexState' } - _ -> st - | otherwise = st - where - scrRows = screenRows st - curInLen = length $ selectedEmails . indexState $ st - curMDLen = length $ detectedMDs . maildirState $ st - limit' = case (mode st) of - MaildirMode -> if curMDLen < scrRows then curMDLen - 1 else scrRows - IndexMode -> if curInLen < scrRows then curInLen - 1 else scrRows - limit = if (statusBar st) && (limit' == scrRows) - then fromIntegral $ limit' - 2 - else fromIntegral limit' - -decrementSelectedRow st | (selectedRow st) > 0 = - case (mode st) of - MaildirMode -> - let - sr = (selectedRowMD . maildirState) st - maildirState' = (maildirState st) { selectedRowMD = sr - 1 } - in - st { maildirState = maildirState' } - IndexMode -> - let - sr = (selectedRowIn . indexState) st - indexState' = (indexState st) { selectedRowIn = sr - 1 } - in - st { indexState = indexState' } - _ -> st - | otherwise = st - selectedRow st = case (mode st) of MaildirMode -> selectedRowMD . maildirState $ st IndexMode -> selectedRowIn . indexState $ st -- cgit v1.2.3