Skip to content

Commit 6da49cb

Browse files
authored
Merge pull request #25 from coder/new-connection-from-recent-workspaces
New connection from recent workspaces - refactors some Coder Gateway IDs - resolves #6 - i18n tooltip for new connection button
2 parents fca3a67 + 3298135 commit 6da49cb

6 files changed

+59
-20
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.coder.gateway
2+
3+
object CoderGatewayConstants {
4+
const val GATEWAY_CONNECTOR_ID = "Coder.Gateway.Connector"
5+
const val GATEWAY_RECENT_CONNECTIONS_ID = "Coder.Gateway.Recent.Connections"
6+
}

src/main/kotlin/com/coder/gateway/CoderGatewayMainView.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import javax.swing.Icon
1414
import javax.swing.JComponent
1515

1616
class CoderGatewayMainView : GatewayConnector {
17+
override fun getConnectorId() = CoderGatewayConstants.GATEWAY_CONNECTOR_ID
18+
1719
override val icon: Icon
1820
get() = CoderIcons.LOGO
1921

src/main/kotlin/com/coder/gateway/views/CoderGatewayConnectorWizardView.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ import com.intellij.ui.dsl.builder.RightGap
1111
import com.intellij.ui.dsl.builder.panel
1212
import com.intellij.ui.dsl.gridLayout.HorizontalAlign
1313
import com.intellij.util.ui.components.BorderLayoutPanel
14-
import com.jetbrains.gateway.api.GatewayUI
1514
import java.awt.Component
1615
import javax.swing.JButton
1716

18-
class CoderGatewayConnectorWizardView : BorderLayoutPanel(), Disposable {
17+
class CoderGatewayConnectorWizardView(private val recentWorkspacesReset: () -> Unit) : BorderLayoutPanel(), Disposable {
1918
private var steps = arrayListOf<CoderWorkspacesWizardStep>()
2019
private var currentStep = 0
2120
private val model = CoderWorkspacesWizardModel()
@@ -54,7 +53,7 @@ class CoderGatewayConnectorWizardView : BorderLayoutPanel(), Disposable {
5453

5554
private fun previous() {
5655
if (currentStep == 0) {
57-
GatewayUI.Companion.getInstance().reset()
56+
recentWorkspacesReset()
5857
} else {
5958
remove(steps[currentStep].component)
6059
updateUI()

src/main/kotlin/com/coder/gateway/views/CoderGatewayConnectorWizardWrapperView.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package com.coder.gateway.views
33
import com.intellij.ui.components.panels.Wrapper
44
import com.intellij.util.ui.JBUI
55
import com.jetbrains.gateway.api.GatewayConnectorView
6+
import com.jetbrains.gateway.api.GatewayUI
67
import javax.swing.JComponent
78

8-
class CoderGatewayConnectorWizardWrapperView : GatewayConnectorView {
9+
class CoderGatewayConnectorWizardWrapperView(private val recentWorkspacesReset: () -> Unit = { GatewayUI.Companion.getInstance().reset() }) : GatewayConnectorView {
910
override val component: JComponent
10-
get() = Wrapper(CoderGatewayConnectorWizardView()).apply { border = JBUI.Borders.empty() }
11+
get() = Wrapper(CoderGatewayConnectorWizardView(recentWorkspacesReset)).apply { border = JBUI.Borders.empty() }
1112
}

src/main/kotlin/com/coder/gateway/views/CoderGatewayRecentWorkspaceConnectionsView.kt

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
package com.coder.gateway.views
44

55
import com.coder.gateway.CoderGatewayBundle
6+
import com.coder.gateway.CoderGatewayConstants
67
import com.coder.gateway.icons.CoderIcons
78
import com.coder.gateway.models.RecentWorkspaceConnection
89
import com.coder.gateway.services.CoderRecentWorkspaceConnectionsService
10+
import com.intellij.icons.AllIcons
911
import com.intellij.ide.BrowserUtil
1012
import com.intellij.openapi.Disposable
1113
import com.intellij.openapi.actionSystem.AnActionEvent
1214
import com.intellij.openapi.components.service
1315
import com.intellij.openapi.project.DumbAwareAction
16+
import com.intellij.openapi.ui.DialogPanel
1417
import com.intellij.openapi.ui.panel.ComponentPanelBuilder
1518
import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
1619
import com.intellij.ui.DocumentAdapter
@@ -25,6 +28,7 @@ import com.intellij.ui.dsl.gridLayout.HorizontalAlign
2528
import com.intellij.ui.dsl.gridLayout.VerticalAlign
2629
import com.intellij.util.ui.JBFont
2730
import com.intellij.util.ui.JBUI
31+
import com.intellij.util.ui.components.BorderLayoutPanel
2832
import com.jetbrains.gateway.api.GatewayRecentConnections
2933
import com.jetbrains.gateway.api.GatewayUI
3034
import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
@@ -41,43 +45,69 @@ class CoderGatewayRecentWorkspaceConnectionsView : GatewayRecentConnections, Dis
4145
private val recentConnectionsService = service<CoderRecentWorkspaceConnectionsService>()
4246
private val cs = CoroutineScope(Dispatchers.Main)
4347

44-
private val contentPanel = JBScrollPane()
48+
private val rootPanel = BorderLayoutPanel()
49+
private lateinit var contentPanel: DialogPanel
50+
private val recentWorkspacesContentPanel = JBScrollPane()
4551

4652
private lateinit var searchBar: SearchTextField
4753

48-
override val id = "CoderGatewayRecentConnections"
54+
override val id = CoderGatewayConstants.GATEWAY_RECENT_CONNECTIONS_ID
4955

5056
override val recentsIcon = CoderIcons.LOGO_16
5157

5258
override fun createRecentsView(lifetime: Lifetime): JComponent {
53-
return panel {
59+
contentPanel = panel {
5460
indent {
5561
row {
5662
label(CoderGatewayBundle.message("gateway.connector.recentconnections.title")).applyToComponent {
5763
font = JBFont.h3().asBold()
5864
}
59-
searchBar = cell(SearchTextField(false)).applyToComponent {
60-
minimumSize = Dimension(350, -1)
61-
textEditor.border = JBUI.Borders.empty(2, 5, 2, 0)
62-
}.horizontalAlign(HorizontalAlign.RIGHT).component
63-
searchBar.addDocumentListener(object : DocumentAdapter() {
64-
override fun textChanged(e: DocumentEvent) {
65-
val toSearchFor = searchBar.text
66-
val filteredConnections = recentConnectionsService.getAllRecentConnections().filter { it.coderWorkspaceHostname?.toLowerCase()?.contains(toSearchFor) ?: false || it.projectPath?.toLowerCase()?.contains(toSearchFor) ?: false }
67-
updateContentView(filteredConnections.groupBy { it.coderWorkspaceHostname })
65+
panel {
66+
row {
67+
searchBar = cell(SearchTextField(false)).applyToComponent {
68+
minimumSize = Dimension(350, -1)
69+
textEditor.border = JBUI.Borders.empty(2, 5, 2, 0)
70+
addDocumentListener(object : DocumentAdapter() {
71+
override fun textChanged(e: DocumentEvent) {
72+
val toSearchFor = this@applyToComponent.text
73+
val filteredConnections = recentConnectionsService.getAllRecentConnections().filter { it.coderWorkspaceHostname?.toLowerCase()?.contains(toSearchFor) ?: false || it.projectPath?.toLowerCase()?.contains(toSearchFor) ?: false }
74+
updateContentView(filteredConnections.groupBy { it.coderWorkspaceHostname })
75+
}
76+
})
77+
}.component
78+
79+
actionButton(
80+
object : DumbAwareAction(CoderGatewayBundle.message("gateway.connector.recentconnections.new.wizard.button.tooltip"), null, AllIcons.General.Add) {
81+
override fun actionPerformed(e: AnActionEvent) {
82+
rootPanel.apply {
83+
removeAll()
84+
addToCenter(CoderGatewayConnectorWizardWrapperView {
85+
rootPanel.apply {
86+
removeAll()
87+
addToCenter(contentPanel)
88+
updateUI()
89+
}
90+
}.component)
91+
updateUI()
92+
}
93+
}
94+
},
95+
).gap(RightGap.SMALL)
6896
}
69-
})
97+
}.horizontalAlign(HorizontalAlign.RIGHT)
7098
}.bottomGap(BottomGap.MEDIUM)
7199
separator(background = WelcomeScreenUIManager.getSeparatorColor())
72100
row {
73101
resizableRow()
74-
cell(contentPanel).resizableColumn().horizontalAlign(HorizontalAlign.FILL).verticalAlign(VerticalAlign.FILL).component
102+
cell(recentWorkspacesContentPanel).resizableColumn().horizontalAlign(HorizontalAlign.FILL).verticalAlign(VerticalAlign.FILL).component
75103
}
76104
}
77105
}.apply {
78106
background = WelcomeScreenUIManager.getMainAssociatedComponentBackground()
79107
border = JBUI.Borders.empty(12, 0, 0, 12)
80108
}
109+
110+
return rootPanel.addToCenter(contentPanel)
81111
}
82112

83113
override fun getRecentsTitle() = CoderGatewayBundle.message("gateway.connector.title")
@@ -87,7 +117,7 @@ class CoderGatewayRecentWorkspaceConnectionsView : GatewayRecentConnections, Dis
87117
}
88118

89119
private fun updateContentView(groupedConnections: Map<String?, List<RecentWorkspaceConnection>>) {
90-
contentPanel.viewport.view = panel {
120+
recentWorkspacesContentPanel.viewport.view = panel {
91121
groupedConnections.entries.forEach { (hostname, recentConnections) ->
92122
row {
93123
if (hostname != null) {

src/main/resources/messages/CoderGatewayBundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ gateway.connector.view.coder.remoteproject.ide.error.text=Could not retrieve any
1616
gateway.connector.view.coder.remoteproject.next.text=Download and Start IDE
1717
gateway.connector.view.coder.remoteproject.choose.text=Choose IDE and project for workspace {0}
1818
gateway.connector.recentconnections.title=Recent Coder Workspaces
19+
gateway.connector.recentconnections.new.wizard.button.tooltip=Open a new Coder Workspace
1920
gateway.connector.recentconnections.remove.button.tooltip=Remove from Recent Connections
2021
gateway.connector.recentconnections.terminal.button.tooltip=Open SSH Web Terminal

0 commit comments

Comments
 (0)