Skip to content

Commit dbee049

Browse files
committed
Refactor dialog components to use QPWMessageDialog for consistent error handling and update package structure for clarity
1 parent 71437f4 commit dbee049

16 files changed

Lines changed: 110 additions & 120 deletions

File tree

src/main/kotlin/com/github/cnrture/quickprojectwizard/common/Utils.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package com.github.cnrture.quickprojectwizard.common
33
import com.github.cnrture.quickprojectwizard.common.file.FileWriter
44
import com.github.cnrture.quickprojectwizard.common.file.ImportAnalyzer
55
import com.github.cnrture.quickprojectwizard.common.file.LibraryDependencyFinder
6+
import com.github.cnrture.quickprojectwizard.components.QPWMessageDialog
67
import com.github.cnrture.quickprojectwizard.data.FeatureTemplate
78
import com.github.cnrture.quickprojectwizard.data.ModuleTemplate
8-
import com.github.cnrture.quickprojectwizard.dialog.MessageDialog
99
import com.intellij.ide.BrowserUtil
1010
import com.intellij.ide.starters.local.GeneratorTemplateFile
1111
import com.intellij.notification.NotificationGroupManager
@@ -58,16 +58,16 @@ object Utils {
5858
file = File(projectRoot, cleanSelectedPath),
5959
featureName = featureName,
6060
packageName = packagePath.plus(".${featureName.lowercase()}"),
61-
showErrorDialog = { MessageDialog("Error: $it").show() },
61+
showErrorDialog = { QPWMessageDialog("Error: $it").show() },
6262
showSuccessDialog = {
63-
MessageDialog("Success").show()
63+
QPWMessageDialog("Success").show()
6464
val currentlySelectedFile = project.getCurrentlySelectedFile(selectedSrc)
6565
listOf(currentlySelectedFile).refreshFileSystem()
6666
},
6767
selectedTemplate = selectedTemplate
6868
)
6969
} catch (e: Exception) {
70-
MessageDialog("Error: ${e.message}").show()
70+
QPWMessageDialog("Error: ${e.message}").show()
7171
}
7272
}
7373

@@ -96,7 +96,7 @@ object Utils {
9696
if (settingsGradleFile != null) {
9797
val moduleName = moduleName.trim()
9898
if (!moduleName.startsWith(":")) {
99-
MessageDialog("Module name must start with ':' (e.g. ':home' or ':feature:home')").show()
99+
QPWMessageDialog("Module name must start with ':' (e.g. ':home' or ':feature:home')").show()
100100
return emptyList()
101101
}
102102

@@ -117,9 +117,9 @@ object Utils {
117117
settingsGradleFile = settingsGradleFile,
118118
modulePathAsString = moduleName,
119119
moduleType = moduleType,
120-
showErrorDialog = { MessageDialog(it).show() },
120+
showErrorDialog = { QPWMessageDialog(it).show() },
121121
showSuccessDialog = {
122-
MessageDialog("Module '$moduleName' created successfully").show()
122+
QPWMessageDialog("Module '$moduleName' created successfully").show()
123123

124124
val projectDir = File(project.basePath.orEmpty())
125125
VfsUtil.markDirtyAndRefresh(false, true, true, VfsUtil.findFileByIoFile(projectDir, true))
@@ -150,11 +150,11 @@ object Utils {
150150
)
151151
return filesCreated
152152
} else {
153-
MessageDialog("Couldn't find settings.gradle(.kts) file").show()
153+
QPWMessageDialog("Couldn't find settings.gradle(.kts) file").show()
154154
return emptyList()
155155
}
156156
} catch (e: Exception) {
157-
MessageDialog("Error: ${e.message}").show()
157+
QPWMessageDialog("Error: ${e.message}").show()
158158
return emptyList()
159159
}
160160
}
@@ -170,7 +170,7 @@ object Utils {
170170

171171
try {
172172
if (!sourceDir.exists() || !sourceDir.isDirectory) {
173-
MessageDialog("Source directory does not exist or is not a directory").show()
173+
QPWMessageDialog("Source directory does not exist or is not a directory").show()
174174
return
175175
}
176176

@@ -187,7 +187,7 @@ object Utils {
187187
}.toList()
188188

189189
if (sourceFiles.isEmpty()) {
190-
MessageDialog("No source files found to move in ${sourceDir.absolutePath}").show()
190+
QPWMessageDialog("No source files found to move in ${sourceDir.absolutePath}").show()
191191
return
192192
}
193193

@@ -258,9 +258,9 @@ object Utils {
258258
openNewModule(project, modulePath, movedFiles)
259259
}
260260

261-
MessageDialog("Moved ${movedFiles.size} files to new module").show()
261+
QPWMessageDialog("Moved ${movedFiles.size} files to new module").show()
262262
} catch (e: Exception) {
263-
MessageDialog("Error moving files: ${e.message}").show()
263+
QPWMessageDialog("Error moving files: ${e.message}").show()
264264
e.printStackTrace()
265265
}
266266
}
@@ -292,7 +292,7 @@ object Utils {
292292
val settingsFile = listOf(settingsGradleKtsPath, settingsGradlePath).firstOrNull {
293293
it.exists()
294294
} ?: run {
295-
MessageDialog("Can't find settings.gradle(.kts) file")
295+
QPWMessageDialog("Can't find settings.gradle(.kts) file")
296296
return null
297297
}
298298

src/main/kotlin/com/github/cnrture/quickprojectwizard/dialog/MessageDialog.kt renamed to src/main/kotlin/com/github/cnrture/quickprojectwizard/components/QPWMessageDialog.kt

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.cnrture.quickprojectwizard.dialog
1+
package com.github.cnrture.quickprojectwizard.components
22

33
import androidx.compose.foundation.layout.*
44
import androidx.compose.runtime.Composable
@@ -10,30 +10,27 @@ import androidx.compose.ui.text.style.TextAlign
1010
import androidx.compose.ui.unit.dp
1111
import androidx.compose.ui.unit.sp
1212
import com.github.cnrture.quickprojectwizard.common.Constants
13-
import com.github.cnrture.quickprojectwizard.components.QPWButton
14-
import com.github.cnrture.quickprojectwizard.components.QPWDialogWrapper
15-
import com.github.cnrture.quickprojectwizard.components.QPWText
1613
import com.github.cnrture.quickprojectwizard.theme.QPWTheme
1714

18-
class MessageDialog(private val message: String) : QPWDialogWrapper() {
15+
class QPWMessageDialog(private val message: String) : QPWDialogWrapper() {
1916

2017
@Composable
2118
override fun createDesign() {
2219
Column(
23-
modifier = Modifier.padding(vertical = 24.dp, horizontal = 64.dp),
24-
horizontalAlignment = Alignment.CenterHorizontally,
20+
modifier = Modifier.Companion.padding(vertical = 24.dp, horizontal = 64.dp),
21+
horizontalAlignment = Alignment.Companion.CenterHorizontally,
2522
verticalArrangement = Arrangement.Center,
2623
) {
2724
QPWText(
2825
text = message,
2926
color = QPWTheme.colors.white,
3027
style = TextStyle(
3128
fontSize = 16.sp,
32-
fontWeight = FontWeight.SemiBold,
33-
textAlign = TextAlign.Center,
29+
fontWeight = FontWeight.Companion.SemiBold,
30+
textAlign = TextAlign.Companion.Center,
3431
),
3532
)
36-
Spacer(modifier = Modifier.size(24.dp))
33+
Spacer(modifier = Modifier.Companion.size(24.dp))
3734
QPWButton(
3835
text = "Okay",
3936
onClick = { close(Constants.DEFAULT_EXIT_CODE) },

src/main/kotlin/com/github/cnrture/quickprojectwizard/toolwindow/QuickProjectWizardToolWindowFactory.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ import androidx.compose.ui.unit.sp
2323
import com.github.cnrture.quickprojectwizard.common.Constants
2424
import com.github.cnrture.quickprojectwizard.components.QPWActionCard
2525
import com.github.cnrture.quickprojectwizard.components.QPWActionCardType
26+
import com.github.cnrture.quickprojectwizard.components.QPWMessageDialog
2627
import com.github.cnrture.quickprojectwizard.components.QPWText
2728
import com.github.cnrture.quickprojectwizard.data.SettingsService
2829
import com.github.cnrture.quickprojectwizard.data.SettingsState
29-
import com.github.cnrture.quickprojectwizard.dialog.ExportSettingsDialog
30-
import com.github.cnrture.quickprojectwizard.dialog.MessageDialog
3130
import com.github.cnrture.quickprojectwizard.theme.QPWTheme
3231
import com.github.cnrture.quickprojectwizard.toolwindow.manager.apitester.ApiTesterContent
3332
import com.github.cnrture.quickprojectwizard.toolwindow.manager.colorpicker.ColorPickerContent
3433
import com.github.cnrture.quickprojectwizard.toolwindow.manager.featuregenerator.FeatureGeneratorContent
3534
import com.github.cnrture.quickprojectwizard.toolwindow.manager.formatter.FormatterContent
3635
import com.github.cnrture.quickprojectwizard.toolwindow.manager.modulegenerator.ModuleGeneratorContent
3736
import com.github.cnrture.quickprojectwizard.toolwindow.manager.settings.SettingsContent
37+
import com.github.cnrture.quickprojectwizard.toolwindow.manager.settings.dialog.ExportSettingsDialog
3838
import com.intellij.ide.BrowserUtil
3939
import com.intellij.openapi.application.ApplicationManager
4040
import com.intellij.openapi.components.service
@@ -228,7 +228,7 @@ class QuickProjectWizardToolWindowFactory : ToolWindowFactory {
228228
ExportSettingsDialog(
229229
settings = settings,
230230
onComplete = { success, message ->
231-
MessageDialog(message).show()
231+
QPWMessageDialog(message).show()
232232
}
233233
).show()
234234
}
@@ -393,10 +393,10 @@ class QuickProjectWizardToolWindowFactory : ToolWindowFactory {
393393
descriptor.title = "Import Settings"
394394
FileChooser.chooseFile(descriptor, project, null) { file ->
395395
if (settings.importFromFile(file.path)) {
396-
MessageDialog("Settings imported successfully!").show()
396+
QPWMessageDialog("Settings imported successfully!").show()
397397
onSuccess(settings.state)
398398
} else {
399-
MessageDialog("Failed to import settings. Please check the file format.").show()
399+
QPWMessageDialog("Failed to import settings. Please check the file format.").show()
400400
}
401401
}
402402
}

src/main/kotlin/com/github/cnrture/quickprojectwizard/action/FeatureGeneratorAction.kt renamed to src/main/kotlin/com/github/cnrture/quickprojectwizard/toolwindow/manager/featuregenerator/action/FeatureGeneratorAction.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
package com.github.cnrture.quickprojectwizard.action
1+
package com.github.cnrture.quickprojectwizard.toolwindow.manager.featuregenerator.action
22

3-
import com.github.cnrture.quickprojectwizard.dialog.FeatureGeneratorDialog
3+
import com.github.cnrture.quickprojectwizard.toolwindow.manager.featuregenerator.dialog.FeatureGeneratorDialog
44
import com.intellij.icons.AllIcons
55
import com.intellij.ide.actions.CreateElementActionBase
66
import com.intellij.openapi.actionSystem.AnActionEvent

src/main/kotlin/com/github/cnrture/quickprojectwizard/toolwindow/manager/featuregenerator/components/ConfigurationPanel.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,9 @@ import androidx.compose.ui.unit.dp
2121
import androidx.compose.ui.unit.sp
2222
import com.github.cnrture.quickprojectwizard.common.Utils
2323
import com.github.cnrture.quickprojectwizard.common.file.FileWriter
24-
import com.github.cnrture.quickprojectwizard.components.QPWActionCard
25-
import com.github.cnrture.quickprojectwizard.components.QPWActionCardType
26-
import com.github.cnrture.quickprojectwizard.components.QPWText
27-
import com.github.cnrture.quickprojectwizard.components.QPWTextField
24+
import com.github.cnrture.quickprojectwizard.components.*
2825
import com.github.cnrture.quickprojectwizard.data.FeatureTemplate
2926
import com.github.cnrture.quickprojectwizard.data.SettingsService
30-
import com.github.cnrture.quickprojectwizard.dialog.MessageDialog
3127
import com.github.cnrture.quickprojectwizard.theme.QPWTheme
3228
import com.intellij.openapi.application.ApplicationManager
3329
import com.intellij.openapi.components.service
@@ -73,9 +69,9 @@ fun ConfigurationPanel(
7369
fileWriter = fileWriter,
7470
selectedTemplate = selectedTemplate,
7571
)
76-
} ?: run { MessageDialog("Please select a feature template").show() }
72+
} ?: run { QPWMessageDialog("Please select a feature template").show() }
7773
} else {
78-
MessageDialog("Please fill out required values").show()
74+
QPWMessageDialog("Please fill out required values").show()
7975
}
8076
},
8177
)

0 commit comments

Comments
 (0)