Make template name for creating new project configurable. Fix #448

This commit is contained in:
Rik van der Kleij 2019-07-16 21:54:09 +02:00
parent 9349a852ea
commit 9698c9d1d4
4 changed files with 16 additions and 3 deletions

View File

@ -37,6 +37,7 @@ import intellij.haskell.cabal.CabalInfo
import intellij.haskell.external.component.{HaskellComponentsManager, PackageInfo}
import intellij.haskell.external.execution.{CommandLine, StackCommandLine}
import intellij.haskell.sdk.HaskellSdkType
import intellij.haskell.settings.HaskellSettingsState
import intellij.haskell.stackyaml.StackYamlComponent
import intellij.haskell.util.{HaskellFileUtil, HaskellProjectUtil, ScalaUtil}
import intellij.haskell.{GlobalInfo, HaskellNotificationGroup}
@ -105,15 +106,16 @@ class HaskellModuleBuilder extends TemplateModuleBuilder(null, HaskellModuleType
val moduleType = getModuleType
val module = moduleModel.newModule(getModuleFilePath, moduleType.getId)
val project = module.getProject
val newProjectTemplateName = HaskellSettingsState.getNewProjectTemplateName
if (isNewProjectWithoutExistingSources) {
val processOutput = StackCommandLine.run(project, Seq("new", project.getName, "--bare", "new-template", "-p", "author-email:Author email here", "-p", "author-name:Author name here", "-p", "category:App category here", "-p", "copyright:2019 Author name here", "-p", "github-username:Github username here"), timeoutInMillis = 60.seconds.toMillis, enableExtraArguments = false)
val processOutput = StackCommandLine.run(project, Seq("new", project.getName, "--bare", newProjectTemplateName, "-p", "author-email:Author email here", "-p", "author-name:Author name here", "-p", "category:App category here", "-p", "copyright:2019 Author name here", "-p", "github-username:Github username here"), timeoutInMillis = 60.seconds.toMillis, enableExtraArguments = false)
processOutput match {
case None =>
throw new RuntimeException("Couldn't create new Stack project due to failure executing Stack command for creating new project on file system")
HaskellNotificationGroup.logErrorBalloonEvent("Couldn't create new Stack project due to failure executing Stack command for creating new project on file system")
case Some(output) =>
if (output.getExitCode != 0) {
throw new RuntimeException(s"Couldn't create new Stack project: ${output.getStdout} ${output.getStderr}")
HaskellNotificationGroup.logErrorBalloonEvent(s"Couldn't create new Stack project: ${output.getStdout} ${output.getStderr}")
}
}
}

View File

@ -28,6 +28,7 @@ class HaskellConfigurable extends Configurable {
private val hlintOptionsField = new JTextField
private val replTimeoutField = new JTextField
private val replTimeoutLabel = new JLabel("Changed timeout will take effect after restarting project")
private val newProjectTemplateNameField = new JTextField
override def getDisplayName: String = {
"Haskell"
@ -48,6 +49,7 @@ class HaskellConfigurable extends Configurable {
hlintOptionsField.getDocument.addDocumentListener(listener)
replTimeoutField.getDocument.addDocumentListener(listener)
newProjectTemplateNameField.getDocument.addDocumentListener(listener)
class SettingsGridBagConstraints extends GridBagConstraints {
@ -89,6 +91,7 @@ class HaskellConfigurable extends Configurable {
addLabeledControl(1, HlintOptions, hlintOptionsField)
addLabeledControl(2, ReplTimeout, replTimeoutField)
addLabeledControl(3, "", replTimeoutLabel)
addLabeledControl(4, NewProjectTemplateName, newProjectTemplateNameField)
settingsPanel.add(new JPanel(), baseGridBagConstraints.setConstraints(
gridx = 0,
@ -104,6 +107,7 @@ class HaskellConfigurable extends Configurable {
val state = HaskellSettingsPersistentStateComponent.getInstance().getState
state.replTimeout = validREPLTimeout
state.hlintOptions = hlintOptionsField.getText
state.newProjectTemplateName = newProjectTemplateNameField.getText
}
private def validateREPLTimeout(): Integer = {
@ -127,10 +131,12 @@ class HaskellConfigurable extends Configurable {
val state = HaskellSettingsPersistentStateComponent.getInstance().getState
hlintOptionsField.setText(state.hlintOptions)
replTimeoutField.setText(state.replTimeout.toString)
newProjectTemplateNameField.setText(state.newProjectTemplateName)
}
}
object HaskellConfigurable {
final val ReplTimeout = "Background REPL timeout in seconds"
final val HlintOptions = "Hlint options"
final val NewProjectTemplateName = "Template name for new project"
}

View File

@ -52,5 +52,6 @@ public class HaskellSettingsPersistentStateComponent implements PersistentStateC
public String hlintOptions = "";
public Boolean reformatCodeBeforeCommit = false;
public Boolean optimizeImportsBeforeCommit = false;
public String newProjectTemplateName = "new-template";
}
}

View File

@ -27,6 +27,10 @@ object HaskellSettingsState {
state.hlintOptions
}
def getNewProjectTemplateName: String = {
state.newProjectTemplateName
}
def isReformatCodeBeforeCommit: Boolean = {
state.reformatCodeBeforeCommit
}