diff --git a/CHANGELOG.md b/CHANGELOG.md index b3d6baeb9..01ba4971e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] ### Added +* Show formatted file path in file not found inspection quickfix name * Automatically index bibliography files outside the project that are included by an absolute path * Disable quotes inspection when TeX ligatures are disabled by fontspec * Inspections can now be suppressed for any single line, or block of text diff --git a/src/nl/hannahsten/texifyidea/inspections/latex/probablebugs/LatexFileNotFoundInspection.kt b/src/nl/hannahsten/texifyidea/inspections/latex/probablebugs/LatexFileNotFoundInspection.kt index b1fc1a839..e13a9fb52 100644 --- a/src/nl/hannahsten/texifyidea/inspections/latex/probablebugs/LatexFileNotFoundInspection.kt +++ b/src/nl/hannahsten/texifyidea/inspections/latex/probablebugs/LatexFileNotFoundInspection.kt @@ -103,7 +103,7 @@ open class LatexFileNotFoundInspection : TexifyInspectionBase() { */ class CreateNewFileWithDialogQuickFix(private val filePath: String, private val extension: String, private val elementPointer: SmartPsiElementPointer, private val key: String, private val range: TextRange) : LocalQuickFix { - override fun getFamilyName() = "Create file ${filePath.appendExtension(extension)}" + override fun getFamilyName() = "Create file ${filePath.appendExtension(extension).formatAsFilePath()}" override fun startInWriteAction() = false diff --git a/src/nl/hannahsten/texifyidea/ui/CreateFileDialog.kt b/src/nl/hannahsten/texifyidea/ui/CreateFileDialog.kt index 0cb415745..b1737c0f7 100644 --- a/src/nl/hannahsten/texifyidea/ui/CreateFileDialog.kt +++ b/src/nl/hannahsten/texifyidea/ui/CreateFileDialog.kt @@ -2,8 +2,8 @@ package nl.hannahsten.texifyidea.ui import com.intellij.openapi.fileChooser.FileChooserDescriptor import com.intellij.openapi.ui.* -import com.intellij.openapi.vfs.LocalFileSystem import nl.hannahsten.texifyidea.util.formatAsFilePath +import nl.hannahsten.texifyidea.util.formatAsFilePathWithExistingParents import java.io.File import javax.swing.JPanel import javax.swing.JTextField @@ -26,17 +26,8 @@ class CreateFileDialog(private val basePath: String?, private val newFileName: S panel.layout = VerticalFlowLayout(VerticalFlowLayout.TOP) // Field to enter the name of the new file. - // If only the file is new, but the directory exists, use the existing directory and don't change it to follow conventions val formattedPath = if (basePath != null) { - var existingPath = LocalFileSystem.getInstance().findFileByPath(basePath) - var existingRelativePath = "" - val partsToFormat = newFileName.split('/').dropWhile { part -> - if (existingPath?.exists() == false) return@dropWhile false - existingPath = existingPath?.children?.firstOrNull { it.name == part } ?: return@dropWhile false - existingRelativePath += "$part/" - true - } - existingRelativePath + partsToFormat.joinToString("/").formatAsFilePath() + formatAsFilePathWithExistingParents(basePath, newFileName) } else { newFileName.formatAsFilePath() diff --git a/src/nl/hannahsten/texifyidea/util/Strings.kt b/src/nl/hannahsten/texifyidea/util/Strings.kt index e4665ad9a..0caa58c4c 100644 --- a/src/nl/hannahsten/texifyidea/util/Strings.kt +++ b/src/nl/hannahsten/texifyidea/util/Strings.kt @@ -1,6 +1,7 @@ package nl.hannahsten.texifyidea.util import com.intellij.openapi.util.TextRange +import com.intellij.openapi.vfs.LocalFileSystem import nl.hannahsten.texifyidea.util.magic.PatternMagic import org.intellij.lang.annotations.Language import java.io.File @@ -175,6 +176,21 @@ fun String.formatAsFilePath(): String { return formatted.ifEmpty { "myfile" } } +/** + * If only the file is new, but the directory exists, use the existing directory and don't change it to follow conventions + */ +fun formatAsFilePathWithExistingParents(basePath: String, newFileName: String): String { + var existingPath = LocalFileSystem.getInstance().findFileByPath(basePath) + var existingRelativePath = "" + val partsToFormat = newFileName.split('/').dropWhile { part -> + if (existingPath?.exists() == false) return@dropWhile false + existingPath = existingPath?.children?.firstOrNull { it.name == part } ?: return@dropWhile false + existingRelativePath += "$part/" + true + } + return existingRelativePath + partsToFormat.joinToString("/").formatAsFilePath() +} + /** * Formats the string as a valid LaTeX label name. */