Added support for zenity dialogs in linux
This commit is contained in:
parent
1a67170b5b
commit
73659a2a10
23
src/main/kotlin/app/extensions/Shell.kt
Normal file
23
src/main/kotlin/app/extensions/Shell.kt
Normal file
@ -0,0 +1,23 @@
|
||||
package app.extensions
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun runCommand(command: String): String? {
|
||||
return try {
|
||||
var result: String?
|
||||
Runtime.getRuntime().exec(command).inputStream.use { inputStream ->
|
||||
Scanner(inputStream).useDelimiter("\\A").use { s ->
|
||||
result = if (s.hasNext())
|
||||
s.next()
|
||||
else
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
result
|
||||
} catch (ex: Exception) {
|
||||
ex.printStackTrace()
|
||||
null
|
||||
}
|
||||
|
||||
}
|
@ -1,10 +1,41 @@
|
||||
import app.AppStateManager
|
||||
import app.extensions.runCommand
|
||||
import app.git.GitManager
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
import javax.swing.JFileChooser
|
||||
|
||||
|
||||
fun openRepositoryDialog(gitManager: GitManager) {
|
||||
val os = System.getProperty("os.name")
|
||||
val appStateManager = gitManager.appStateManager
|
||||
val latestDirectoryOpened = appStateManager.latestOpenedRepositoryPath
|
||||
|
||||
|
||||
if(os.lowercase() == "linux") {
|
||||
val checkZenityInstalled = runCommand("which zenity 2>/dev/null")
|
||||
val isZenityInstalled = !checkZenityInstalled.isNullOrEmpty()
|
||||
|
||||
if(isZenityInstalled) {
|
||||
val openDirectory = runCommand(
|
||||
"zenity --file-selection --title=\"Select your git directory\" --directory --filename=\"$latestDirectoryOpened\""
|
||||
)?.replace("\n", "")
|
||||
|
||||
if(!openDirectory.isNullOrEmpty())
|
||||
gitManager.openRepository(openDirectory)
|
||||
} else
|
||||
openRepositoryDialog(gitManager, latestDirectoryOpened)
|
||||
} else {
|
||||
openRepositoryDialog(gitManager, latestDirectoryOpened)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private fun openRepositoryDialog(
|
||||
gitManager: GitManager,
|
||||
latestDirectoryOpened: String
|
||||
) {
|
||||
|
||||
val fileChooser = if (latestDirectoryOpened.isEmpty())
|
||||
JFileChooser()
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user