Make plugin compatible with idea version 2019.3
This commit is contained in:
parent
6262bda2fb
commit
32bf4dfacb
|
|
@ -1,4 +1,4 @@
|
|||
kotlin.code.style=official
|
||||
|
||||
pluginVersion = 1.0.0-192
|
||||
platformVersion = 2019.2
|
||||
pluginVersion = 1.0.0-193
|
||||
platformVersion = 2019.3
|
||||
|
|
|
|||
|
|
@ -3,12 +3,17 @@ package de.idetools.filename_template
|
|||
import com.intellij.icons.AllIcons
|
||||
import com.intellij.ide.IdeBundle
|
||||
import com.intellij.ide.actions.CreateFileAction
|
||||
import com.intellij.ide.ui.newItemPopup.NewItemPopupUtil
|
||||
import com.intellij.ide.ui.newItemPopup.NewItemSimplePopupPanel
|
||||
import com.intellij.lang.LangBundle
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.ui.Messages
|
||||
import com.intellij.openapi.ui.InputValidatorEx
|
||||
import com.intellij.psi.PsiDirectory
|
||||
import com.intellij.psi.PsiElement
|
||||
import java.awt.event.InputEvent
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneOffset
|
||||
import java.util.function.Consumer
|
||||
|
||||
class CreateFileWithFilenameTemplateAction(
|
||||
text: String,
|
||||
|
|
@ -17,17 +22,33 @@ class CreateFileWithFilenameTemplateAction(
|
|||
) :
|
||||
CreateFileAction(text, description, AllIcons.FileTypes.Unknown) {
|
||||
|
||||
override fun invokeDialog(project: Project?, directory: PsiDirectory?): Array<PsiElement> {
|
||||
override fun invokeDialog(
|
||||
project: Project,
|
||||
directory: PsiDirectory,
|
||||
elementsConsumer: Consumer<Array<PsiElement?>?>
|
||||
) {
|
||||
val validator: MyInputValidator = MyValidator(project, directory)
|
||||
Messages.showInputDialog(
|
||||
project,
|
||||
IdeBundle.message("prompt.enter.new.file.name"),
|
||||
IdeBundle.message("title.new.file"),
|
||||
null,
|
||||
processTemplate(template),
|
||||
validator
|
||||
)
|
||||
return validator.createdElements
|
||||
val contentPanel = NewItemSimplePopupPanel()
|
||||
val nameField = contentPanel.textField
|
||||
|
||||
nameField.text = processTemplate(template)
|
||||
|
||||
val popup = NewItemPopupUtil.createNewItemPopup(IdeBundle.message("title.new.file"), contentPanel, nameField)
|
||||
contentPanel.setApplyAction { event: InputEvent? ->
|
||||
val name = nameField.text
|
||||
if (validator.checkInput(name) && validator.canClose(name)) {
|
||||
popup.closeOk(event)
|
||||
elementsConsumer.accept(validator.createdElements)
|
||||
} else {
|
||||
val errorMessage =
|
||||
if (validator is InputValidatorEx)
|
||||
(validator as InputValidatorEx).getErrorText(name)
|
||||
else
|
||||
LangBundle.message("incorrect.name")
|
||||
contentPanel.setError(errorMessage)
|
||||
}
|
||||
}
|
||||
popup.showCenteredInCurrentWindow(project)
|
||||
}
|
||||
|
||||
private fun processTemplate(template: String): String {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user