package com.haskforce;

import com.intellij.ide.util.projectWizard.JavaModuleBuilder;
import com.intellij.ide.util.projectWizard.ModuleBuilderListener;
import com.intellij.ide.util.projectWizard.SourcePathsBuilder;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.projectRoots.SdkTypeId;
import com.intellij.openapi.roots.ModifiableRootModel;
import org.jetbrains.annotations.NotNull;

public class HaskellModuleBuilder extends JavaModuleBuilder implements SourcePathsBuilder, ModuleBuilderListener {
    @Override
    public void setupRootModel(ModifiableRootModel rootModel) throws ConfigurationException {
        addListener(this);
        super.setupRootModel(rootModel);
    }

    @Override
    public ModuleType getModuleType() {
        return HaskellModuleType.getInstance();
    }

    @Override
    public boolean isSuitableSdkType(SdkTypeId sdkType) {
        return sdkType == HaskellSdkType.getInstance();
    }

    @Override
    public void moduleCreated(@NotNull Module module) {
        // TODO
    }
}

@@ -188,34 +188,210 @@
 tWizard.
-SourcePathsBuilder
+ModuleWizardStep;%0Aimport com.intellij.ide.util.projectWizard.SettingsStep;%0Aimport com.intellij.ide.util.projectWizard.SourcePathsBuilder;%0Aimport com.intellij.ide.util.projectWizard.WizardContext
 ;%0Aimport
@@ -652,41 +652,134 @@
 ort 
-org.jetbrains.annotations.NotNull
+com.intellij.openapi.util.text.StringUtil;%0Aimport org.jetbrains.annotations.NotNull;%0Aimport org.jetbrains.annotations.Nullable
 ;%0A%0Ap
@@ -1067,32 +1067,88 @@
 tModel);%0A    %7D%0A%0A
+    /**%0A     * Returns the Haskell module type.%0A     */%0A
     @Override%0A  
@@ -1232,32 +1232,95 @@
 tance();%0A    %7D%0A%0A
+    /**%0A     * Ensures that SDK type is a Haskell SDK.%0A     */%0A
     @Override%0A  
@@ -1434,24 +1434,79 @@
 e();%0A    %7D%0A%0A
+    /**%0A     * Called after module is created.%0A     */%0A
     @Overrid
@@ -1584,11 +1584,698 @@
 DO%0A    %7D
+%0A%0A    /**%0A     * Hook into the new project creation and set dist to the compiler output%0A     * directory.%0A     */%0A    @Override%0A    @Nullable%0A    public ModuleWizardStep modifySettingsStep(@NotNull SettingsStep settingsStep) %7B%0A        if (settingsStep.getContext().isCreatingNewProject() &&%0A                settingsStep.getContext().isProjectFileDirectorySet()) %7B%0A            WizardContext c = settingsStep.getContext();%0A            String path = c.getProjectFileDirectory();%0A            String out = StringUtil.endsWithChar(path, '/') ? path + %22dist%22 : path + %22/dist%22;%0A            c.setCompilerOutputDirectory(out);%0A        %7D%0A        return super.modifySettingsStep(settingsStep);%0A    %7D
 %0A%7D%0A

Set "dist" to the compiler output directory.