packageNew' :: FilePath -> C.Sink ToolOutput IDEM () -> (Bool -> FilePath -> IDEAction) -> IDEAction
packageNew' workspaceDir log activateAction = do
    windows  <- getWindows
    mbNewPackage <- liftIO $ newPackageDialog (head windows) workspaceDir
    case mbNewPackage of
        Nothing -> return ()
        Just NewPackage{..} | templatePackage == Nothing -> do
            let dirName = newPackageParentDir </> T.unpack newPackageName
            mbCabalFile <-  liftIO $ cabalFileName dirName
            window <- getMainWindow
            case mbCabalFile of
                Just cfn -> do
                    add <- liftIO $ do
                        md <- messageDialogNew (Just window) [] MessageQuestion ButtonsCancel
                             (T.pack $ printf (__
                              "There is already file %s in this directory. Would you like to add this package to the workspace?")
                              (takeFileName cfn))
                        dialogAddButton md (__ "_Add Package") (ResponseUser 1)
                        dialogSetDefaultResponse md (ResponseUser 1)
                        set md [ windowWindowPosition := WinPosCenterOnParent ]
                        rid <- dialogRun md
                        widgetDestroy md
                        return $ rid == ResponseUser 1
                    when add $ activateAction False cfn
                Nothing -> do
                    liftIO $ createDirectoryIfMissing True dirName
                    isEmptyDir <- liftIO $ isEmptyDirectory dirName
                    make <- if isEmptyDir
                        then return True
                        else liftIO $ do
                            md <- messageDialogNew (Just window) [] MessageQuestion ButtonsCancel
                                 (T.pack $ printf (__
                                  "The path you have choosen %s is not an empty directory. Are you sure you want to make a new package here?")
                                  dirName)
                            dialogAddButton md (__ "_Make Package Here") (ResponseUser 1)
                            dialogSetDefaultResponse md (ResponseUser 1)
                            set md [ windowWindowPosition := WinPosCenterOnParent ]
                            rid <- dialogRun md
                            widgetDestroy md
                            return $ rid == ResponseUser 1
                    when make $ do
                        modules <- liftIO $ allModules dirName
                        let Just initialVersion = simpleParse "0.0.1"
                        editPackage emptyPackageDescription {
                            package   = PackageIdentifier (PackageName $ T.unpack newPackageName)
                                                          initialVersion
                          , buildType = Just Simple
                          , specVersionRaw = Right (orLaterVersion (Version [1,12] []))
                          , license = AllRightsReserved
                          , executables = [emptyExecutable {
                                exeName    = T.unpack newPackageName
                              , modulePath = "Main.hs"
                              , buildInfo  = emptyBuildInfo {
                                    hsSourceDirs    = ["src"]
                                  , targetBuildDepends = [Dependency (PackageName "base") anyVersion]
                                  , defaultLanguage = Just Haskell2010}}]
                          , testSuites = [emptyTestSuite {
                                    testName = "test-" ++ T.unpack newPackageName
                                  , testInterface = (TestSuiteExeV10 (Version [1,0] []) "Main.hs")
                                  , testBuildInfo = emptyBuildInfo {
                                        hsSourceDirs    = ["test"]
                                      , targetBuildDepends = [
                                            Dependency (PackageName "base") anyVersion
                                          , Dependency (PackageName "QuickCheck") anyVersion
                                          , Dependency (PackageName "doctest") anyVersion]
                                      , defaultLanguage = Just Haskell2010}}]
                          , benchmarks =  []
                          } dirName modules (activateAction True)
                    return ()
        Just NewPackage{..} -> cabalUnpack newPackageParentDir (fromJust templatePackage) False (Just newPackageName) log (activateAction False)
packageNew' :: FilePath -> C.Sink ToolOutput IDEM () -> (Bool -> FilePath -> IDEAction) -> IDEAction
packageNew' workspaceDir log activateAction = do
    windows  <- getWindows
    mbNewPackage <- liftIO $ newPackageDialog (head windows) workspaceDir
    case mbNewPackage of
        Nothing -> return ()
        Just NewPackage{..} | templatePackage == Nothing -> do
            let dirName = newPackageParentDir </> T.unpack newPackageName
            mbCabalFile <-  liftIO $ cabalFileName dirName
            window <- getMainWindow
            case mbCabalFile of
                Just cfn -> do
                    add <- liftIO $ do
                        md <- messageDialogNew (Just window) [] MessageQuestion ButtonsCancel
                             (T.pack $ printf (__
                              "There is already file %s in this directory. Would you like to add this package to the workspace?")
                              (takeFileName cfn))
                        dialogAddButton md (__ "_Add Package") (ResponseUser 1)
                        dialogSetDefaultResponse md (ResponseUser 1)
                        set md [ windowWindowPosition := WinPosCenterOnParent ]
                        rid <- dialogRun md
                        widgetDestroy md
                        return $ rid == ResponseUser 1
                    when add $ activateAction False cfn
                Nothing -> do
                    liftIO $ createDirectoryIfMissing True dirName
                    isEmptyDir <- liftIO $ isEmptyDirectory dirName
                    make <- if isEmptyDir
                        then return True
                        else liftIO $ do
                            md <- messageDialogNew (Just window) [] MessageQuestion ButtonsCancel
                                 (T.pack $ printf (__
                                  "The path you have choosen %s is not an empty directory. Are you sure you want to make a new package here?")
                                  dirName)
                            dialogAddButton md (__ "_Make Package Here") (ResponseUser 1)
                            dialogSetDefaultResponse md (ResponseUser 1)
                            set md [ windowWindowPosition := WinPosCenterOnParent ]
                            rid <- dialogRun md
                            widgetDestroy md
                            return $ rid == ResponseUser 1
                    when make $ do
                        modules <- liftIO $ allModules dirName
                        let Just initialVersion = simpleParse "0.0.1"
                        editPackage emptyPackageDescription {
                            package   = PackageIdentifier (PackageName $ T.unpack newPackageName)
                                                          initialVersion
                          , buildType = Just Simple
                          , specVersionRaw = Right (orLaterVersion (Version [1,12] []))
                          , license = AllRightsReserved
                          , executables = [emptyExecutable {
                                exeName    = T.unpack newPackageName
                              , modulePath = "Main.hs"
                              , buildInfo  = emptyBuildInfo {
                                    hsSourceDirs    = ["src"]
                                  , targetBuildDepends = [Dependency (PackageName "base") anyVersion]
                                  , defaultLanguage = Just Haskell2010}}]
                          , testSuites = [emptyTestSuite {
                                    testName = "test-" ++ T.unpack newPackageName
                                  , testInterface = (TestSuiteExeV10 (Version [1,0] []) "Main.hs")
                                  , testBuildInfo = emptyBuildInfo {
                                        hsSourceDirs    = ["test"]
                                      , targetBuildDepends = [
                                            Dependency (PackageName "base") anyVersion
                                          , Dependency (PackageName "QuickCheck") anyVersion
                                          , Dependency (PackageName "doctest") anyVersion]
                                      , defaultLanguage = Just Haskell2010}}]
                          , benchmarks =  []
                          } dirName modules (activateAction True)
                    return ()
        Just NewPackage{..} -> cabalUnpack newPackageParentDir (fromJust templatePackage) False (Just newPackageName) log (activateAction False)
packageNew' workspaceDir log activateAction = do
    windows  <- getWindows
    mbNewPackage <- liftIO $ newPackageDialog (head windows) workspaceDir
    case mbNewPackage of
        Nothing -> return ()
        Just NewPackage{..} | templatePackage == Nothing -> do
            let dirName = newPackageParentDir </> T.unpack newPackageName
            mbCabalFile <-  liftIO $ cabalFileName dirName
            window <- getMainWindow
            case mbCabalFile of
                Just cfn -> do
                    add <- liftIO $ do
                        md <- messageDialogNew (Just window) [] MessageQuestion ButtonsCancel
                             (T.pack $ printf (__
                              "There is already file %s in this directory. Would you like to add this package to the workspace?")
                              (takeFileName cfn))
                        dialogAddButton md (__ "_Add Package") (ResponseUser 1)
                        dialogSetDefaultResponse md (ResponseUser 1)
                        set md [ windowWindowPosition := WinPosCenterOnParent ]
                        rid <- dialogRun md
                        widgetDestroy md
                        return $ rid == ResponseUser 1
                    when add $ activateAction False cfn
                Nothing -> do
                    liftIO $ createDirectoryIfMissing True dirName
                    isEmptyDir <- liftIO $ isEmptyDirectory dirName
                    make <- if isEmptyDir
                        then return True
                        else liftIO $ do
                            md <- messageDialogNew (Just window) [] MessageQuestion ButtonsCancel
                                 (T.pack $ printf (__
                                  "The path you have choosen %s is not an empty directory. Are you sure you want to make a new package here?")
                                  dirName)
                            dialogAddButton md (__ "_Make Package Here") (ResponseUser 1)
                            dialogSetDefaultResponse md (ResponseUser 1)
                            set md [ windowWindowPosition := WinPosCenterOnParent ]
                            rid <- dialogRun md
                            widgetDestroy md
                            return $ rid == ResponseUser 1
                    when make $ do
                        modules <- liftIO $ allModules dirName
                        let Just initialVersion = simpleParse "0.0.1"
                        editPackage emptyPackageDescription {
                            package   = PackageIdentifier (PackageName $ T.unpack newPackageName)
                                                          initialVersion
                          , buildType = Just Simple
                          , specVersionRaw = Right (orLaterVersion (Version [1,12] []))
                          , license = AllRightsReserved
                          , executables = [emptyExecutable {
                                exeName    = T.unpack newPackageName
                              , modulePath = "Main.hs"
                              , buildInfo  = emptyBuildInfo {
                                    hsSourceDirs    = ["src"]
                                  , targetBuildDepends = [Dependency (PackageName "base") anyVersion]
                                  , defaultLanguage = Just Haskell2010}}]
                          , testSuites = [emptyTestSuite {
                                    testName = "test-" ++ T.unpack newPackageName
                                  , testInterface = (TestSuiteExeV10 (Version [1,0] []) "Main.hs")
                                  , testBuildInfo = emptyBuildInfo {
                                        hsSourceDirs    = ["test"]
                                      , targetBuildDepends = [
                                            Dependency (PackageName "base") anyVersion
                                          , Dependency (PackageName "QuickCheck") anyVersion
                                          , Dependency (PackageName "doctest") anyVersion]
                                      , defaultLanguage = Just Haskell2010}}]
                          , benchmarks =  []
                          } dirName modules (activateAction True)
                    return ()
        Just NewPackage{..} -> cabalUnpack newPackageParentDir (fromJust templatePackage) False (Just newPackageName) log (activateAction False)