Skip to content

Commit

Permalink
Merge branch 'master' into autocompile
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
PHPirates committed Dec 24, 2024
2 parents 1b0d8f4 + 2033bea commit b398880
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 10 deletions.
25 changes: 24 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,36 @@
### Added
* Add option to disable automatic compilation in power save mode
* Convert automatic compilation settings to a combobox
* Add checkboxes to graphic insertion wizard for relative width or height

### Fixed

## [0.9.10-alpha.4] - 2024-12-21

### Added
* Add sections to breadcrumbs
* Improve performance when starting a run configuration and when using autocompletion directly after starting the IDE
* Change order in structure view to match source file and sectioning level
* Add command redefinitions to command definition filter in structure view
* Add support for automatic language injection on the minted environment
* Add support for automatic detection of custom command aliases for include commands
* Add support for DeclareGraphicsExtensions
* Add inspection to warn about a missing reference for a glossary occurrence
* Do not fold sections in a command definition
* Include optional parameters in spellcheck, if it contains text
* Improve performance of finding files to be indexed
* 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

### Fixed

* Fix auto import from local bibtex file on Windows
* Fix false positive for duplicate command definition inspection in if/else
* Fix LaTeX files not showing up when choosing main file in run configuration
* Fix various issues with the Grazie implementation, in particular default rules for Grazie Pro

## [0.9.10-alpha.3] - 2024-12-15

### Added
Expand All @@ -29,6 +50,7 @@
* Inspections can now be suppressed for any single line, or block of text

### Fixed

* Fix false positive for duplicate command definition inspection in if/else
* Fix LaTeX files not showing up when choosing main file in run configuration
* Fix various issues with the Grazie implementation, in particular default rules for Grazie Pro
Expand Down Expand Up @@ -480,7 +502,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.10-alpha.3...HEAD
[Unreleased]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.10-alpha.4...HEAD
[0.9.10-alpha.4]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.10-alpha.3...v0.9.10-alpha.4
[0.9.10-alpha.3]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.10-alpha.2...v0.9.10-alpha.3
[0.9.10-alpha.2]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.9...v0.9.10-alpha.2
[0.9.9]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.8...v0.9.9
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.10-alpha.3
pluginVersion = 0.9.10-alpha.4

# 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.components.JBTextField
import com.intellij.ui.components.fields.ExpandableTextField
import com.intellij.ui.components.panels.HorizontalLayout
import nl.hannahsten.texifyidea.lang.commands.LatexGenericRegularCommand
import nl.hannahsten.texifyidea.lang.graphic.CaptionLocation
import nl.hannahsten.texifyidea.lang.graphic.FigureLocation
import nl.hannahsten.texifyidea.util.*
import nl.hannahsten.texifyidea.util.magic.FileMagic
import java.awt.Dimension
import java.awt.event.ActionEvent
import java.io.File
import java.util.*
import javax.swing.Box
Expand Down Expand Up @@ -66,6 +68,31 @@ open class InsertGraphicWizardDialogWrapper(val initialFilePath: String = "") :
}
}

private fun addOrRemoveSizeCommand(field: JBTextField, event: ActionEvent, command: String) {
val isSelected = (event.source as JBCheckBox).isSelected
if (isSelected && command !in field.text) {
field.text += command
}
else if (!isSelected && command in field.text) {
field.text = field.text.remove(command)
}
}

private val txtWidthRelative = JBCheckBox("Relative to line width").apply {
addActionListener {
// linewidth seems to be a good default: https://tex.stackexchange.com/a/17085/98850
val command = LatexGenericRegularCommand.LINEWIDTH.commandWithSlash
addOrRemoveSizeCommand(txtWidth, it, command)
}
}

private val txtHeightRelative = JBCheckBox("Relative to text height").apply {
addActionListener {
val command = LatexGenericRegularCommand.TEXTHEIGHT.commandWithSlash
addOrRemoveSizeCommand(txtHeight, it, command)
}
}

/**
* The angle option for the graphic. When empty, no angle. Not necessarily a number.
*/
Expand All @@ -76,6 +103,25 @@ open class InsertGraphicWizardDialogWrapper(val initialFilePath: String = "") :
}
}

private val keepAspectRatio = JBCheckBox("Keep aspect ratio").apply {
addActionListener {
val option = "keepaspectratio"
val isSelected = (it.source as JBCheckBox).isSelected
if (isSelected && option !in txtCustomOptions.text) {
if (txtCustomOptions.text.isNotBlank()) txtCustomOptions.text += ","
txtCustomOptions.text += option
}
else if (!isSelected && option in txtCustomOptions.text) {
if (",$option" in txtCustomOptions.text) {
txtCustomOptions.text = txtCustomOptions.text.remove(",$option")
}
else {
txtCustomOptions.text = txtCustomOptions.text.remove(option)
}
}
}
}

/**
* The custom graphics options. This is basically the optional parameter of \includegraphics.
* Can get modified when the width/height/angle get modified.
Expand Down Expand Up @@ -211,7 +257,13 @@ open class InsertGraphicWizardDialogWrapper(val initialFilePath: String = "") :
addLabeledComponent(txtAngle, "Angle:", labelWidth)
}
add(optionsPanel)
addLabeledComponent(txtCustomOptions, "Custom:", labelWidth)
val relativeOptionsPanel = JPanel(HorizontalLayout(10)).apply {
add(txtWidthRelative)
add(txtHeightRelative)
add(keepAspectRatio)
}
add(relativeOptionsPanel)
addLabeledComponent(txtCustomOptions, "Custom:", 80)
}

private fun JPanel.addLayoutControls() {
Expand Down Expand Up @@ -258,19 +310,25 @@ open class InsertGraphicWizardDialogWrapper(val initialFilePath: String = "") :
}

private fun JTextField.updateGraphicsOptions(fieldName: String) {
val text = text.replace(",", "")
val newOptionValue = text.replace(",", "")
// Update
if (txtCustomOptions.text.contains("$fieldName=")) {
txtCustomOptions.text = txtCustomOptions.text
.replace(Regex("$fieldName=[^,]*"), Regex.escapeReplacement("$fieldName=$text"))
if (newOptionValue.isNotBlank()) {
txtCustomOptions.text = txtCustomOptions.text
.replace(Regex("$fieldName=[^,]*"), Regex.escapeReplacement("$fieldName=$newOptionValue"))
}
else {
// Remove
txtCustomOptions.text = txtCustomOptions.text.replace(Regex(",?$fieldName=[^,]*"), "")
}
}
// Nothing yet, set width property.
else if (txtCustomOptions.text.isBlank()) {
txtCustomOptions.text = "$fieldName=$text"
txtCustomOptions.text = "$fieldName=$newOptionValue"
}
// When there is something, append width property.
else {
txtCustomOptions.text += ",$fieldName=$text"
txtCustomOptions.text += ",$fieldName=$newOptionValue"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import com.intellij.codeInsight.completion.InsertionContext
import com.intellij.codeInsight.lookup.LookupElement
import nl.hannahsten.texifyidea.file.BibtexFile
import nl.hannahsten.texifyidea.psi.BibtexEntry
import nl.hannahsten.texifyidea.psi.LatexPsiHelper
import nl.hannahsten.texifyidea.settings.TexifySettings
import nl.hannahsten.texifyidea.util.files.bibtexIdsInFileSet
import nl.hannahsten.texifyidea.util.files.referencedFileSet
import nl.hannahsten.texifyidea.util.parser.firstChildOfType

/**
* @author Sten Wessel
Expand All @@ -20,18 +22,21 @@ class LatexReferenceInsertHandler(private val remote: Boolean = false, private v

if (remote and TexifySettings.getInstance().automaticBibtexImport) {
remoteBib ?: return
// remoteBib may come from a file with CRLF line separators, which cannot be accepted into a psi file, so we need to fix that
val newBibEntry = LatexPsiHelper(context.project).createBibtexFromText(remoteBib.text.replace("\r\n", "\n")).firstChildOfType(BibtexEntry::class) ?: return

val bibsInFile = context.file.originalFile.bibtexIdsInFileSet()
// Add the bib item after the last item we found in the file set, and hope that that makes sense...
bibsInFile.lastOrNull()?.let {
it.parent.addAfter(remoteBib, it)
it.parent.addAfter(newBibEntry, it)
}

// If there are no bib items in the fileset yet, see if there is a(n empty) bib file we can add the bib entry to.
if (bibsInFile.isEmpty()) {
context.file.originalFile
.referencedFileSet()
.firstOrNull { it is BibtexFile }
?.add(remoteBib)
?.add(newBibEntry)
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/nl/hannahsten/texifyidea/psi/LatexPsiHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.psi.PsiFile
import com.intellij.psi.PsiFileFactory
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.impl.source.tree.LeafPsiElement
import nl.hannahsten.texifyidea.grammar.BibtexLanguage
import nl.hannahsten.texifyidea.grammar.LatexLanguage
import nl.hannahsten.texifyidea.psi.LatexTypes.*
import nl.hannahsten.texifyidea.util.Log
Expand Down Expand Up @@ -57,6 +58,9 @@ class LatexPsiHelper(private val project: Project) {
fun createFromText(text: String): PsiFile =
PsiFileFactory.getInstance(project).createFileFromText("DUMMY.tex", LatexLanguage, text, false, true)

fun createBibtexFromText(text: String): PsiFile =
PsiFileFactory.getInstance(project).createFileFromText("DUMMY.bib", BibtexLanguage, text, false, true)

/**
* Adds the supplied element to the content of the environment.
* @param environment The environment whose content should be manipulated
Expand Down

0 comments on commit b398880

Please sign in to comment.