Skip to content

Commit

Permalink
Show Export path and package in settings, make path relative to the c…
Browse files Browse the repository at this point in the history
…urrent project
  • Loading branch information
egorikftp committed Sep 24, 2024
1 parent 88c0bd4 commit cd8e167
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.github.composegears.valkyrie.ui.foundation

import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import io.github.composegears.valkyrie.ui.foundation.theme.PreviewTheme

@Composable
fun InfoItem(
title: String,
description: String,
modifier: Modifier = Modifier,
) {
Column(modifier = modifier.padding(vertical = 8.dp)) {
Text(
text = title,
style = MaterialTheme.typography.bodyMedium,
)
Text(
text = description,
style = MaterialTheme.typography.labelSmall,
color = LocalContentColor.current.dim(),
)
}
}

@Preview
@Composable
private fun PreviewInfoItem() = PreviewTheme {
InfoItem(
title = "Title",
description = "Description",
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.github.composegears.valkyrie.ui.platform

import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalInspectionMode
import com.intellij.openapi.project.ProjectManager

@Composable
fun rememberCurrentProject(): CurrentProject {
if (LocalInspectionMode.current) return NoOpCurrentProject

return CurrentProjectImpl
}

interface CurrentProject {
val path: String?
}

private object NoOpCurrentProject : CurrentProject {
override val path: String? = null
}

private object CurrentProjectImpl : CurrentProject {

override val path: String?
get() = ProjectManager.getInstance().openProjects.firstOrNull()?.basePath
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import io.github.composegears.valkyrie.ui.foundation.DragAndDropBox
import io.github.composegears.valkyrie.ui.foundation.InfoItem
import io.github.composegears.valkyrie.ui.foundation.VerticalSpacer
import io.github.composegears.valkyrie.ui.foundation.icons.Folder
import io.github.composegears.valkyrie.ui.foundation.icons.ValkyrieIcons
import io.github.composegears.valkyrie.ui.foundation.theme.PreviewTheme
import io.github.composegears.valkyrie.ui.platform.picker.rememberDirectoryPicker
import io.github.composegears.valkyrie.ui.platform.rememberCurrentProject
import io.github.composegears.valkyrie.ui.platform.rememberDragAndDropFolderHandler
import io.github.composegears.valkyrie.ui.screen.mode.iconpack.newpack.ui.model.NewPackAction
import io.github.composegears.valkyrie.ui.screen.mode.iconpack.newpack.ui.model.NewPackAction.SaveDestination
Expand Down Expand Up @@ -84,33 +85,21 @@ fun ChoosePackDirectory(
VerticalSpacer(36.dp)
Column(
modifier = Modifier.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(24.dp),
verticalArrangement = Arrangement.spacedBy(16.dp),
) {
if (state.iconPackDestination.isNotEmpty()) {
Column {
Text(
text = "Export path:",
style = MaterialTheme.typography.bodyMedium,
)
Text(
text = state.iconPackDestination,
textDecoration = TextDecoration.Underline,
style = MaterialTheme.typography.labelSmall,
)
}
val currentProject = rememberCurrentProject()

InfoItem(
title = "Export path",
description = "~${state.iconPackDestination.replace(currentProject.path.orEmpty(), "")}",
)
}
if (state.predictedPackage.isNotEmpty()) {
Column {
Text(
text = "Predicted package:",
style = MaterialTheme.typography.bodyMedium,
)
Text(
textDecoration = TextDecoration.Underline,
text = state.predictedPackage,
style = MaterialTheme.typography.labelSmall,
)
}
InfoItem(
title = "Predicted package",
description = state.predictedPackage.ifEmpty { "Not found" },
)
}
}
VerticalSpacer(16.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,21 @@ import com.composegears.tiamat.NavController
import com.composegears.tiamat.koin.koinSharedTiamatViewModel
import com.composegears.tiamat.navController
import com.composegears.tiamat.navDestination
import io.github.composegears.valkyrie.generator.imagevector.OutputFormat
import io.github.composegears.valkyrie.settings.InMemorySettings
import io.github.composegears.valkyrie.ui.domain.model.Mode
import io.github.composegears.valkyrie.settings.ValkyriesSettings
import io.github.composegears.valkyrie.ui.domain.model.Mode.IconPack
import io.github.composegears.valkyrie.ui.domain.model.Mode.Simple
import io.github.composegears.valkyrie.ui.domain.model.Mode.Unspecified
import io.github.composegears.valkyrie.ui.foundation.InfoItem
import io.github.composegears.valkyrie.ui.foundation.VerticalSpacer
import io.github.composegears.valkyrie.ui.foundation.dim
import io.github.composegears.valkyrie.ui.foundation.disabled
import io.github.composegears.valkyrie.ui.foundation.icons.PlayForward
import io.github.composegears.valkyrie.ui.foundation.icons.ValkyrieIcons
import io.github.composegears.valkyrie.ui.foundation.rememberMutableState
import io.github.composegears.valkyrie.ui.foundation.theme.PreviewTheme
import io.github.composegears.valkyrie.ui.platform.rememberCurrentProject
import io.github.composegears.valkyrie.ui.screen.intro.IntroScreen
import io.github.composegears.valkyrie.ui.screen.settings.SettingsViewModel
import org.koin.compose.koinInject
Expand All @@ -60,7 +63,7 @@ val GeneralSettingsScreen by navDestination<Unit> {
var showClearSettingsDialog by rememberMutableState { false }

GeneralSettingsUi(
mode = settings.mode,
settings = settings,
onClearSettings = {
showClearSettingsDialog = true
},
Expand Down Expand Up @@ -92,13 +95,19 @@ private fun openIntro(navController: NavController) {

@Composable
private fun GeneralSettingsUi(
mode: Mode,
settings: ValkyriesSettings,
onClearSettings: () -> Unit,
modifier: Modifier = Modifier,
onChangeMode: () -> Unit,
) {
val mode = settings.mode
val initialMode = remember { mode }
val currentMode = remember(mode) { if (mode == Unspecified) initialMode else mode }
val currentMode = remember(mode) {
when (mode) {
Unspecified -> initialMode
else -> mode
}
}

Column(modifier = modifier.fillMaxWidth()) {
VerticalSpacer(16.dp)
Expand All @@ -116,7 +125,10 @@ private fun GeneralSettingsUi(
IconPack -> "IconPack"
Unspecified -> "Unspecified"
}
Text(text = "Current mode: $name")
Text(
style = MaterialTheme.typography.bodyMedium,
text = "Current mode: $name",
)
},
supportingContent = {
Text(
Expand All @@ -136,6 +148,7 @@ private fun GeneralSettingsUi(
horizontalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
modifier = Modifier.padding(bottom = 4.dp),
text = "Change",
color = tint,
)
Expand All @@ -147,7 +160,23 @@ private fun GeneralSettingsUi(
}
},
)
VerticalSpacer(24.dp)
val currentProject = rememberCurrentProject()

InfoItem(
modifier = Modifier.padding(horizontal = 24.dp),
title = "Export path",
description = when {
settings.iconPackDestination.isEmpty() -> "Not specified"
else -> "~${settings.iconPackDestination.replace(currentProject.path.orEmpty(), "")}"
},
)
VerticalSpacer(16.dp)
InfoItem(
modifier = Modifier.padding(horizontal = 24.dp),
title = "Package",
description = settings.packageName.ifEmpty { "Not specified" },
)
VerticalSpacer(36.dp)
SectionTitle(name = "Danger zone")
TextButton(
modifier = Modifier.padding(horizontal = 12.dp),
Expand Down Expand Up @@ -215,7 +244,16 @@ private fun ClearSettingsDialog(
@Composable
private fun GeneralSettingsPreview() = PreviewTheme(alignment = Alignment.TopStart) {
GeneralSettingsUi(
mode = Unspecified,
settings = ValkyriesSettings(
mode = Simple,
packageName = "io.github.composegears.valkyrie",
iconPackName = "ValkyrieIcons",
iconPackDestination = "path/to/export",
nestedPacks = emptyList(),
outputFormat = OutputFormat.BackingProperty,
generatePreview = false,
showImageVectorPreview = true,
),
onChangeMode = {},
onClearSettings = {},
)
Expand Down

0 comments on commit cd8e167

Please sign in to comment.