@@ -2,12 +2,17 @@ package com.coder.toolbox.views
2
2
3
3
import com.coder.toolbox.settings.Source
4
4
import com.coder.toolbox.util.withPath
5
+ import com.jetbrains.toolbox.api.core.ServiceLocator
6
+ import com.jetbrains.toolbox.api.localization.LocalizableString
7
+ import com.jetbrains.toolbox.api.localization.LocalizableStringFactory
5
8
import com.jetbrains.toolbox.api.ui.actions.RunnableActionDescription
6
9
import com.jetbrains.toolbox.api.ui.components.LabelField
7
10
import com.jetbrains.toolbox.api.ui.components.LinkField
8
11
import com.jetbrains.toolbox.api.ui.components.TextField
9
12
import com.jetbrains.toolbox.api.ui.components.TextType
10
13
import com.jetbrains.toolbox.api.ui.components.UiField
14
+ import kotlinx.coroutines.flow.MutableStateFlow
15
+ import kotlinx.coroutines.flow.StateFlow
11
16
import java.net.URL
12
17
13
18
/* *
@@ -17,34 +22,44 @@ import java.net.URL
17
22
* enter their own.
18
23
*/
19
24
class TokenPage (
25
+ serviceLocator : ServiceLocator ,
26
+ title : LocalizableString ,
20
27
deploymentURL : URL ,
21
28
token : Pair <String , Source >? ,
22
29
private val onToken : ((token: String ) -> Unit ),
23
- ) : CoderPage(" Enter your token" ) {
24
- private val tokenField = TextField (" Token" , token?.first ? : " " , TextType .General )
30
+ ) : CoderPage(serviceLocator, title) {
31
+ private val i18n: LocalizableStringFactory = serviceLocator.getService(LocalizableStringFactory ::class .java)
32
+
33
+ private val tokenField = TextField (i18n.ptrl(" Token" ), token?.first ? : " " , TextType .General )
25
34
26
35
/* *
27
36
* Fields for this page, displayed in order.
28
37
*
29
38
* TODO@JB: Fields are reset when you navigate back.
30
39
* Ideally they remember what the user entered.
31
40
*/
32
- override val fields: MutableList <UiField > = listOfNotNull(
41
+ override val fields: StateFlow <List <UiField >> = MutableStateFlow (
42
+ listOfNotNull(
33
43
tokenField,
34
44
LabelField (
35
- token?.second?.description(" token" )
36
- ? : " No existing token for ${deploymentURL.host} found." ,
45
+ i18n.pnotr(
46
+ token?.second?.description(" token" )
47
+ ? : " No existing token for ${deploymentURL.host} found."
48
+ ),
37
49
),
38
50
// TODO@JB: The link text displays twice.
39
- LinkField (" Get a token" , deploymentURL.withPath(" /login?redirect=%2Fcli-auth" ).toString()),
51
+ LinkField (i18n.ptrl( " Get a token" ) , deploymentURL.withPath(" /login?redirect=%2Fcli-auth" ).toString()),
40
52
errorField,
41
- ).toMutableList()
53
+ )
54
+ )
42
55
43
56
/* *
44
57
* Buttons displayed at the bottom of the page.
45
58
*/
46
- override val actionButtons: MutableList <RunnableActionDescription > = mutableListOf (
47
- Action (" Connect" , closesPage = false ) { submit(tokenField.text.value) },
59
+ override val actionButtons: StateFlow <List <RunnableActionDescription >> = MutableStateFlow (
60
+ listOf (
61
+ Action (i18n.ptrl(" Connect" ), closesPage = false ) { submit(tokenField.textState.value) },
62
+ )
48
63
)
49
64
50
65
/* *
0 commit comments