Skip to content

Commit c309d29

Browse files
committed
Refactor dialog components to use state management and improve UI consistency
1 parent 9d3f962 commit c309d29

5 files changed

Lines changed: 261 additions & 196 deletions

File tree

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.cnrture.quickprojectwizard.data
22

3+
import com.github.cnrture.quickprojectwizard.common.Constants
34
import kotlinx.serialization.Serializable
45

56
@Serializable
@@ -8,4 +9,13 @@ data class FeatureTemplate(
89
val name: String,
910
val fileTemplates: List<FileTemplate> = emptyList(),
1011
val isDefault: Boolean = false,
11-
)
12+
) {
13+
companion object {
14+
val EMPTY = FeatureTemplate(
15+
id = Constants.EMPTY,
16+
name = Constants.EMPTY,
17+
fileTemplates = emptyList(),
18+
isDefault = false
19+
)
20+
}
21+
}
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.github.cnrture.quickprojectwizard.data
22

3+
import com.github.cnrture.quickprojectwizard.common.Constants
34
import kotlinx.serialization.Serializable
45

56
@Serializable
@@ -8,4 +9,13 @@ data class ModuleTemplate(
89
val name: String,
910
val fileTemplates: List<FileTemplate> = emptyList(),
1011
val isDefault: Boolean = false,
11-
)
12+
) {
13+
companion object {
14+
val EMPTY = ModuleTemplate(
15+
id = Constants.EMPTY,
16+
name = Constants.EMPTY,
17+
fileTemplates = emptyList(),
18+
isDefault = false
19+
)
20+
}
21+
}

src/main/kotlin/com/github/cnrture/quickprojectwizard/toolwindow/manager/settings/SettingsContent.kt

Lines changed: 146 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import androidx.compose.ui.text.font.FontWeight
1717
import androidx.compose.ui.text.style.TextAlign
1818
import androidx.compose.ui.unit.dp
1919
import androidx.compose.ui.unit.sp
20+
import androidx.compose.ui.window.Dialog
21+
import androidx.compose.ui.window.DialogProperties
2022
import com.github.cnrture.quickprojectwizard.common.Constants
2123
import com.github.cnrture.quickprojectwizard.common.Utils
2224
import com.github.cnrture.quickprojectwizard.components.*
@@ -25,10 +27,10 @@ import com.github.cnrture.quickprojectwizard.data.ModuleTemplate
2527
import com.github.cnrture.quickprojectwizard.service.AnalyticsService
2628
import com.github.cnrture.quickprojectwizard.service.SettingsService
2729
import com.github.cnrture.quickprojectwizard.theme.QPWTheme
28-
import com.github.cnrture.quickprojectwizard.toolwindow.manager.settings.dialog.FeatureTemplateCreatorDialog
29-
import com.github.cnrture.quickprojectwizard.toolwindow.manager.settings.dialog.FeatureTemplateEditorDialog
30-
import com.github.cnrture.quickprojectwizard.toolwindow.manager.settings.dialog.TemplateCreatorDialog
31-
import com.github.cnrture.quickprojectwizard.toolwindow.manager.settings.dialog.TemplateEditorDialog
30+
import com.github.cnrture.quickprojectwizard.toolwindow.manager.settings.dialog.FeatureTemplateCreatorContent
31+
import com.github.cnrture.quickprojectwizard.toolwindow.manager.settings.dialog.FeatureTemplateEditorContent
32+
import com.github.cnrture.quickprojectwizard.toolwindow.manager.settings.dialog.TemplateCreatorContent
33+
import com.github.cnrture.quickprojectwizard.toolwindow.manager.settings.dialog.TemplateEditorContent
3234
import com.intellij.openapi.project.Project
3335

3436
@Composable
@@ -240,6 +242,11 @@ private fun ModuleTemplatesTab(
240242
onSetDefault: (ModuleTemplate) -> Unit,
241243
onImport: () -> Unit,
242244
) {
245+
var isCreateDialogVisible by remember { mutableStateOf(Pair(false, ModuleTemplate.EMPTY)) }
246+
var isEditDialogVisible by remember { mutableStateOf(Pair(false, ModuleTemplate.EMPTY)) }
247+
val settings = SettingsService.getInstance()
248+
val analyticsService = AnalyticsService.getInstance()
249+
243250
Column(
244251
modifier = Modifier.fillMaxSize(),
245252
verticalArrangement = Arrangement.spacedBy(16.dp)
@@ -265,7 +272,7 @@ private fun ModuleTemplatesTab(
265272
icon = Icons.Rounded.Add,
266273
type = QPWActionCardType.SMALL,
267274
actionColor = QPWTheme.colors.green,
268-
onClick = { TemplateCreatorDialog(onRefreshTriggered = onRefreshTriggered).show() }
275+
onClick = { isCreateDialogVisible = Pair(true, ModuleTemplate.EMPTY) }
269276
)
270277
QPWActionCard(
271278
title = "Import",
@@ -281,7 +288,7 @@ private fun ModuleTemplatesTab(
281288
ModuleTemplateCard(
282289
template = template,
283290
defaultTemplateId = defaultTemplateId,
284-
onEdit = { TemplateEditorDialog(template, onRefreshTriggered).show() },
291+
onEdit = { isEditDialogVisible = Pair(true, template) },
285292
onDelete = { if (!template.isDefault) onTemplateDelete(template) },
286293
onSetDefault = { onSetDefault(template) },
287294
onExport = {
@@ -291,6 +298,69 @@ private fun ModuleTemplatesTab(
291298
}
292299
)
293300
}
301+
302+
if (isEditDialogVisible.first) {
303+
Dialog(
304+
onDismissRequest = {},
305+
properties = DialogProperties(
306+
dismissOnBackPress = false,
307+
dismissOnClickOutside = false,
308+
usePlatformDefaultWidth = false,
309+
)
310+
) {
311+
TemplateEditorContent(
312+
template = isEditDialogVisible.second,
313+
onCancelClick = {
314+
onRefreshTriggered()
315+
isEditDialogVisible = Pair(false, ModuleTemplate.EMPTY)
316+
},
317+
onApplyClick = { updatedTemplate ->
318+
settings.saveTemplate(updatedTemplate)
319+
},
320+
onOkayClick = { updatedTemplate ->
321+
settings.saveTemplate(updatedTemplate)
322+
analyticsService.track("module_template_updated")
323+
Utils.showInfo(
324+
title = "Quick Project Wizard",
325+
message = "Module template '${updatedTemplate.name}' updated successfully!",
326+
)
327+
onRefreshTriggered()
328+
isEditDialogVisible = Pair(false, ModuleTemplate.EMPTY)
329+
},
330+
)
331+
}
332+
}
333+
334+
if (isCreateDialogVisible.first) {
335+
Dialog(
336+
onDismissRequest = {},
337+
properties = DialogProperties(
338+
dismissOnBackPress = false,
339+
dismissOnClickOutside = false,
340+
usePlatformDefaultWidth = false,
341+
)
342+
) {
343+
TemplateCreatorContent(
344+
onCancelClick = {
345+
onRefreshTriggered()
346+
isCreateDialogVisible = Pair(false, ModuleTemplate.EMPTY)
347+
},
348+
onApplyClick = { template ->
349+
settings.saveTemplate(template)
350+
},
351+
onOkayClick = { template ->
352+
settings.saveTemplate(template)
353+
analyticsService.track("module_template_added")
354+
Utils.showInfo(
355+
title = "Quick Project Wizard",
356+
message = "Module template '${template.name}' added successfully!",
357+
)
358+
onRefreshTriggered()
359+
isCreateDialogVisible = Pair(false, ModuleTemplate.EMPTY)
360+
}
361+
)
362+
}
363+
}
294364
}
295365
}
296366

@@ -486,6 +556,11 @@ private fun FeatureTemplatesTab(
486556
onSetDefault: (FeatureTemplate) -> Unit,
487557
onImport: () -> Unit,
488558
) {
559+
var isCreateDialogVisible by remember { mutableStateOf(Pair(false, FeatureTemplate.EMPTY)) }
560+
var isEditDialogVisible by remember { mutableStateOf(Pair(false, FeatureTemplate.EMPTY)) }
561+
val settings = SettingsService.getInstance()
562+
val analyticsService = AnalyticsService.getInstance()
563+
489564
Column(
490565
modifier = Modifier.fillMaxSize(),
491566
verticalArrangement = Arrangement.spacedBy(16.dp)
@@ -511,7 +586,7 @@ private fun FeatureTemplatesTab(
511586
icon = Icons.Rounded.Add,
512587
type = QPWActionCardType.SMALL,
513588
actionColor = QPWTheme.colors.green,
514-
onClick = { FeatureTemplateCreatorDialog(onRefreshTriggered).show() }
589+
onClick = { isCreateDialogVisible = Pair(true, FeatureTemplate.EMPTY) }
515590
)
516591
QPWActionCard(
517592
title = "Import",
@@ -527,7 +602,7 @@ private fun FeatureTemplatesTab(
527602
FeatureTemplateCard(
528603
template = template,
529604
defaultTemplateId = defaultTemplateId,
530-
onEdit = { FeatureTemplateEditorDialog(template, onRefreshTriggered).show() },
605+
onEdit = { isEditDialogVisible = Pair(true, template) },
531606
onDelete = { if (!template.isDefault) onTemplateDelete(template) },
532607
onSetDefault = { onSetDefault(template) },
533608
onExport = {
@@ -537,6 +612,69 @@ private fun FeatureTemplatesTab(
537612
}
538613
)
539614
}
615+
616+
if (isEditDialogVisible.first) {
617+
Dialog(
618+
onDismissRequest = {},
619+
properties = DialogProperties(
620+
dismissOnBackPress = false,
621+
dismissOnClickOutside = false,
622+
usePlatformDefaultWidth = false,
623+
)
624+
) {
625+
FeatureTemplateEditorContent(
626+
template = isEditDialogVisible.second,
627+
onCancelClick = {
628+
onRefreshTriggered()
629+
isEditDialogVisible = Pair(false, FeatureTemplate.EMPTY)
630+
},
631+
onApplyClick = { updatedTemplate ->
632+
settings.saveFeatureTemplate(updatedTemplate)
633+
},
634+
onOkayClick = { updatedTemplate ->
635+
settings.saveFeatureTemplate(updatedTemplate)
636+
analyticsService.track("feature_template_updated")
637+
Utils.showInfo(
638+
title = "Quick Project Wizard",
639+
message = "Feature template '${updatedTemplate.name}' updated successfully!",
640+
)
641+
onRefreshTriggered()
642+
isEditDialogVisible = Pair(false, FeatureTemplate.EMPTY)
643+
},
644+
)
645+
}
646+
}
647+
648+
if (isCreateDialogVisible.first) {
649+
Dialog(
650+
onDismissRequest = {},
651+
properties = DialogProperties(
652+
dismissOnBackPress = false,
653+
dismissOnClickOutside = false,
654+
usePlatformDefaultWidth = false,
655+
)
656+
) {
657+
FeatureTemplateCreatorContent(
658+
onCancelClick = {
659+
onRefreshTriggered()
660+
isCreateDialogVisible = Pair(false, FeatureTemplate.EMPTY)
661+
},
662+
onApplyClick = { template ->
663+
settings.saveFeatureTemplate(template)
664+
},
665+
onOkayClick = { template ->
666+
settings.saveFeatureTemplate(template)
667+
analyticsService.track("feature_template_added")
668+
Utils.showInfo(
669+
title = "Quick Project Wizard",
670+
message = "Feature template '${template.name}' added successfully!",
671+
)
672+
onRefreshTriggered()
673+
isCreateDialogVisible = Pair(false, FeatureTemplate.EMPTY)
674+
}
675+
)
676+
}
677+
}
540678
}
541679
}
542680

0 commit comments

Comments
 (0)