trim long filenames (have to fit on the sidebar)

30 characters would mostly work, but 20 is safer due to some wider letters
like 'w'. Of course this is very heuristic based on filesize anyway.

(Bootstrap does a surprisingly bad job at dealing with overlong words
in the sidebar.)
This commit is contained in:
Joey Hess 2012-08-02 09:15:08 -04:00
parent 520a0463a7
commit 1f2127c520

View file

@ -247,11 +247,18 @@ sanityCheckFixAlert msg = Alert
combinemessage _ _ = Nothing
addFileAlert :: FilePath -> Alert
addFileAlert file = (activityAlert (Just "Added") $ takeFileName file)
addFileAlert file = (activityAlert (Just "Added") $ trim $ takeFileName file)
{ alertName = Just AddFileAlert
, alertCombiner = messageCombiner combinemessage
}
where
trim f
| len < maxlen = f
| otherwise = take half f ++ ".." ++ drop (len - half) f
where
len = length f
maxlen = 20
half = (maxlen - 2) `div` 2
combinemessage (StringAlert new) (StringAlert old) =
Just $ StringAlert $
unlines $ take 10 $ new : lines old