@@ -56,7 +56,9 @@ class DefaultConnectionPinningManager :
56
56
ConnectionPinningManager ,
57
57
PersistentStateComponent <ConnectionPinningManagerState >,
58
58
Disposable {
59
- private var doNotPromptForPinning: Boolean = false
59
+ @VisibleForTesting
60
+ internal var shouldPinConnections: Boolean? = null
61
+
60
62
private val pinnedConnections = ConcurrentHashMap <String , ToolkitConnection >()
61
63
62
64
init {
@@ -108,14 +110,14 @@ class DefaultConnectionPinningManager :
108
110
}
109
111
110
112
override fun getState () = ConnectionPinningManagerState (
111
- doNotPromptForPinning ,
113
+ shouldPinConnections ,
112
114
pinnedConnections.entries.associate { (k, v) -> k to v.id }
113
115
)
114
116
115
117
override fun loadState (state : ConnectionPinningManagerState ) {
116
118
val authManager = ToolkitAuthManager .getInstance()
117
119
118
- doNotPromptForPinning = state.doNotPromptForPinning
120
+ shouldPinConnections = state.shouldPinConnections
119
121
120
122
pinnedConnections.clear()
121
123
pinnedConnections.putAll(
@@ -129,35 +131,37 @@ class DefaultConnectionPinningManager :
129
131
130
132
@VisibleForTesting
131
133
internal fun showDialogIfNeeded (oldConnection : ToolkitConnection ? , newConnection : ToolkitConnection , featuresString : String , project : Project ? = null) =
132
- if (! doNotPromptForPinning) {
133
- val bearerTokenConnectionName = bearerTokenConnectionString(oldConnection, newConnection)
134
-
135
- computeOnEdt(ModalityState .defaultModalityState()) {
136
- MessageDialogBuilder .yesNo(
137
- message(" credentials.switch.confirmation.title" , featuresString, bearerTokenConnectionName),
138
- message(" credentials.switch.confirmation.comment" , featuresString, bearerTokenConnectionName, message(" iam.name" ))
139
- )
140
- .yesText(message(" credentials.switch.confirmation.yes" ))
141
- .noText(message(" credentials.switch.confirmation.no" ))
142
- .doNotAsk(object : com.intellij.openapi.ui.DoNotAskOption .Adapter () {
143
- override fun rememberChoice (isSelected : Boolean , exitCode : Int ) {
144
- if (isSelected && exitCode == DialogWrapper .OK_EXIT_CODE ) {
145
- doNotPromptForPinning = true
134
+ shouldPinConnections.let { shouldPinConnections ->
135
+ if (shouldPinConnections == null ) {
136
+ val bearerTokenConnectionName = bearerTokenConnectionString(oldConnection, newConnection)
137
+
138
+ computeOnEdt(ModalityState .defaultModalityState()) {
139
+ MessageDialogBuilder .yesNo(
140
+ message(" credentials.switch.confirmation.title" , featuresString, bearerTokenConnectionName),
141
+ message(" credentials.switch.confirmation.comment" , featuresString, bearerTokenConnectionName, message(" iam.name" ))
142
+ )
143
+ .yesText(message(" credentials.switch.confirmation.yes" ))
144
+ .noText(message(" credentials.switch.confirmation.no" ))
145
+ .doNotAsk(object : com.intellij.openapi.ui.DoNotAskOption .Adapter () {
146
+ override fun rememberChoice (isSelected : Boolean , exitCode : Int ) {
147
+ if (isSelected) {
148
+ this @DefaultConnectionPinningManager.shouldPinConnections = exitCode == DialogWrapper .OK_EXIT_CODE
149
+ }
150
+ }
151
+ })
152
+ .icon(AllIcons .General .QuestionDialog )
153
+ .help(HelpIds .EXPLORER_CREDS_HELP .id)
154
+ .ask(project).apply {
155
+ if (this ) {
156
+ UiTelemetry .click(project, " connection_multiple_auths_yes" )
157
+ } else {
158
+ UiTelemetry .click(project, " connection_multiple_auths_no" )
146
159
}
147
160
}
148
- })
149
- .icon(AllIcons .General .QuestionDialog )
150
- .help(HelpIds .EXPLORER_CREDS_HELP .id)
151
- .ask(project).apply {
152
- if (this ) {
153
- UiTelemetry .click(project, " connection_multiple_auths_yes" )
154
- } else {
155
- UiTelemetry .click(project, " connection_multiple_auths_no" )
156
- }
157
- }
161
+ }
162
+ } else {
163
+ shouldPinConnections
158
164
}
159
- } else {
160
- false
161
165
}
162
166
163
167
private fun bearerTokenConnectionString (oldConnection : ToolkitConnection ? , newConnection : ToolkitConnection ): String {
@@ -167,6 +171,6 @@ class DefaultConnectionPinningManager :
167
171
}
168
172
169
173
data class ConnectionPinningManagerState (
170
- var doNotPromptForPinning : Boolean = false ,
174
+ var shouldPinConnections : Boolean? = null ,
171
175
var pinnedConnections : Map <String , String > = emptyMap()
172
176
)
0 commit comments