Skip to content

Commit

Permalink
Merge pull request #3769 from Hannah-Sten/create-file-intention
Browse files Browse the repository at this point in the history
Improve 'create file' quickfix
  • Loading branch information
PHPirates authored Nov 25, 2024
2 parents 3cd4655 + 3f302b3 commit 787188d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 7 deletions.
32 changes: 31 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,40 @@
## [Unreleased]

### Added

### Fixed

## [0.9.9-alpha.7] - 2024-11-24

### Added

* Support references in \subfix command
* Provide autocompletion for all relevant directories when using subfiles
* Do not format existing directories in the given path in the file creation quickfix dialog
* Disable Evince inverse search on Windows to avoid a UI freeze on opening a second project
* Use xdg-mime to choose a default pdf viewer in the run configuration template
* Don't insert the right brace when in front of text
* Add DeclareMathSymbol to indexed command definitions in installed packages
* Add support for TEXMFHOME for reference resolving
* Add diffcoeff and upgreek packages to autocompletion, by @Toseflo
* Improve reference resolving when using subfiles
* Add setting to disable auto-import of bibtex entries from remote libraries

### Fixed

* Fix 'missing import' false positive in subfiles
* Don't override the file icon for .txt files, by @Steve-Li-1998
* Fix exceptions #3754 and #3326
* Fix exceptions in structure view when command parameters are missing
* Improve error report submitter for long stacktraces
* Fix a parser issue with bidirectional arrow in TikZ
* Fix default Docker image name when running Dockerized TeX Live without a project SDK
* Always use content roots to resolve references
* Fix 'package not found' error when using texlive-full on Windows, and improve running of system commands, by @tristankretzer
* Fix rename of files when using subfiles
* Fix incorrect 'package already included' warning for the subfiles package
* Fix exception #3557 if using bibtex structure view when bibtex file type is reassignd to plain text
* Avoid referencing obsolete psifiles, fix exception #3635

## [0.9.9-alpha.6] - 2024-11-23

Expand Down Expand Up @@ -487,7 +516,8 @@ Thanks to @jojo2357 and @MisterDeenis for contributing to this release!
* Fix some intention previews. ([#2796](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2796))
* Other small bug fixes and improvements. ([#2776](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2776), [#2774](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2774), [#2765](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2765)-[#2773](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2773))

[Unreleased]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.9-alpha.6...HEAD
[Unreleased]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.9-alpha.7...HEAD
[0.9.9-alpha.7]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.9-alpha.6...v0.9.9-alpha.7
[0.9.9-alpha.6]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.9-alpha.4...v0.9.9-alpha.6
[0.9.9-alpha.4]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.9-alpha.3...v0.9.9-alpha.4
[0.9.9-alpha.3]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.9-alpha.2...v0.9.9-alpha.3
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pluginVersion = 0.9.9-alpha.6
pluginVersion = 0.9.9-alpha.7

# Info about build ranges: https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html
# Note that an xyz branch corresponds to version 20xy.z and a since build of xyz.*
Expand Down
26 changes: 21 additions & 5 deletions src/nl/hannahsten/texifyidea/ui/CreateFileDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 java.io.File
import javax.swing.JPanel
Expand All @@ -12,12 +13,11 @@ import javax.swing.JTextField
*
* Dialog to ask the user for a file name and location when creating a new file.
*
* @param currentFilePath The path of the file we are currently in, e.g., the file from which an intention was triggered
* that creates a new file.
* @param basePath The path of the file to which the newFileName is relative
* @param newFileName The name of the new file, with or without the extension. Will be reformatted before being shown to the user.
* @param newFileFullPath The full path of the new file, without tex extension.
*/
class CreateFileDialog(private val currentFilePath: String?, private val newFileName: String, var newFileFullPath: String? = null) {
class CreateFileDialog(private val basePath: String?, private val newFileName: String, var newFileFullPath: String? = null) {

init {
DialogBuilder().apply {
Expand All @@ -26,10 +26,26 @@ class CreateFileDialog(private val currentFilePath: String?, private val newFile
panel.layout = VerticalFlowLayout(VerticalFlowLayout.TOP)

// Field to enter the name of the new file.
val nameField = JTextField(newFileName.formatAsFilePath())
// 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()
}
else {
newFileName.formatAsFilePath()
}
val nameField = JTextField(formattedPath)

// Field to select the folder/location of the new file.
val pathField = TextFieldWithBrowseButton()
pathField.text = currentFilePath ?: return@apply
pathField.text = basePath ?: return@apply
// Make sure the dialog is wide enough to fit the whole path in the text field.
pathField.textField.columns = pathField.text.length

Expand Down

0 comments on commit 787188d

Please sign in to comment.