11package com.joetr.modulemaker
22
3+ import androidx.compose.animation.AnimatedVisibility
34import androidx.compose.foundation.layout.Column
5+ import androidx.compose.foundation.layout.ExperimentalLayoutApi
6+ import androidx.compose.foundation.layout.FlowRow
47import androidx.compose.foundation.layout.Row
58import androidx.compose.foundation.layout.fillMaxSize
69import androidx.compose.foundation.layout.fillMaxWidth
@@ -21,6 +24,7 @@ import androidx.compose.material.Text
2124import androidx.compose.material.icons.Icons
2225import androidx.compose.material.icons.filled.Info
2326import androidx.compose.runtime.Composable
27+ import androidx.compose.runtime.mutableStateListOf
2428import androidx.compose.runtime.mutableStateOf
2529import androidx.compose.runtime.remember
2630import androidx.compose.ui.Alignment
@@ -53,12 +57,13 @@ import javax.swing.Action
5357import javax.swing.JComponent
5458
5559private const val WINDOW_WIDTH = 840
56- private const val WINDOW_HEIGHT = 600
60+ private const val WINDOW_HEIGHT = 800
5761private const val FILE_TREE_WIDTH = 300
5862private const val CONFIGURATION_PANEL_WIDTH = 540
5963
6064const val ANDROID = " Android"
61- const val KOTLIN = " Kotlin"
65+ const val MULTIPLATFORM = " Multiplatform"
66+ const val KOTLIN = " Kotlin / JVM"
6267
6368private const val DEFAULT_MODULE_NAME = " :repository:database (as an example)"
6469private const val DEFAULT_SRC_VALUE = " EMPTY"
@@ -82,8 +87,10 @@ class ModuleMakerDialogWrapper(
8287 private val addReadme = mutableStateOf(preferenceService.preferenceState.addReadme)
8388 private val addGitIgnore = mutableStateOf(preferenceService.preferenceState.addGitIgnore)
8489 private val moduleTypeSelection = mutableStateOf(ANDROID )
90+ private val platformTypeSelection = mutableStateOf(ANDROID )
8591 private val moduleName = mutableStateOf(" " )
8692 private val packageName = mutableStateOf(preferenceService.preferenceState.packageName)
93+ private val sourceSets = mutableStateListOf<String >()
8794
8895 // Segment's write key isn't really a secret
8996 private var analytics: Analytics = Analytics (" CNghGjhOHipwGB9YdWMBwkMTJbRFtizc" ) {
@@ -121,7 +128,8 @@ class ModuleMakerDialogWrapper(
121128 modifier = Modifier .height(startingHeight.value.dp).width(fileTreeWidth.value.dp)
122129 )
123130 ConfigurationPanel (
124- modifier = Modifier .height(startingHeight.value.dp).width(configurationPanelWidth.value.dp)
131+ modifier = Modifier .height(startingHeight.value.dp)
132+ .width(configurationPanelWidth.value.dp)
125133 )
126134 }
127135 }
@@ -222,6 +230,7 @@ class ModuleMakerDialogWrapper(
222230 )
223231 }
224232
233+ @OptIn(ExperimentalLayoutApi ::class )
225234 @Composable
226235 private fun ConfigurationPanel (
227236 modifier : Modifier = Modifier
@@ -295,6 +304,7 @@ class ModuleMakerDialogWrapper(
295304 val radioOptions = listOf (ANDROID , KOTLIN )
296305 val moduleTypeSelectionState = remember { moduleTypeSelection }
297306 Column {
307+ Text (" Module Type" )
298308 radioOptions.forEach { text ->
299309 Row (
300310 modifier = Modifier .selectable(
@@ -324,6 +334,85 @@ class ModuleMakerDialogWrapper(
324334 }
325335 }
326336
337+ val platformTypeRadioOptions = listOf (ANDROID , MULTIPLATFORM )
338+ val platformTypeRadioOptionsState = remember { platformTypeSelection }
339+ Column {
340+ Text (" Platform Type" )
341+ platformTypeRadioOptions.forEach { text ->
342+ Row (
343+ modifier = Modifier .selectable(
344+ selected = (text == platformTypeRadioOptionsState.value),
345+ onClick = {
346+ platformTypeRadioOptionsState.value = text
347+ }
348+ ).padding(end = 16 .dp),
349+ verticalAlignment = Alignment .CenterVertically
350+ ) {
351+ RadioButton (
352+ colors = RadioButtonDefaults .colors(
353+ selectedColor = MaterialTheme .colors.primary,
354+ unselectedColor = MaterialTheme .colors.primaryVariant
355+ ),
356+ selected = (text == platformTypeRadioOptionsState.value),
357+ onClick = {
358+ platformTypeRadioOptionsState.value = text
359+ }
360+ )
361+ Text (
362+ text = text,
363+ style = MaterialTheme .typography.body1.merge(),
364+ modifier = Modifier .padding(start = 8 .dp)
365+ )
366+ }
367+ }
368+
369+ val selectedSourceSets = remember {
370+ sourceSets
371+ }
372+
373+ AnimatedVisibility (
374+ platformTypeSelection.value == MULTIPLATFORM
375+ ) {
376+ Column {
377+ Text (modifier = Modifier .padding(vertical = 8 .dp), text = " Selected Source Sets: ${selectedSourceSets.joinToString(separator = " , " )} " )
378+
379+ FlowRow (Modifier .padding(vertical = 8 .dp)) {
380+ kotlinMultiplatformSourceSets.forEach { sourceSet ->
381+ LabelledCheckbox (
382+ label = sourceSet,
383+ checked = selectedSourceSets.contains(sourceSet),
384+ onCheckedChange = {
385+ if (it) {
386+ selectedSourceSets.add(sourceSet)
387+ } else {
388+ selectedSourceSets.remove(sourceSet)
389+ }
390+ }
391+ )
392+ }
393+ }
394+
395+ Text (" Test Source Sets" )
396+
397+ FlowRow (Modifier .padding(vertical = 8 .dp)) {
398+ kotlinMultiplatformTestSourceSets.forEach { sourceSet ->
399+ LabelledCheckbox (
400+ label = sourceSet,
401+ checked = selectedSourceSets.contains(sourceSet),
402+ onCheckedChange = {
403+ if (it) {
404+ selectedSourceSets.add(sourceSet)
405+ } else {
406+ selectedSourceSets.remove(sourceSet)
407+ }
408+ }
409+ )
410+ }
411+ }
412+ }
413+ }
414+ }
415+
327416 val packageNameState = remember { packageName }
328417 OutlinedTextField (
329418 label = { Text (" Package Name" ) },
@@ -420,7 +509,9 @@ class ModuleMakerDialogWrapper(
420509 packageName = packageName.value,
421510 addReadme = addReadme.value,
422511 addGitIgnore = addGitIgnore.value,
423- previewMode = previewMode
512+ previewMode = previewMode,
513+ platformType = platformTypeSelection.value,
514+ sourceSets = sourceSets.toList()
424515 )
425516
426517 return filesCreated
@@ -476,3 +567,7 @@ class ModuleMakerDialogWrapper(
476567 return path.split(File .separator).last()
477568 }
478569}
570+
571+ /*
572+ kotlin multiplatform template in settings
573+ create folders for each source set*/
0 commit comments