diff options
author | Joey Hess <joey@kitenet.net> | 2014-02-18 20:16:28 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-02-18 20:16:28 -0400 |
commit | 18fe5ebbb5aef07aa2ab5d621dd44b0788862a07 (patch) | |
tree | 4b8fd66d51850b86a7dd8b623c78c4428a16f5c4 /Command | |
parent | 5ec224d48f28bb8823d898ecc10a9c376a41245b (diff) |
add vcycle command
Diffstat (limited to 'Command')
-rw-r--r-- | Command/VCycle.hs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Command/VCycle.hs b/Command/VCycle.hs new file mode 100644 index 000000000..c32ce2eb1 --- /dev/null +++ b/Command/VCycle.hs @@ -0,0 +1,45 @@ +{- git-annex command + - + - Copyright 2014 Joey Hess <joey@kitenet.net> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +module Command.VCycle where + +import Common.Annex +import Command +import Annex.View +import Types.View +import Logs.View +import Command.View (checkoutViewBranch) + +def :: [Command] +def = [notBareRepo $ notDirect $ + command "vcycle" paramNothing seek SectionUtility + "switch view to next layout"] + +seek :: CommandSeek +seek = withNothing start + +start ::CommandStart +start = go =<< currentView + where + go Nothing = error "Not in a view." + go (Just v) = do + let v' = v { viewComponents = vcycle [] (viewComponents v) } + if v == v' + then do + showNote "unchanged" + next $ next $ return True + else next $ perform v' + + vcycle rest (c:cs) + | multiValue (viewFilter c) = rest ++ cs ++ [c] + | otherwise = vcycle (c:rest) cs + vcycle rest c = rest ++ c + +perform :: View -> CommandPerform +perform view = do + branch <- narrowView view + next $ checkoutViewBranch view branch |