Skip to content

Commit ce6581a

Browse files
committed
Refactor notification handling to use Utils.showInfo for user messages
1 parent 72b5fdf commit ce6581a

8 files changed

Lines changed: 125 additions & 76 deletions

File tree

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

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ 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
76
import com.github.cnrture.quickprojectwizard.data.FeatureTemplate
87
import com.github.cnrture.quickprojectwizard.data.ModuleTemplate
98
import com.github.cnrture.quickprojectwizard.data.PluginListItem
109
import com.github.cnrture.quickprojectwizard.service.AnalyticsService
1110
import com.intellij.ide.BrowserUtil
1211
import com.intellij.ide.starters.local.GeneratorTemplateFile
12+
import com.intellij.notification.NotificationDisplayType
1313
import com.intellij.notification.NotificationGroupManager
1414
import com.intellij.notification.NotificationType
1515
import com.intellij.openapi.actionSystem.AnAction
@@ -67,17 +67,28 @@ object Utils {
6767
file = File(projectRoot, cleanSelectedPath),
6868
featureName = featureName,
6969
packageName = packagePath.plus(".${featureName.lowercase()}"),
70-
showErrorDialog = { QPWMessageDialog("Error: $it").show() },
70+
showErrorDialog = {
71+
showInfo(
72+
message = "Error creating feature: $it",
73+
type = NotificationType.ERROR
74+
)
75+
},
7176
showSuccessDialog = {
7277
analyticsService.track("${from}_feature_created")
73-
QPWMessageDialog("Success").show()
78+
showInfo(
79+
message = "Feature '$featureName' created successfully",
80+
type = NotificationType.INFORMATION
81+
)
7482
val currentlySelectedFile = project.getCurrentlySelectedFile(selectedSrc)
7583
listOf(currentlySelectedFile).refreshFileSystem()
7684
},
7785
selectedTemplate = selectedTemplate
7886
)
7987
} catch (e: Exception) {
80-
QPWMessageDialog("Error: ${e.message}").show()
88+
showInfo(
89+
message = "Error creating feature: ${e.message}",
90+
type = NotificationType.ERROR
91+
)
8192
}
8293
}
8394

@@ -108,7 +119,10 @@ object Utils {
108119
if (settingsGradleFile != null) {
109120
val moduleName = moduleName.trim()
110121
if (!moduleName.startsWith(":")) {
111-
QPWMessageDialog("Module name must start with ':' (e.g. ':home' or ':feature:home')").show()
122+
showInfo(
123+
message = "Module name must start with ':' (e.g. ':home' or ':feature:home')",
124+
type = NotificationType.ERROR
125+
)
112126
return emptyList()
113127
}
114128

@@ -131,10 +145,18 @@ object Utils {
131145
modulePathAsString = moduleName,
132146
name = name,
133147
moduleType = moduleType,
134-
showErrorDialog = { QPWMessageDialog(it).show() },
148+
showErrorDialog = {
149+
showInfo(
150+
message = "Error creating module: $it",
151+
type = NotificationType.ERROR
152+
)
153+
},
135154
showSuccessDialog = {
136155
analyticsService.track("${from}_module_created")
137-
QPWMessageDialog("Module '$moduleName' created successfully").show()
156+
showInfo(
157+
message = "Module '$moduleName' created successfully",
158+
type = NotificationType.INFORMATION
159+
)
138160

139161
val projectDir = File(project.basePath.orEmpty())
140162
VfsUtil.markDirtyAndRefresh(false, true, true, VfsUtil.findFileByIoFile(projectDir, true))
@@ -169,11 +191,17 @@ object Utils {
169191
)
170192
return filesCreated
171193
} else {
172-
QPWMessageDialog("Couldn't find settings.gradle(.kts) file").show()
194+
showInfo(
195+
message = "Couldn't find settings.gradle(.kts) file",
196+
type = NotificationType.ERROR
197+
)
173198
return emptyList()
174199
}
175200
} catch (e: Exception) {
176-
QPWMessageDialog("Error: ${e.message}").show()
201+
showInfo(
202+
message = "Error creating module: ${e.message}",
203+
type = NotificationType.ERROR
204+
)
177205
return emptyList()
178206
}
179207
}
@@ -189,7 +217,10 @@ object Utils {
189217

190218
try {
191219
if (!sourceDir.exists() || !sourceDir.isDirectory) {
192-
QPWMessageDialog("Source directory does not exist or is not a directory").show()
220+
showInfo(
221+
message = "Source directory does not exist or is not a directory",
222+
type = NotificationType.ERROR
223+
)
193224
return
194225
}
195226

@@ -206,7 +237,10 @@ object Utils {
206237
}.toList()
207238

208239
if (sourceFiles.isEmpty()) {
209-
QPWMessageDialog("No source files found to move in ${sourceDir.absolutePath}").show()
240+
showInfo(
241+
message = "No source files found to move in ${sourceDir.absolutePath}",
242+
type = NotificationType.WARNING
243+
)
210244
return
211245
}
212246

@@ -276,10 +310,15 @@ object Utils {
276310
ApplicationManager.getApplication().invokeLater {
277311
openNewModule(project, modulePath, movedFiles)
278312
}
279-
280-
QPWMessageDialog("Moved ${movedFiles.size} files to new module").show()
313+
showInfo(
314+
message = "Files moved to new module: ${targetModulePath.replace(":", "/")}",
315+
type = NotificationType.INFORMATION
316+
)
281317
} catch (e: Exception) {
282-
QPWMessageDialog("Error moving files: ${e.message}").show()
318+
showInfo(
319+
message = "Error moving files: ${e.message}",
320+
type = NotificationType.ERROR
321+
)
283322
e.printStackTrace()
284323
}
285324
}
@@ -311,7 +350,10 @@ object Utils {
311350
val settingsFile = listOf(settingsGradleKtsPath, settingsGradlePath).firstOrNull {
312351
it.exists()
313352
} ?: run {
314-
QPWMessageDialog("Can't find settings.gradle(.kts) file")
353+
showInfo(
354+
message = "Can't find settings.gradle(.kts) file in project: ${project.name}",
355+
type = NotificationType.ERROR
356+
)
315357
return null
316358
}
317359

@@ -626,13 +668,13 @@ object Utils {
626668
}
627669
}
628670

629-
fun showInfo(title: String, message: String) {
671+
fun showInfo(title: String? = null, message: String, type: NotificationType = NotificationType.INFORMATION) {
630672
val notification = NotificationGroupManager.getInstance()
631673
.getNotificationGroup("QPW Notification Group")
632674
.createNotification(
633-
title = title,
675+
title = title ?: "Quick Project Wizard",
634676
content = message,
635-
type = NotificationType.INFORMATION,
677+
type = type,
636678
)
637679
notification.addAction(
638680
object : AnAction("Contact Developer") {

src/main/kotlin/com/github/cnrture/quickprojectwizard/components/QPWMessageDialog.kt

Lines changed: 0 additions & 41 deletions
This file was deleted.

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import androidx.compose.ui.unit.sp
2323
import androidx.compose.ui.window.Dialog
2424
import androidx.compose.ui.window.DialogProperties
2525
import com.github.cnrture.quickprojectwizard.common.Constants
26+
import com.github.cnrture.quickprojectwizard.common.Utils
2627
import com.github.cnrture.quickprojectwizard.components.QPWActionCard
2728
import com.github.cnrture.quickprojectwizard.components.QPWActionCardType
28-
import com.github.cnrture.quickprojectwizard.components.QPWMessageDialog
2929
import com.github.cnrture.quickprojectwizard.components.QPWText
3030
import com.github.cnrture.quickprojectwizard.data.SettingsState
3131
import com.github.cnrture.quickprojectwizard.service.AnalyticsService
@@ -39,6 +39,7 @@ import com.github.cnrture.quickprojectwizard.toolwindow.manager.modulegenerator.
3939
import com.github.cnrture.quickprojectwizard.toolwindow.manager.settings.SettingsContent
4040
import com.github.cnrture.quickprojectwizard.toolwindow.manager.settings.dialog.ExportSettingsContent
4141
import com.intellij.ide.BrowserUtil
42+
import com.intellij.notification.NotificationType
4243
import com.intellij.openapi.fileChooser.FileChooser
4344
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
4445
import com.intellij.openapi.project.Project
@@ -334,7 +335,11 @@ class QuickProjectWizardToolWindowFactory : ToolWindowFactory {
334335
settings = settings,
335336
onExport = { success, message ->
336337
analyticsService.track("export_settings")
337-
QPWMessageDialog(message).show()
338+
if (success) isExportDialogVisible = false
339+
Utils.showInfo(
340+
message = message,
341+
type = if (success) NotificationType.INFORMATION else NotificationType.ERROR,
342+
)
338343
},
339344
onCancel = { isExportDialogVisible = false }
340345
)
@@ -427,10 +432,16 @@ class QuickProjectWizardToolWindowFactory : ToolWindowFactory {
427432
descriptor.title = "Import Settings"
428433
FileChooser.chooseFile(descriptor, project, null) { file ->
429434
if (settings.importFromFile(file.path)) {
430-
QPWMessageDialog("Settings imported successfully!").show()
435+
Utils.showInfo(
436+
message = "Settings imported successfully!",
437+
type = NotificationType.INFORMATION,
438+
)
431439
onSuccess(settings.state)
432440
} else {
433-
QPWMessageDialog("Failed to import settings. Please check the file format.").show()
441+
Utils.showInfo(
442+
message = "Failed to import settings. Please check the file format.",
443+
type = NotificationType.ERROR,
444+
)
434445
}
435446
}
436447
}

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ 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.*
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
2528
import com.github.cnrture.quickprojectwizard.data.FeatureTemplate
2629
import com.github.cnrture.quickprojectwizard.service.SettingsService
2730
import com.github.cnrture.quickprojectwizard.theme.QPWTheme
31+
import com.intellij.notification.NotificationType
2832
import com.intellij.openapi.project.Project
2933

3034
@OptIn(ExperimentalLayoutApi::class)
@@ -68,9 +72,17 @@ fun ConfigurationPanel(
6872
selectedTemplate = selectedTemplate,
6973
from = "tool",
7074
)
71-
} ?: run { QPWMessageDialog("Please select a feature template").show() }
75+
} ?: run {
76+
Utils.showInfo(
77+
message = "Please select a feature template",
78+
type = NotificationType.WARNING,
79+
)
80+
}
7281
} else {
73-
QPWMessageDialog("Please fill out required values").show()
82+
Utils.showInfo(
83+
message = "Please fill out required values",
84+
type = NotificationType.WARNING,
85+
)
7486
}
7587
},
7688
)

src/main/kotlin/com/github/cnrture/quickprojectwizard/toolwindow/manager/featuregenerator/dialog/FeatureGeneratorDialog.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ import androidx.compose.ui.text.font.FontWeight
2020
import androidx.compose.ui.text.style.TextAlign
2121
import androidx.compose.ui.unit.dp
2222
import androidx.compose.ui.unit.sp
23-
import com.github.cnrture.quickprojectwizard.service.AnalyticsService
2423
import com.github.cnrture.quickprojectwizard.common.Constants
2524
import com.github.cnrture.quickprojectwizard.common.Utils
2625
import com.github.cnrture.quickprojectwizard.common.file.FileWriter
2726
import com.github.cnrture.quickprojectwizard.common.rootDirectoryString
2827
import com.github.cnrture.quickprojectwizard.common.rootDirectoryStringDropLast
2928
import com.github.cnrture.quickprojectwizard.components.*
3029
import com.github.cnrture.quickprojectwizard.data.FeatureTemplate
30+
import com.github.cnrture.quickprojectwizard.service.AnalyticsService
3131
import com.github.cnrture.quickprojectwizard.service.SettingsService
3232
import com.github.cnrture.quickprojectwizard.theme.QPWTheme
33+
import com.intellij.notification.NotificationType
3334
import com.intellij.openapi.project.Project
3435
import com.intellij.openapi.vfs.VirtualFile
3536
import java.io.File
@@ -126,9 +127,17 @@ class FeatureGeneratorDialog(
126127
if (validateInput()) {
127128
selectedTemplate?.let {
128129
createFeature(it)
129-
} ?: run { QPWMessageDialog("Please select a feature template").show() }
130+
} ?: run {
131+
Utils.showInfo(
132+
message = "Please select a feature template",
133+
type = NotificationType.WARNING,
134+
)
135+
}
130136
} else {
131-
QPWMessageDialog("Please fill out required values").show()
137+
Utils.showInfo(
138+
message = "Please fill out required values",
139+
type = NotificationType.WARNING,
140+
)
132141
}
133142
},
134143
)
@@ -326,7 +335,10 @@ class FeatureGeneratorDialog(
326335
from = "action",
327336
)
328337
} catch (e: Exception) {
329-
QPWMessageDialog("Error: ${e.message}").show()
338+
Utils.showInfo(
339+
message = "Failed to create feature: ${e.message}",
340+
type = NotificationType.ERROR,
341+
)
330342
} finally {
331343
close(0)
332344
}

src/main/kotlin/com/github/cnrture/quickprojectwizard/toolwindow/manager/modulegenerator/CreateNewModuleConfigurationPanel.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import com.github.cnrture.quickprojectwizard.common.file.FileWriter
1616
import com.github.cnrture.quickprojectwizard.common.file.LibraryDependencyFinder
1717
import com.github.cnrture.quickprojectwizard.components.QPWActionCard
1818
import com.github.cnrture.quickprojectwizard.components.QPWActionCardType
19-
import com.github.cnrture.quickprojectwizard.components.QPWMessageDialog
2019
import com.github.cnrture.quickprojectwizard.data.ModuleTemplate
2120
import com.github.cnrture.quickprojectwizard.data.PluginListItem
2221
import com.github.cnrture.quickprojectwizard.service.SettingsService
2322
import com.github.cnrture.quickprojectwizard.theme.QPWTheme
2423
import com.github.cnrture.quickprojectwizard.toolwindow.manager.modulegenerator.components.*
24+
import com.intellij.notification.NotificationType
2525
import com.intellij.openapi.project.Project
2626

2727
@OptIn(ExperimentalLayoutApi::class)
@@ -100,7 +100,10 @@ fun CreateNewModuleConfigurationPanel(
100100
from = "new",
101101
)
102102
} else {
103-
QPWMessageDialog("Please fill out required values").show()
103+
Utils.showInfo(
104+
message = "Please fill out required values",
105+
type = NotificationType.WARNING,
106+
)
104107
}
105108
},
106109
)

0 commit comments

Comments
 (0)