only use smart default on first run

This commit is contained in:
Joey Hess 2012-07-31 21:34:29 -04:00
parent b9afb7785e
commit 1efe4f3332

View file

@ -96,15 +96,15 @@ checkRepositoryPath p = do
expandTilde home ('~':path) = home </> path expandTilde home ('~':path) = home </> path
expandTilde _ path = path expandTilde _ path = path
{- If run in the home directory, default to putting it in ~/Desktop/annex, {- On first run, if run in the home directory, default to putting it in
- when a Desktop directory exists, and ~/annex otherwise. - ~/Desktop/annex, when a Desktop directory exists, and ~/annex otherwise.
- -
- If run in another directory, the user probably wants to put it there. -} - If run in another directory, the user probably wants to put it there. -}
defaultRepositoryPath :: IO FilePath defaultRepositoryPath :: Bool -> IO FilePath
defaultRepositoryPath = do defaultRepositoryPath firstrun = do
cwd <- liftIO $ getCurrentDirectory cwd <- liftIO $ getCurrentDirectory
home <- myHomeDir home <- myHomeDir
if home == cwd if home == cwd && firstRun
then ifM (doesDirectoryExist $ home </> "Desktop") then ifM (doesDirectoryExist $ home </> "Desktop")
(return "~/Desktop/annex", return "~/annex") (return "~/Desktop/annex", return "~/annex")
else return cwd else return cwd
@ -112,7 +112,7 @@ defaultRepositoryPath = do
addRepositoryForm :: Form RepositoryPath addRepositoryForm :: Form RepositoryPath
addRepositoryForm msg = do addRepositoryForm msg = do
path <- T.pack . addTrailingPathSeparator path <- T.pack . addTrailingPathSeparator
<$> liftIO defaultRepositoryPath <$> liftIO defaultRepositoryPath =<< lift inFirstRun
(pathRes, pathView) <- mreq (repositoryPathField True) ""(Just path) (pathRes, pathView) <- mreq (repositoryPathField True) ""(Just path)
let (err, errmsg) = case pathRes of let (err, errmsg) = case pathRes of
FormMissing -> (False, "") FormMissing -> (False, "")