Skip to content

Commit

Permalink
Use FileKit dir picker on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Sep 5, 2024
1 parent 75632fd commit ba53d50
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -138,15 +137,13 @@ 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(
description = "Gradle User Home",
state = gradleUserHome,
defaultState = System.getProperty("user.home") + "/.gradle",
isError = !isGradleUserHomeValid,
showHiddenFiles = true,
showSnackbar = { message -> scope.launch { snackbarState.showSnackbar(message) } },
)
GradleDistributionField(state = gradleDistSource)
Expand Down Expand Up @@ -270,7 +267,6 @@ private fun DirectoryField(
defaultState: String? = null,
readOnly: Boolean = false,
isError: Boolean = false,
showHiddenFiles: Boolean = false,
showSnackbar: (message: String) -> Unit,
) {
BuildTextField(
Expand All @@ -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<String>,
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<String>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -83,38 +87,13 @@ 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)
}
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,
Expand Down

This file was deleted.

0 comments on commit ba53d50

Please sign in to comment.