3
3
4
4
package software.aws.toolkits.jetbrains.settings
5
5
6
- import com.intellij.openapi.application.ApplicationManager
7
- import com.intellij.openapi.application.ModalityState
8
- import com.intellij.openapi.application.runInEdt
9
6
import com.intellij.openapi.options.BoundConfigurable
10
7
import com.intellij.openapi.project.ProjectManager
8
+ import com.intellij.openapi.ui.InputValidator
9
+ import com.intellij.openapi.ui.Messages
10
+ import com.intellij.openapi.ui.messages.MessagesService
11
11
import com.intellij.ui.CheckBoxList
12
12
import com.intellij.ui.FilterComponent
13
13
import com.intellij.ui.ListSpeedSearch
14
14
import com.intellij.ui.layout.panel
15
+ import kotlinx.coroutines.launch
16
+ import kotlinx.coroutines.withContext
17
+ import software.amazon.awssdk.services.toolkittelemetry.model.Sentiment
15
18
import software.aws.toolkits.core.utils.replace
19
+ import software.aws.toolkits.jetbrains.core.coroutines.applicationCoroutineScope
20
+ import software.aws.toolkits.jetbrains.core.coroutines.getCoroutineBgContext
21
+ import software.aws.toolkits.jetbrains.core.coroutines.getCoroutineUiContext
16
22
import software.aws.toolkits.jetbrains.core.explorer.ExplorerToolWindow
17
23
import software.aws.toolkits.jetbrains.services.dynamic.DynamicResourceSupportedTypes
18
24
import software.aws.toolkits.jetbrains.services.dynamic.explorer.OtherResourcesNode
25
+ import software.aws.toolkits.jetbrains.services.telemetry.TelemetryService
26
+ import software.aws.toolkits.jetbrains.ui.feedback.FEEDBACK_SOURCE
27
+ import software.aws.toolkits.jetbrains.utils.notifyError
19
28
import software.aws.toolkits.resources.message
29
+ import software.aws.toolkits.telemetry.FeedbackTelemetry
20
30
import javax.swing.ListSelectionModel
21
31
22
32
class DynamicResourcesConfigurable : BoundConfigurable (message("aws.settings.dynamic_resources_configurable.title")) {
23
33
34
+ private val coroutineScope = applicationCoroutineScope()
24
35
private val checklist = CheckBoxList <String >()
25
36
private val allResources = mutableSetOf<String >()
26
37
private val selected = mutableSetOf<String >()
@@ -43,14 +54,22 @@ class DynamicResourcesConfigurable : BoundConfigurable(message("aws.settings.dyn
43
54
44
55
override fun createPanel () = panel {
45
56
selected.replace(DynamicResourcesSettings .getInstance().selected)
46
- ApplicationManager .getApplication().executeOnPooledThread {
57
+ coroutineScope.launch(getCoroutineBgContext()) {
47
58
allResources.addAll(DynamicResourceSupportedTypes .getInstance().getSupportedTypes())
48
- runInEdt( ModalityState .any ()) {
59
+ withContext(getCoroutineUiContext ()) {
49
60
updateCheckboxList()
50
61
}
51
62
}
52
-
53
- row { filter(growX) }
63
+ row {
64
+ cell(isFullWidth = true ) {
65
+ filter(growX, pushX)
66
+ link(message(" aws.settings.dynamic_resources_configurable.suggest_types.prompt" )) {
67
+ showTypeSuggestionBox()?.let { suggestion ->
68
+ submitSuggestion(suggestion)
69
+ }
70
+ }
71
+ }
72
+ }
54
73
row {
55
74
scrollPane(checklist)
56
75
.constraints(growX, pushX)
@@ -78,6 +97,19 @@ class DynamicResourcesConfigurable : BoundConfigurable(message("aws.settings.dyn
78
97
}
79
98
}
80
99
100
+ private fun submitSuggestion (suggestion : String ) {
101
+ coroutineScope.launch(getCoroutineBgContext()) {
102
+ try {
103
+ TelemetryService .getInstance().sendFeedback(Sentiment .NEGATIVE , suggestion, mapOf (FEEDBACK_SOURCE to " Resource Type Suggestions" )).also {
104
+ FeedbackTelemetry .result(project = null , success = true )
105
+ }
106
+ } catch (e: Exception ) {
107
+ e.notifyError(message(" feedback.submit_failed" , e))
108
+ FeedbackTelemetry .result(project = null , success = false )
109
+ }
110
+ }
111
+ }
112
+
81
113
private fun CheckBoxList <* >.toggleAll (state : Boolean ) {
82
114
(0 until model.size).forEach { idx ->
83
115
checkboxStateHandler(idx, state)
@@ -112,4 +144,24 @@ class DynamicResourcesConfigurable : BoundConfigurable(message("aws.settings.dyn
112
144
}
113
145
}
114
146
}
147
+
148
+ companion object {
149
+ private const val INITIAL_INPUT = " AWS::"
150
+ private const val MAX_LENGTH = 2000
151
+
152
+ private fun showTypeSuggestionBox (): String? = MessagesService .getInstance().showMultilineInputDialog(
153
+ project = null ,
154
+ message = message(" aws.settings.dynamic_resources_configurable.suggest_types.dialog.message" ),
155
+ title = message(" aws.settings.dynamic_resources_configurable.suggest_types.dialog.title" ),
156
+ initialValue = INITIAL_INPUT ,
157
+ icon = Messages .getQuestionIcon(),
158
+ object : InputValidator {
159
+ override fun checkInput (inputString : String? ) = validateSuggestion(inputString)
160
+ override fun canClose (inputString : String? ) = validateSuggestion(inputString)
161
+ }
162
+ )?.takeIf { it.isNotBlank() }
163
+
164
+ private fun validateSuggestion (inputString : String? ) =
165
+ inputString != null && inputString.isNotBlank() && inputString != INITIAL_INPUT && inputString.length <= MAX_LENGTH
166
+ }
115
167
}
0 commit comments