aboutsummaryrefslogtreecommitdiff
path: root/Command/VCycle.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-02-18 20:16:28 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-02-18 20:16:28 -0400
commit18fe5ebbb5aef07aa2ab5d621dd44b0788862a07 (patch)
tree4b8fd66d51850b86a7dd8b623c78c4428a16f5c4 /Command/VCycle.hs
parent5ec224d48f28bb8823d898ecc10a9c376a41245b (diff)
add vcycle command
Diffstat (limited to 'Command/VCycle.hs')
-rw-r--r--Command/VCycle.hs45
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