@@ -17,21 +17,22 @@ import java.util.*
1717 */
1818class FileNameTextFieldDialog (private val project : Project ) {
1919
20- fun openDialog (isDirectory : Boolean , consumer : Consumer <String >) {
21- val validator = FileNameValidator (isDirectory)
20+ fun openDialog (isDirectory : Boolean , value : String? = null, consumer : Consumer <String >) {
21+ val validator = FileNameValidator (isDirectory, value )
2222 if (Experiments .getInstance().isFeatureEnabled(" show.create.new.element.in.popup" )) {
23- createLightWeightPopup(validator, consumer).showCenteredInCurrentWindow(project)
23+ createLightWeightPopup(validator, value, consumer).showCenteredInCurrentWindow(project)
2424 } else {
2525 Messages .showInputDialog(
2626 this .project, " Create something new" ,
27- " New File" , null , null , validator
27+ " New ${ if (isDirectory) " Folder " else " File" } " , null , value , validator
2828 )
2929 }
3030 }
3131
32- private fun createLightWeightPopup (validator : FileNameValidator , consumer : Consumer <String >): JBPopup {
32+ private fun createLightWeightPopup (validator : FileNameValidator , value : String? = null, consumer : Consumer <String >): JBPopup {
3333 val contentPanel = NewItemSimplePopupPanel ()
3434 val nameField = contentPanel.textField
35+ if (value != null ) nameField.text = value
3536 return NewItemPopupUtil .createNewItemPopup(" New ${validator.objectName.replaceFirstChar { it.uppercaseChar() }} " , contentPanel, nameField).also { popup ->
3637 contentPanel.applyAction = Consumer { event: InputEvent ? ->
3738 val name = nameField.text
@@ -47,7 +48,10 @@ class FileNameTextFieldDialog(private val project: Project) {
4748
4849}
4950
50- class FileNameValidator (private val isDirectory : Boolean ) : InputValidatorEx {
51+ class FileNameValidator (
52+ private val isDirectory : Boolean ,
53+ private val value : String? = null ,
54+ ) : InputValidatorEx {
5155
5256 val objectName: String = if (isDirectory) " folder" else " file"
5357
@@ -63,6 +67,10 @@ class FileNameValidator(private val isDirectory: Boolean) : InputValidatorEx {
6367 errorText = " $objectName name can NOT end withs ${ExplorerBaseWindow .FILE_SEP } "
6468 return false
6569 }
70+ if (value == inputString) {
71+ errorText = " $value already exists"
72+ return false
73+ }
6674 val tokenizer = StringTokenizer (
6775 parsedName,
6876 ExplorerBaseWindow .FILE_SEP ,
0 commit comments