From ba53d50c312ef676f9f862f43f2fa59d24f7886e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 5 Sep 2024 16:44:49 +0200 Subject: [PATCH] Use FileKit dir picker on Linux --- .../org/gradle/client/core/util/DesktopOS.kt | 2 - .../gradle/client/ui/build/BuildContent.kt | 41 +------------------ .../client/ui/buildlist/BuildListContent.kt | 37 ++++------------- .../client/ui/composables/DirChooserDialog.kt | 27 ------------ 4 files changed, 10 insertions(+), 97 deletions(-) delete mode 100644 gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/composables/DirChooserDialog.kt diff --git a/gradle-client/src/jvmMain/kotlin/org/gradle/client/core/util/DesktopOS.kt b/gradle-client/src/jvmMain/kotlin/org/gradle/client/core/util/DesktopOS.kt index e279ff0..5a03408 100644 --- a/gradle-client/src/jvmMain/kotlin/org/gradle/client/core/util/DesktopOS.kt +++ b/gradle-client/src/jvmMain/kotlin/org/gradle/client/core/util/DesktopOS.kt @@ -4,8 +4,6 @@ enum class DesktopOS(val id: String) { Linux("linux"), Mac("macos"), Windows("windows"); - - val isLinux: Boolean get() = this == Linux } val currentDesktopOS: DesktopOS by lazy { diff --git a/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/build/BuildContent.kt b/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/build/BuildContent.kt index a4b340b..a48cebd 100644 --- a/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/build/BuildContent.kt +++ b/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/build/BuildContent.kt @@ -22,7 +22,6 @@ import org.gradle.client.core.gradle.GradleConnectionParameters.Companion.isVali import org.gradle.client.core.gradle.GradleConnectionParameters.Companion.isValidGradleVersion import org.gradle.client.core.gradle.GradleConnectionParameters.Companion.isValidJavaHome import org.gradle.client.core.gradle.GradleDistribution -import org.gradle.client.core.util.currentDesktopOS import org.gradle.client.ui.composables.* import org.gradle.client.ui.theme.plusPaneSpacing import org.gradle.client.ui.theme.spacing @@ -138,7 +137,6 @@ private fun BuildMainContent(component: BuildComponent, build: Build, snackbarSt state = javaHome, defaultState = System.getenv("JAVA_HOME")?.takeIf { it.isNotBlank() }, isError = !isJavaHomeValid, - showHiddenFiles = true, showSnackbar = { message -> scope.launch { snackbarState.showSnackbar(message) } } ) DirectoryField( @@ -146,7 +144,6 @@ private fun BuildMainContent(component: BuildComponent, build: Build, snackbarSt state = gradleUserHome, defaultState = System.getProperty("user.home") + "/.gradle", isError = !isGradleUserHomeValid, - showHiddenFiles = true, showSnackbar = { message -> scope.launch { snackbarState.showSnackbar(message) } }, ) GradleDistributionField(state = gradleDistSource) @@ -270,7 +267,6 @@ private fun DirectoryField( defaultState: String? = null, readOnly: Boolean = false, isError: Boolean = false, - showHiddenFiles: Boolean = false, showSnackbar: (message: String) -> Unit, ) { BuildTextField( @@ -288,46 +284,13 @@ private fun DirectoryField( } }, trailingIcon = { - val helpText = "Select a $description" - if (currentDesktopOS.isLinux) { - LinuxDirectoryFieldPicker(description, helpText, state, showHiddenFiles, showSnackbar) - } else { - NonLinuxDirectoryFieldPicker(description, helpText, state, showSnackbar) - } + DirectoryFieldPicker(description, "Select a $description", state, showSnackbar) }, ) } @Composable -private fun LinuxDirectoryFieldPicker( - description: String, - helpText: String, - state: MutableState, - showHiddenFiles: Boolean = false, - showSnackbar: (message: String) -> Unit, -) { - var isDirChooserOpen by remember { mutableStateOf(false) } - if (isDirChooserOpen) { - DirChooserDialog( - helpText = helpText, - showHiddenFiles = showHiddenFiles, - onDirChosen = { dir -> - isDirChooserOpen = false - if (dir == null) { - showSnackbar("No $description selected") - } else { - state.value = dir.absolutePath - } - } - ) - } - DirectoryFilePickerIcon(helpText, state) { - isDirChooserOpen = true - } -} - -@Composable -private fun NonLinuxDirectoryFieldPicker( +private fun DirectoryFieldPicker( description: String, helpText: String, state: MutableState, diff --git a/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/buildlist/BuildListContent.kt b/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/buildlist/BuildListContent.kt index cbc9f38..81adfb8 100644 --- a/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/buildlist/BuildListContent.kt +++ b/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/buildlist/BuildListContent.kt @@ -9,20 +9,24 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add import androidx.compose.material.icons.filled.Close import androidx.compose.material3.* -import androidx.compose.runtime.* +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp import com.arkivanov.decompose.extensions.compose.subscribeAsState import io.github.vinceglb.filekit.compose.rememberDirectoryPickerLauncher -import io.github.vinceglb.filekit.core.FileKitPlatformSettings import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import org.gradle.client.core.Constants.APPLICATION_DISPLAY_NAME import org.gradle.client.core.database.Build -import org.gradle.client.core.util.currentDesktopOS -import org.gradle.client.ui.composables.* +import org.gradle.client.ui.composables.Loading +import org.gradle.client.ui.composables.PlainTextTooltip +import org.gradle.client.ui.composables.TitleMedium +import org.gradle.client.ui.composables.TopBar import org.gradle.client.ui.theme.plusPaneSpacing import java.io.File @@ -83,15 +87,6 @@ private fun BuildListDeleteButon(component: BuildListComponent, build: Build) { @Composable private fun AddBuildButton(component: BuildListComponent, snackbarState: SnackbarHostState) { - if (currentDesktopOS.isLinux) { - LinuxAddBuildButton(component, snackbarState) - } else { - NonLinuxAddBuildButton(component, snackbarState) - } -} - -@Composable -private fun NonLinuxAddBuildButton(component: BuildListComponent, snackbarState: SnackbarHostState) { val scope = rememberCoroutineScope() val dirPickerLauncher = rememberDirectoryPickerLauncher(ADD_BUILD_HELP_TEXT) { rootDir -> onBuildDirSelected(scope, component, snackbarState, rootDir?.file) @@ -99,22 +94,6 @@ private fun NonLinuxAddBuildButton(component: BuildListComponent, snackbarState: AddBuildDirFAB { dirPickerLauncher.launch() } } -@Composable -private fun LinuxAddBuildButton(component: BuildListComponent, snackbarState: SnackbarHostState) { - val scope = rememberCoroutineScope() - var isDirChooserOpen by remember { mutableStateOf(false) } - if (isDirChooserOpen) { - DirChooserDialog( - helpText = ADD_BUILD_HELP_TEXT, - onDirChosen = { rootDir -> - isDirChooserOpen = false - onBuildDirSelected(scope, component, snackbarState, rootDir) - } - ) - } - AddBuildDirFAB { isDirChooserOpen = true } -} - private fun onBuildDirSelected( scope: CoroutineScope, component: BuildListComponent, diff --git a/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/composables/DirChooserDialog.kt b/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/composables/DirChooserDialog.kt deleted file mode 100644 index ed52e9d..0000000 --- a/gradle-client/src/jvmMain/kotlin/org/gradle/client/ui/composables/DirChooserDialog.kt +++ /dev/null @@ -1,27 +0,0 @@ -package org.gradle.client.ui.composables - -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import java.io.File -import javax.swing.JFileChooser - -@Composable -fun DirChooserDialog( - helpText: String, - showHiddenFiles: Boolean = false, - onDirChosen: (dir: File?) -> Unit, -) { - LaunchedEffect(Unit) { - val chooser = JFileChooser() - chooser.dialogTitle = helpText - chooser.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY - chooser.isAcceptAllFileFilterUsed = false - chooser.isMultiSelectionEnabled = false - chooser.isFileHidingEnabled = !showHiddenFiles - if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { - onDirChosen(chooser.selectedFile) - } else { - onDirChosen(null) - } - } -}