-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use IJ Platform infrastructure for executing processes
- Loading branch information
1 parent
16ebec0
commit 57d6763
Showing
7 changed files
with
97 additions
and
77 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/com/firsttimeinforever/intellij/pdf/viewer/tex/SynctexUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.firsttimeinforever.intellij.pdf.viewer.tex | ||
|
||
import com.firsttimeinforever.intellij.pdf.viewer.util.CommandExecutionUtils | ||
import com.intellij.execution.configurations.GeneralCommandLine | ||
import com.intellij.openapi.vfs.VirtualFile | ||
|
||
object SynctexUtils { | ||
/** | ||
* Checks if there is a SyncTeX file in the same folder as [this] file, | ||
* with the same base name (until the first period). | ||
* When there is no such SyncTeX file, all SyncTeX features should be disabled. | ||
* | ||
* Call this function on a pdf file to check if it has an accompanying SyncTeX file in the same folder. | ||
*/ | ||
fun VirtualFile.isSynctexFileAvailable(): Boolean { | ||
return parent.children | ||
.filter { it.name.contains("synctex") } | ||
.any { file -> | ||
file.name.takeWhile { it != '.' } == name.takeWhile { it != '.' } | ||
} | ||
} | ||
|
||
/** | ||
* Check if the SyncTeX command line utility is installed by trying to execute a SyncTeX command. | ||
*/ | ||
fun isSynctexInstalled(): Boolean { | ||
val output = CommandExecutionUtils.runCommand(GeneralCommandLine("synctex", "version")) ?: return false | ||
return output.stdout.contains("This is SyncTeX command line utility") || | ||
output.stderr.contains("This is SyncTeX command line utility") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/main/kotlin/com/firsttimeinforever/intellij/pdf/viewer/util/CommandExecutionUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.firsttimeinforever.intellij.pdf.viewer.util | ||
|
||
import com.intellij.execution.ExecutionException | ||
import com.intellij.execution.configurations.GeneralCommandLine | ||
import com.intellij.execution.process.ProcessOutput | ||
import com.intellij.execution.util.ExecUtil | ||
import com.intellij.openapi.application.ApplicationManager | ||
|
||
internal object CommandExecutionUtils { | ||
fun runCommand(commandLine: GeneralCommandLine): ProcessOutput? { | ||
return ApplicationManager.getApplication().executeOnPooledThread<ProcessOutput?> { | ||
try { | ||
ExecUtil.execAndGetOutput(commandLine, timeoutInMilliseconds = 3000) | ||
} catch (exception: ExecutionException) { | ||
exception.printStackTrace() | ||
null | ||
} | ||
}.get() | ||
} | ||
|
||
fun getCommandStdoutIfSuccessful(commandLine: GeneralCommandLine): String? { | ||
return runCommand(commandLine)?.let { | ||
when (it.exitCode) { | ||
0 -> it.stdout | ||
else -> null | ||
} | ||
} | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
src/main/kotlin/com/firsttimeinforever/intellij/pdf/viewer/util/Synctex.kt
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
src/main/kotlin/com/firsttimeinforever/intellij/pdf/viewer/util/System.kt
This file was deleted.
Oops, something went wrong.