Skip to content

Commit

Permalink
Merge pull request #3391 from Hannah-Sten/preview-ui
Browse files Browse the repository at this point in the history
Improve user feedback for preview when Inkscape is not installed
  • Loading branch information
PHPirates authored Jan 14, 2024
2 parents 5345ab6 + d74d3ac commit dd01bae
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 deletions.
21 changes: 19 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,34 @@

### Fixed

## [0.9.3-alpha.3] - 2024-01-08
## [0.9.3-alpha.4] - 2024-01-12

### Added

* Improve autocompletion performance after starting IDE
* Improve plugin loading performance

### Fixed

* Fix incorrectly inserted \items in enumeration environments, by @jojo2357
* Fix false positives for equation gathering inspection, by @jojo2357
* Don't attempt to use mthelp when it is not available, by @jojo2357
* Fix #3361: false positive on duplicate identifier on @string entries in bib files
* Replace code deprecated in 2023.3
* Avoid creating output directories recursively and improve the cleanup process

## [0.9.3-alpha.3] - 2024-01-08

### Added

* Improve plugin loading performance

### Fixed

* Don't attempt to use mthelp when it is not available, by @jojo2357
* Fix #3361: false positive on duplicate identifier on @string entries in bib files
* Replace code deprecated in 2023.3
* Avoid creating output directories recursively and improve the cleanup process

## [0.9.2] - 2023-11-24

Expand Down Expand Up @@ -268,8 +284,9 @@ 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.3-alpha.3...HEAD
[Unreleased]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.3-alpha.4...HEAD
[0.9.3-alpha.3]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.2...v0.9.3-alpha.3
[0.9.3-alpha.4]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.3-alpha.3...v0.9.3-alpha.4
[0.9.2]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.1...v0.9.2
[0.9.1]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.0...v0.9.1
[0.9.0]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.7.33...v0.9.0
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pluginVersion = 0.9.3-alpha.3
pluginVersion = 0.9.3-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.*
# means that the first possible build is the next branch number after xyz, so e.g.
# a since build of 173.* is equal to 181
pluginSinceBuild = 232
pluginSinceBuild = 233

# Token for releasing to Jetbrains using the Gradle intellij/publishPlugin task, for more information see the Gradle build file.
intellijPublishToken=mytoken
Expand Down
37 changes: 22 additions & 15 deletions src/nl/hannahsten/texifyidea/action/preview/InkscapePreviewer.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package nl.hannahsten.texifyidea.action.preview

import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.progress.ProgressManager
import com.intellij.openapi.progress.Task
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.SystemInfo
import com.intellij.openapi.util.io.FileUtil
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import nl.hannahsten.texifyidea.settings.sdk.LatexSdkUtil
import nl.hannahsten.texifyidea.util.SystemEnvironment
import nl.hannahsten.texifyidea.util.runCommandWithExitCode
Expand All @@ -21,8 +22,8 @@ import javax.swing.SwingUtilities
class InkscapePreviewer : Previewer {

override fun preview(input: String, previewForm: PreviewForm, project: Project, preamble: String, waitTime: Long) {
runBlocking {
launch {
ProgressManager.getInstance().run(object : Task.Backgroundable(project, "Generating preview...") {
override fun run(indicator: ProgressIndicator) {
try {
// Snap apps are confined to the users home directory
if (SystemEnvironment.isInkscapeInstalledAsSnap) {
Expand All @@ -46,7 +47,7 @@ class InkscapePreviewer : Previewer {
previewForm.setLatexErrorMessage("${exception.message}")
}
}
}
})
}

/**
Expand Down Expand Up @@ -87,10 +88,13 @@ $previewCode
previewForm
) ?: return

runInkscape(tempBasename, tempDirectory, waitTime, previewForm)
val image = ImageIO.read(File("$tempBasename.png"))
SwingUtilities.invokeLater {
previewForm.setPreview(image, latexStdoutText)
// Sets error message to the UI if any
val success = runInkscape(tempBasename, tempDirectory, waitTime, previewForm)
if (success) {
val image = ImageIO.read(File("$tempBasename.png"))
SwingUtilities.invokeLater {
previewForm.setPreview(image, latexStdoutText)
}
}
}
finally {
Expand All @@ -106,7 +110,7 @@ $previewCode
waitTime: Long,
previewForm: PreviewForm
): String? {
val result = runCommandWithExitCode(command, *args, workingDirectory = workDirectory, timeout = waitTime)
val result = runCommandWithExitCode(command, *args, workingDirectory = workDirectory, timeout = waitTime, returnExceptionMessage = true)

if (result.second != 0) {
previewForm.setLatexErrorMessage("$command exited with ${result.second}\n${result.first ?: ""}")
Expand All @@ -118,10 +122,12 @@ $previewCode

/**
* Run inkscape command to convert pdf to png, depending on the version of inkscape.
*
* @return If successful
*/
private fun runInkscape(tempBasename: String, tempDirectory: File, waitTime: Long, previewForm: PreviewForm) {
private fun runInkscape(tempBasename: String, tempDirectory: File, waitTime: Long, previewForm: PreviewForm): Boolean {
// If 1.0 or higher
if (SystemEnvironment.inkscapeMajorVersion >= 1) {
if (SystemEnvironment.inkscapeMajorVersion >= 1 || !SystemEnvironment.isAvailable("inkscape")) {
runPreviewFormCommand(
inkscapeExecutable(),
arrayOf(
Expand All @@ -135,7 +141,7 @@ $previewCode
tempDirectory,
waitTime,
previewForm
) ?: throw AccessDeniedException(tempDirectory)
) ?: return false
}
else {
runPreviewFormCommand(
Expand All @@ -147,7 +153,7 @@ $previewCode
tempDirectory,
waitTime,
previewForm
) ?: return
) ?: return false

runPreviewFormCommand(
inkscapeExecutable(),
Expand All @@ -161,8 +167,9 @@ $previewCode
tempDirectory,
waitTime,
previewForm
) ?: throw AccessDeniedException(tempDirectory)
) ?: return false
}
return true
}

private fun inkscapeExecutable(): String {
Expand Down

0 comments on commit dd01bae

Please sign in to comment.