diff --git a/idea/resources/fileTemplates/internal/Kotlin Script.kts.ft b/idea/resources/fileTemplates/internal/Kotlin Script.kts.ft
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/idea/resources/fileTemplates/internal/Kotlin Script.kts.html b/idea/resources/fileTemplates/internal/Kotlin Script.kts.html
new file mode 100644
index 00000000000..4fb996c3e5d
--- /dev/null
+++ b/idea/resources/fileTemplates/internal/Kotlin Script.kts.html
@@ -0,0 +1,14 @@
+
+
+
+
+ |
+
+ This is a built-in template used by IDEA each time you create a
+ Kotlin script
+
+ |
+
+
+
+
\ No newline at end of file
diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml
index 615d649fee4..c96669475fd 100644
--- a/idea/src/META-INF/plugin.xml
+++ b/idea/src/META-INF/plugin.xml
@@ -79,6 +79,9 @@
+
+
+
@@ -352,6 +355,7 @@
+
diff --git a/idea/src/META-INF/plugin.xml.172 b/idea/src/META-INF/plugin.xml.172
index 52de155e6e3..b88f001c5df 100644
--- a/idea/src/META-INF/plugin.xml.172
+++ b/idea/src/META-INF/plugin.xml.172
@@ -79,6 +79,9 @@
+
+
+
diff --git a/idea/src/META-INF/plugin.xml.181 b/idea/src/META-INF/plugin.xml.181
index b76c7b42b65..8308eceb8b2 100644
--- a/idea/src/META-INF/plugin.xml.181
+++ b/idea/src/META-INF/plugin.xml.181
@@ -79,6 +79,9 @@
+
+
+
diff --git a/idea/src/META-INF/plugin.xml.182 b/idea/src/META-INF/plugin.xml.182
index 2f4b30d5e1e..d2eb34e511a 100644
--- a/idea/src/META-INF/plugin.xml.182
+++ b/idea/src/META-INF/plugin.xml.182
@@ -80,6 +80,9 @@
+
+
+
diff --git a/idea/src/META-INF/plugin.xml.as31 b/idea/src/META-INF/plugin.xml.as31
index ca1958bec0c..39f652ecdd1 100644
--- a/idea/src/META-INF/plugin.xml.as31
+++ b/idea/src/META-INF/plugin.xml.as31
@@ -79,6 +79,9 @@
+
+
+
diff --git a/idea/src/META-INF/plugin.xml.as32 b/idea/src/META-INF/plugin.xml.as32
index 3c7332c2128..42ef909fd71 100644
--- a/idea/src/META-INF/plugin.xml.as32
+++ b/idea/src/META-INF/plugin.xml.as32
@@ -79,6 +79,9 @@
+
+
+
diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/NewKotlinFileAction.kt b/idea/src/org/jetbrains/kotlin/idea/actions/NewKotlinFileAction.kt
index 4306a78bec8..c95a18eca02 100644
--- a/idea/src/org/jetbrains/kotlin/idea/actions/NewKotlinFileAction.kt
+++ b/idea/src/org/jetbrains/kotlin/idea/actions/NewKotlinFileAction.kt
@@ -115,7 +115,7 @@ class NewKotlinFileAction
companion object {
private fun findOrCreateTarget(dir: PsiDirectory, name: String, directorySeparators: Array): Pair {
- var className = name.removeSuffix(".kt")
+ var className = name.substringBeforeLast(".kt")
var targetDir = dir
for (splitChar in directorySeparators) {
diff --git a/idea/src/org/jetbrains/kotlin/idea/actions/NewKotlinScriptAction.kt b/idea/src/org/jetbrains/kotlin/idea/actions/NewKotlinScriptAction.kt
new file mode 100644
index 00000000000..374a3290e10
--- /dev/null
+++ b/idea/src/org/jetbrains/kotlin/idea/actions/NewKotlinScriptAction.kt
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
+ * that can be found in the license/LICENSE.txt file.
+ */
+
+package org.jetbrains.kotlin.idea.actions
+
+import com.intellij.ide.actions.CreateFileFromTemplateAction
+import com.intellij.ide.actions.CreateFileFromTemplateDialog
+import com.intellij.ide.fileTemplates.FileTemplate
+import com.intellij.openapi.module.ModuleUtilCore
+import com.intellij.openapi.project.DumbAware
+import com.intellij.openapi.project.Project
+import com.intellij.psi.PsiDirectory
+import com.intellij.psi.PsiFile
+import org.jetbrains.kotlin.idea.KotlinFileType
+import org.jetbrains.kotlin.psi.KtFile
+
+class NewKotlinScriptAction : CreateFileFromTemplateAction(
+ "Kotlin Script",
+ "Creates new Kotlin script",
+ KotlinFileType.INSTANCE.icon
+), DumbAware {
+
+ override fun postProcess(createdElement: PsiFile, templateName: String?, customProperties: Map?) {
+ super.postProcess(createdElement, templateName, customProperties)
+
+ val module = ModuleUtilCore.findModuleForPsiElement(createdElement)
+
+ if (createdElement is KtFile && module != null) {
+ NewKotlinFileHook.EP_NAME.extensions.forEach { it.postProcess(createdElement, module) }
+ }
+ }
+
+ override fun buildDialog(project: Project, directory: PsiDirectory, builder: CreateFileFromTemplateDialog.Builder) {
+ builder.setTitle("New Kotlin Script")
+ .addKind("Kotlin Script", KotlinFileType.INSTANCE.icon, "Kotlin Script")
+ }
+
+ override fun createFileFromTemplate(name: String, template: FileTemplate, dir: PsiDirectory) =
+ NewKotlinFileAction.createFileFromTemplate(name, template, dir)
+
+ override fun getActionName(directory: PsiDirectory, newName: String, templateName: String) = "Kotlin Script"
+
+ override fun startInWriteAction() = false
+
+ override fun hashCode(): Int = 0
+
+ override fun equals(other: Any?): Boolean = other is NewKotlinScriptAction
+}
\ No newline at end of file