@@ -13,50 +13,58 @@ import androidx.compose.ui.text.TextStyle
1313import androidx.compose.ui.text.font.FontWeight
1414import androidx.compose.ui.unit.dp
1515import androidx.compose.ui.unit.sp
16+ import com.github.cnrture.quickprojectwizard.common.Constants
17+ import com.github.cnrture.quickprojectwizard.common.Utils
1618import com.github.cnrture.quickprojectwizard.components.*
1719import com.github.cnrture.quickprojectwizard.data.FeatureTemplate
1820import com.github.cnrture.quickprojectwizard.data.FileTemplate
1921import com.github.cnrture.quickprojectwizard.data.ModuleTemplate
22+ import com.github.cnrture.quickprojectwizard.service.AnalyticsService
2023import com.github.cnrture.quickprojectwizard.service.SettingsService
2124import com.github.cnrture.quickprojectwizard.theme.QPWTheme
2225import com.github.cnrture.quickprojectwizard.toolwindow.manager.settings.component.FileTemplateEditor
23- import com.intellij.openapi.application.ApplicationManager
24- import com.intellij.openapi.components.service
2526import java.util.*
2627
2728class TemplateCreatorDialog (
28- private val onTemplateCreated : (ModuleTemplate ) -> Unit ,
29+ private val onRefreshTriggered : () -> Unit ,
2930) : QPWDialogWrapper(800 , 1200 , modal = false ) {
3031
32+ val settings = SettingsService .getInstance()
33+ val analyticsService = AnalyticsService .getInstance()
34+
3135 @Composable
3236 override fun createDesign () {
3337 TemplateCreatorContent (
34- onSave = { template ->
35- onTemplateCreated(template)
36- saveTemplateToSettings(template)
38+ onCancelClick = {
39+ onRefreshTriggered()
3740 close(0 )
3841 },
39- onCancel = {
42+ onApplyClick = { template ->
43+ settings.saveTemplate(template)
44+ },
45+ onOkayClick = { template ->
46+ settings.saveTemplate(template)
47+ analyticsService.track(" module_template_added" )
48+ Utils .showInfo(
49+ title = " Quick Project Wizard" ,
50+ message = " Module template '${template.name} ' added successfully!" ,
51+ )
52+ onRefreshTriggered()
4053 close(1 )
4154 }
4255 )
4356 }
44-
45- private fun saveTemplateToSettings (template : ModuleTemplate ) {
46- val settingsService = service<SettingsService >()
47- ApplicationManager .getApplication().invokeLater {
48- settingsService.saveTemplate(template)
49- }
50- }
5157}
5258
5359@Composable
5460private fun TemplateCreatorContent (
55- onSave : (ModuleTemplate ) -> Unit ,
56- onCancel : () -> Unit ,
61+ onCancelClick : () -> Unit ,
62+ onApplyClick : (ModuleTemplate ) -> Unit ,
63+ onOkayClick : (ModuleTemplate ) -> Unit ,
5764) {
5865 var templateName by remember { mutableStateOf(" " ) }
5966 val fileTemplates = remember { mutableStateListOf<FileTemplate >() }
67+ var id by remember { mutableStateOf(Constants .EMPTY ) }
6068
6169 Column (
6270 modifier = Modifier
@@ -150,63 +158,88 @@ private fun TemplateCreatorContent(
150158 title = " Cancel" ,
151159 type = QPWActionCardType .MEDIUM ,
152160 actionColor = QPWTheme .colors.lightGray,
153- onClick = onCancel
161+ onClick = onCancelClick
154162 )
155163
156164 QPWActionCard (
157- title = " Add Template" ,
158- icon = Icons .Rounded .Add ,
165+ title = " Apply" ,
159166 type = QPWActionCardType .MEDIUM ,
160167 actionColor = QPWTheme .colors.green,
168+ isEnabled = templateName.isNotBlank() && fileTemplates.any { it.fileName.isNotBlank() },
161169 onClick = {
162170 if (templateName.isNotBlank()) {
163171 val template = ModuleTemplate (
164- id = UUID .randomUUID().toString(),
172+ id = id.ifEmpty { UUID .randomUUID().toString(). apply { id = this } } ,
165173 name = templateName,
166174 fileTemplates = fileTemplates.filter { it.fileName.isNotBlank() },
167175 isDefault = false
168176 )
169- onSave (template)
177+ onApplyClick (template)
170178 }
171179 }
172180 )
181+
182+ QPWActionCard (
183+ title = " Okay" ,
184+ type = QPWActionCardType .MEDIUM ,
185+ actionColor = QPWTheme .colors.green,
186+ isEnabled = templateName.isNotBlank() && fileTemplates.any { it.fileName.isNotBlank() },
187+ onClick = {
188+ if (templateName.isNotBlank()) {
189+ val template = ModuleTemplate (
190+ id = id.ifEmpty { UUID .randomUUID().toString().apply { id = this } },
191+ name = templateName,
192+ fileTemplates = fileTemplates.filter { it.fileName.isNotBlank() },
193+ isDefault = false
194+ )
195+ onOkayClick(template)
196+ }
197+ },
198+ )
173199 }
174200 }
175201}
176202
177203class FeatureTemplateCreatorDialog (
178- private val onTemplateCreated : (FeatureTemplate ) -> Unit ,
204+ private val onRefreshTriggered : () -> Unit ,
179205) : QPWDialogWrapper(800 , 1200 , modal = false ) {
180206
207+ val settings = SettingsService .getInstance()
208+ val analyticsService = AnalyticsService .getInstance()
209+
181210 @Composable
182211 override fun createDesign () {
183212 FeatureTemplateCreatorContent (
184- onSave = { template ->
185- onTemplateCreated(template)
186- saveTemplateToSettings(template)
213+ onCancelClick = {
214+ onRefreshTriggered()
187215 close(0 )
188216 },
189- onCancel = {
217+ onApplyClick = { template ->
218+ settings.saveFeatureTemplate(template)
219+ },
220+ onOkayClick = { template ->
221+ settings.saveFeatureTemplate(template)
222+ analyticsService.track(" feature_template_added" )
223+ Utils .showInfo(
224+ title = " Quick Project Wizard" ,
225+ message = " Feature template '${template.name} ' added successfully!" ,
226+ )
227+ onRefreshTriggered()
190228 close(1 )
191229 }
192230 )
193231 }
194-
195- private fun saveTemplateToSettings (template : FeatureTemplate ) {
196- val settingsService = service<SettingsService >()
197- ApplicationManager .getApplication().invokeLater {
198- settingsService.saveFeatureTemplate(template)
199- }
200- }
201232}
202233
203234@Composable
204235private fun FeatureTemplateCreatorContent (
205- onSave : (FeatureTemplate ) -> Unit ,
206- onCancel : () -> Unit ,
236+ onCancelClick : () -> Unit ,
237+ onApplyClick : (FeatureTemplate ) -> Unit ,
238+ onOkayClick : (FeatureTemplate ) -> Unit ,
207239) {
208240 var templateName by remember { mutableStateOf(" " ) }
209241 val fileTemplates = remember { mutableStateListOf<FileTemplate >() }
242+ var id by remember { mutableStateOf(Constants .EMPTY ) }
210243
211244 Column (
212245 modifier = Modifier
@@ -300,25 +333,43 @@ private fun FeatureTemplateCreatorContent(
300333 title = " Cancel" ,
301334 type = QPWActionCardType .MEDIUM ,
302335 actionColor = QPWTheme .colors.lightGray,
303- onClick = onCancel
336+ onClick = onCancelClick
304337 )
305338
306339 QPWActionCard (
307- title = " Add Template" ,
308- icon = Icons .Rounded .Add ,
340+ title = " Apply" ,
309341 type = QPWActionCardType .MEDIUM ,
310342 actionColor = QPWTheme .colors.green,
343+ isEnabled = templateName.isNotBlank() && fileTemplates.any { it.fileName.isNotBlank() },
311344 onClick = {
312345 if (templateName.isNotBlank()) {
313346 val template = FeatureTemplate (
314- id = UUID .randomUUID().toString(),
347+ id = id.ifEmpty { UUID .randomUUID().toString(). apply { id = this } } ,
315348 name = templateName,
316349 fileTemplates = fileTemplates.filter { it.fileName.isNotBlank() },
317350 isDefault = false
318351 )
319- onSave (template)
352+ onApplyClick (template)
320353 }
321- }
354+ },
355+ )
356+
357+ QPWActionCard (
358+ title = " Okay" ,
359+ type = QPWActionCardType .MEDIUM ,
360+ actionColor = QPWTheme .colors.green,
361+ isEnabled = templateName.isNotBlank() && fileTemplates.any { it.fileName.isNotBlank() },
362+ onClick = {
363+ if (templateName.isNotBlank()) {
364+ val template = FeatureTemplate (
365+ id = id.ifEmpty { UUID .randomUUID().toString().apply { id = this } },
366+ name = templateName,
367+ fileTemplates = fileTemplates.filter { it.fileName.isNotBlank() },
368+ isDefault = false
369+ )
370+ onOkayClick(template)
371+ }
372+ },
322373 )
323374 }
324375 }
0 commit comments