From 7af1756a8e3daf1fe0fa5f8703fc53a4815d7c2a Mon Sep 17 00:00:00 2001 From: Abdelilah El Aissaoui Date: Mon, 4 Oct 2021 20:34:39 +0200 Subject: [PATCH] Moved opening dialog to a function --- src/main/kotlin/SystemDialogs.kt | 17 +++++++++++++++++ src/main/kotlin/main.kt | 16 ++-------------- 2 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 src/main/kotlin/SystemDialogs.kt diff --git a/src/main/kotlin/SystemDialogs.kt b/src/main/kotlin/SystemDialogs.kt new file mode 100644 index 0000000..fcd2b11 --- /dev/null +++ b/src/main/kotlin/SystemDialogs.kt @@ -0,0 +1,17 @@ +import git.GitManager +import javax.swing.JFileChooser + +fun openRepositoryDialog(gitManager: GitManager) { + val latestDirectoryOpened = gitManager.latestDirectoryOpened + + val f = if (latestDirectoryOpened == null) + JFileChooser() + else + JFileChooser(latestDirectoryOpened) + + f.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY + f.showSaveDialog(null) + + if (f.selectedFile != null) + gitManager.openRepository(f.selectedFile) +} \ No newline at end of file diff --git a/src/main/kotlin/main.kt b/src/main/kotlin/main.kt index fa7c84f..7144765 100644 --- a/src/main/kotlin/main.kt +++ b/src/main/kotlin/main.kt @@ -79,8 +79,7 @@ fun main() = application { LazyColumn( modifier = Modifier - .fillMaxSize() - .background(Color.Cyan) + .fillMaxSize(), ) { items(items = tabs.value, key = { it.key }) { val isItemSelected = it.key == selectedTabKey @@ -130,18 +129,7 @@ fun Gitnuro(isNewTab: Boolean, tabName: MutableState) { ) { GMenu( onRepositoryOpen = { - val latestDirectoryOpened = gitManager.latestDirectoryOpened - - val f = if (latestDirectoryOpened == null) - JFileChooser() - else - JFileChooser(latestDirectoryOpened) - - f.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY - f.showSaveDialog(null) - - if (f.selectedFile != null) - gitManager.openRepository(f.selectedFile) + openRepositoryDialog(gitManager = gitManager) }, onPull = { gitManager.pull() }, onPush = { gitManager.push() },