diff --git a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/MavenConfig.kt b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/MavenConfig.kt index e33d91a..8446f4e 100644 --- a/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/MavenConfig.kt +++ b/core/src/commonMain/kotlin/dev/inmo/kmppscriptbuilder/core/models/MavenConfig.kt @@ -6,13 +6,13 @@ const val defaultProjectName = "\${project.name}" const val defaultProjectDescription = "\${project.name}" @Serializable -sealed class GpgSigning { +sealed class GpgSigning(val name: String) { @Serializable - object Disabled : GpgSigning() + object Disabled : GpgSigning("Disabled") @Serializable - object Optional : GpgSigning() + object Optional : GpgSigning("Optional") @Serializable - object Enabled : GpgSigning() + object Enabled : GpgSigning("Enabled") } @Serializable diff --git a/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/BuilderView.kt b/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/BuilderView.kt index 3288142..cfa3d19 100644 --- a/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/BuilderView.kt +++ b/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/BuilderView.kt @@ -1,11 +1,13 @@ package dev.inmo.kmppscriptbuilder.desktop.views -import androidx.compose.foundation.Image -import androidx.compose.foundation.clickable +import androidx.compose.foundation.* import androidx.compose.foundation.layout.* +import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.* import androidx.compose.runtime.* import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.shadow +import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp import dev.inmo.kmppscriptbuilder.core.models.Config @@ -28,6 +30,34 @@ class BuilderView : View() { saveAvailableState = true } + @OptIn(ExperimentalFoundationApi::class) + @Composable + private fun createIcon( + tooltip: String, + resource: String, + onClick: () -> Unit + ) { + TooltipArea( + tooltip = { + Surface( + modifier = Modifier.shadow(4.dp), + color = MaterialTheme.colors.primarySurface, + shape = RoundedCornerShape(4.dp) + ) { + Text(tooltip, modifier = Modifier.padding(10.dp), color = MaterialTheme.colors.onPrimary) + } + } + ) { + IconButton(onClick) { + Image( + painter = painterResource(resource), + contentDescription = tooltip + ) + } + } + } + + @OptIn(ExperimentalFoundationApi::class) @Composable override fun build() { Box(Modifier.fillMaxSize()) { @@ -37,56 +67,28 @@ class BuilderView : View() { CommonText("Kotlin publication scripts builder", Modifier.clickable { println(config) }) }, actions = { - IconButton( - { - loadConfig()?.also { - config = it - } - } - ) { - Image( - painter = painterResource("images/open_file.svg"), - contentDescription = "Open file" - ) - } - - if (saveAvailableState) { - IconButton( - { - saveConfig(config) - } - ) { - Image( - painter = painterResource("images/save_file.svg"), - contentDescription = "Save file" - ) + createIcon("Open file", "images/open_file.svg") { + loadConfig()?.also { + config = it } } if (saveAvailableState) { - IconButton( - { - exportGradle(config) - } - ) { - Image( - painter = painterResource("images/export_gradle.svg"), - contentDescription = "Export Gradle script" - ) + createIcon("Save", "images/save_file.svg") { + saveConfig(config) } } - IconButton( - { - if (saveAs(config)) { - saveAvailableState = true - } + if (saveAvailableState) { + createIcon("Export Gradle script", "images/export_gradle.svg") { + exportGradle(config) + } + } + + createIcon("Save as", "images/save_as.svg") { + if (saveAs(config)) { + saveAvailableState = true } - ) { - Image( - painter = painterResource("images/save_as.svg"), - contentDescription = "Export Gradle script" - ) } } ) diff --git a/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/MavenInfoView.kt b/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/MavenInfoView.kt index 54f7fed..32c30c4 100644 --- a/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/MavenInfoView.kt +++ b/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/MavenInfoView.kt @@ -1,7 +1,12 @@ package dev.inmo.kmppscriptbuilder.desktop.views -import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.foundation.layout.* +import androidx.compose.material.* import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.layout.VerticalAlignmentLine +import androidx.compose.ui.unit.dp import dev.inmo.kmppscriptbuilder.core.models.* import dev.inmo.kmppscriptbuilder.desktop.utils.* @@ -45,6 +50,24 @@ class MavenInfoView : VerticalView("Project information") { // developersView.developers = value.developers } + @Composable + private fun addGpgSigningButton(gpgSigning: GpgSigning) { + if (gpgSignProperty == gpgSigning) { + Button({}, Modifier.padding(8.dp)) { + Text(gpgSigning.name) + } + } else { + OutlinedButton( + { + gpgSignProperty = gpgSigning + }, + Modifier.padding(8.dp) + ) { + Text(gpgSigning.name) + } + } + } + override val content: @Composable ColumnScope.() -> Unit = { CommonTextField( projectNameProperty, @@ -63,12 +86,12 @@ class MavenInfoView : VerticalView("Project information") { "Public project VCS URL (with .git)" ) { projectVcsUrlProperty = it } - -// SwitchWithLabel( -// "Include GPG Signing", -// includeGpgSignProperty, -// placeSwitchAtTheStart = true -// ) { includeGpgSignProperty = it } + Row(verticalAlignment = Alignment.CenterVertically) { + Text("Gpg Signing: ") + addGpgSigningButton(GpgSigning.Disabled) + addGpgSigningButton(GpgSigning.Optional) + addGpgSigningButton(GpgSigning.Enabled) + } SwitchWithLabel( "Include publication to MavenCentral", diff --git a/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/ProjectTypeView.kt b/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/ProjectTypeView.kt index 052b3a4..6a70c2f 100644 --- a/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/ProjectTypeView.kt +++ b/desktop/src/jvmMain/kotlin/dev/inmo/kmppscriptbuilder/desktop/views/ProjectTypeView.kt @@ -1,33 +1,40 @@ package dev.inmo.kmppscriptbuilder.desktop.views import androidx.compose.foundation.layout.* -import androidx.compose.material.Switch -import androidx.compose.material.Text +import androidx.compose.material.* import androidx.compose.runtime.* +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import dev.inmo.kmppscriptbuilder.core.models.* import dev.inmo.kmppscriptbuilder.desktop.utils.VerticalView class ProjectTypeView : VerticalView("Project type") { - private var projectTypeState by mutableStateOf(false) - private val calculatedProjectType: ProjectType - get() = if (projectTypeState) JVMProjectType else MultiplatformProjectType - var projectType: ProjectType - get() = calculatedProjectType - set(value) { - projectTypeState = value == JVMProjectType + var projectType by mutableStateOf(MultiplatformProjectType) + + @Composable + private fun addProjectTypeButton(newProjectType: ProjectType) { + if (projectType == newProjectType) { + Button({}, Modifier.padding(8.dp)) { + Text(newProjectType.name) + } + } else { + OutlinedButton( + { + projectType = newProjectType + }, + Modifier.padding(8.dp) + ) { + Text(newProjectType.name) + } } + } override val content: @Composable ColumnScope.() -> Unit = { - Row(horizontalArrangement = Arrangement.spacedBy(5.dp)) { - Text("Multiplatform", Modifier.alignByBaseline()) - Switch( - projectTypeState, - { projectTypeState = it }, - Modifier.padding(4.dp, 0.dp) - ) - Text("JVM", Modifier.alignByBaseline()) + Row(verticalAlignment = Alignment.CenterVertically) { + addProjectTypeButton(MultiplatformProjectType) + addProjectTypeButton(JVMProjectType) + addProjectTypeButton(JSProjectType) } } }