Skip to content

Commit

Permalink
Merge pull request #3552 from jojo2357/refactoring-name
Browse files Browse the repository at this point in the history
Do not select the extension when refactoring file names
  • Loading branch information
PHPirates authored May 27, 2024
2 parents 11aeebd + 5880e53 commit 16d6418
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions resources/META-INF/extensions/files-and-project.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
<applicationService serviceInterface="nl.hannahsten.texifyidea.util.files.ReferencedFileSetService"
serviceImplementation="nl.hannahsten.texifyidea.util.files.impl.ReferencedFileSetServiceImpl"/>
<indexPatternBuilder implementation="nl.hannahsten.texifyidea.index.LatexIndexPatternBuilder"/>

<renamePsiElementProcessor implementation="nl.hannahsten.texifyidea.LatexRenameProcessor"/>
</extensions>
</idea-plugin>
24 changes: 24 additions & 0 deletions src/nl/hannahsten/texifyidea/LatexRenameProcessor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package nl.hannahsten.texifyidea

import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.refactoring.rename.RenameDialog
import com.intellij.refactoring.rename.RenamePsiElementProcessor
import com.intellij.refactoring.rename.RenamePsiFileProcessor.PsiFileRenameDialog

class LatexRenameProcessor : RenamePsiElementProcessor() {
override fun canProcessElement(element: PsiElement): Boolean {
// The reason below is only applicable for files
return when (element) {
is PsiFile -> true
else -> false
}
}

override fun createRenameDialog(project: Project, element: PsiElement, nameSuggestionContext: PsiElement?, editor: Editor?): RenameDialog {
// We want to not select the extension in the dialog when renaming files, and looking at RenameDialog#createNewNameComponent(), this is done by setting the editor to null
return PsiFileRenameDialog(project, element, nameSuggestionContext, null)
}
}

0 comments on commit 16d6418

Please sign in to comment.