Clicking an image diff will now open ir with the default image viewer

This commit is contained in:
Abdelilah El Aissaoui 2022-08-14 20:26:42 +02:00
parent 5659bf8918
commit e550a6289c
2 changed files with 21 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import java.awt.Desktop
import java.awt.Toolkit
import java.awt.datatransfer.Clipboard
import java.awt.datatransfer.StringSelection
import java.io.File
import java.net.URI
import java.nio.file.FileSystems
@ -20,6 +21,12 @@ fun openUrlInBrowser(url: String) {
}
}
fun openFileWithExternalApp(filePath: String) {
if (!openSystemSpecific(filePath)) {
openFileJdk(filePath)
}
}
private fun openSystemSpecific(url: String): Boolean {
when(getCurrentOs()) {
OS.LINUX -> {
@ -39,7 +46,7 @@ private fun openSystemSpecific(url: String): Boolean {
return false
}
fun openUrlInBrowserJdk(url: String) {
private fun openUrlInBrowserJdk(url: String) {
try {
Desktop.getDesktop().browse(URI(url))
@ -49,6 +56,15 @@ fun openUrlInBrowserJdk(url: String) {
}
}
private fun openFileJdk(filePath: String) {
try {
Desktop.getDesktop().open(File(filePath))
} catch (ex: Exception) {
println("Failed to open URL in browser")
ex.printStackTrace()
}
}
fun copyInBrowser(textToCopy: String) {
try {
val selection = StringSelection(textToCopy)

View File

@ -28,9 +28,7 @@ import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import app.extensions.lineDelimiter
import app.extensions.removeLineDelimiters
import app.extensions.toStringWithSpaces
import app.extensions.*
import app.git.*
import app.git.diff.DiffResult
import app.git.diff.Hunk
@ -237,6 +235,9 @@ fun ImageDiff(tempImagePath: Path) {
bitmap = loadImageBitmap(inputStream = FileInputStream(tempImagePath.absolutePathString())),
contentDescription = null,
modifier = Modifier.fillMaxSize()
.handMouseClickable {
openFileWithExternalApp(tempImagePath.absolutePathString())
}
)
}