@@ -2,12 +2,17 @@ package com.coder.toolbox.views
22
33import com.coder.toolbox.settings.Source
44import 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
58import com.jetbrains.toolbox.api.ui.actions.RunnableActionDescription
69import com.jetbrains.toolbox.api.ui.components.LabelField
710import com.jetbrains.toolbox.api.ui.components.LinkField
811import com.jetbrains.toolbox.api.ui.components.TextField
912import com.jetbrains.toolbox.api.ui.components.TextType
1013import com.jetbrains.toolbox.api.ui.components.UiField
14+ import kotlinx.coroutines.flow.MutableStateFlow
15+ import kotlinx.coroutines.flow.StateFlow
1116import java.net.URL
1217
1318/* *
@@ -17,34 +22,44 @@ import java.net.URL
1722 * enter their own.
1823 */
1924class TokenPage (
25+ serviceLocator : ServiceLocator ,
26+ title : LocalizableString ,
2027 deploymentURL : URL ,
2128 token : Pair <String , Source >? ,
2229 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 )
2534
2635 /* *
2736 * Fields for this page, displayed in order.
2837 *
2938 * TODO@JB: Fields are reset when you navigate back.
3039 * Ideally they remember what the user entered.
3140 */
32- override val fields: MutableList <UiField > = listOfNotNull(
41+ override val fields: StateFlow <List <UiField >> = MutableStateFlow (
42+ listOfNotNull(
3343 tokenField,
3444 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+ ),
3749 ),
3850 // 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()),
4052 errorField,
41- ).toMutableList()
53+ )
54+ )
4255
4356 /* *
4457 * Buttons displayed at the bottom of the page.
4558 */
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+ )
4863 )
4964
5065 /* *
0 commit comments