Skip to content

New connection from recent workspaces #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/kotlin/com/coder/gateway/CoderGatewayConstants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.coder.gateway

object CoderGatewayConstants {
const val GATEWAY_CONNECTOR_ID = "Coder.Gateway.Connector"
const val GATEWAY_RECENT_CONNECTIONS_ID = "Coder.Gateway.Recent.Connections"
}
2 changes: 2 additions & 0 deletions src/main/kotlin/com/coder/gateway/CoderGatewayMainView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import javax.swing.Icon
import javax.swing.JComponent

class CoderGatewayMainView : GatewayConnector {
override fun getConnectorId() = CoderGatewayConstants.GATEWAY_CONNECTOR_ID

override val icon: Icon
get() = CoderIcons.LOGO

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import com.intellij.ui.dsl.builder.RightGap
import com.intellij.ui.dsl.builder.panel
import com.intellij.ui.dsl.gridLayout.HorizontalAlign
import com.intellij.util.ui.components.BorderLayoutPanel
import com.jetbrains.gateway.api.GatewayUI
import java.awt.Component
import javax.swing.JButton

class CoderGatewayConnectorWizardView : BorderLayoutPanel(), Disposable {
class CoderGatewayConnectorWizardView(private val recentWorkspacesReset: () -> Unit) : BorderLayoutPanel(), Disposable {
private var steps = arrayListOf<CoderWorkspacesWizardStep>()
private var currentStep = 0
private val model = CoderWorkspacesWizardModel()
Expand Down Expand Up @@ -54,7 +53,7 @@ class CoderGatewayConnectorWizardView : BorderLayoutPanel(), Disposable {

private fun previous() {
if (currentStep == 0) {
GatewayUI.Companion.getInstance().reset()
recentWorkspacesReset()
} else {
remove(steps[currentStep].component)
updateUI()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package com.coder.gateway.views
import com.intellij.ui.components.panels.Wrapper
import com.intellij.util.ui.JBUI
import com.jetbrains.gateway.api.GatewayConnectorView
import com.jetbrains.gateway.api.GatewayUI
import javax.swing.JComponent

class CoderGatewayConnectorWizardWrapperView : GatewayConnectorView {
class CoderGatewayConnectorWizardWrapperView(private val recentWorkspacesReset: () -> Unit = { GatewayUI.Companion.getInstance().reset() }) : GatewayConnectorView {
override val component: JComponent
get() = Wrapper(CoderGatewayConnectorWizardView()).apply { border = JBUI.Borders.empty() }
get() = Wrapper(CoderGatewayConnectorWizardView(recentWorkspacesReset)).apply { border = JBUI.Borders.empty() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
package com.coder.gateway.views

import com.coder.gateway.CoderGatewayBundle
import com.coder.gateway.CoderGatewayConstants
import com.coder.gateway.icons.CoderIcons
import com.coder.gateway.models.RecentWorkspaceConnection
import com.coder.gateway.services.CoderRecentWorkspaceConnectionsService
import com.intellij.icons.AllIcons
import com.intellij.ide.BrowserUtil
import com.intellij.openapi.Disposable
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.components.service
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.ui.DialogPanel
import com.intellij.openapi.ui.panel.ComponentPanelBuilder
import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeScreenUIManager
import com.intellij.ui.DocumentAdapter
Expand All @@ -25,6 +28,7 @@ import com.intellij.ui.dsl.gridLayout.HorizontalAlign
import com.intellij.ui.dsl.gridLayout.VerticalAlign
import com.intellij.util.ui.JBFont
import com.intellij.util.ui.JBUI
import com.intellij.util.ui.components.BorderLayoutPanel
import com.jetbrains.gateway.api.GatewayRecentConnections
import com.jetbrains.gateway.api.GatewayUI
import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
Expand All @@ -41,43 +45,69 @@ class CoderGatewayRecentWorkspaceConnectionsView : GatewayRecentConnections, Dis
private val recentConnectionsService = service<CoderRecentWorkspaceConnectionsService>()
private val cs = CoroutineScope(Dispatchers.Main)

private val contentPanel = JBScrollPane()
private val rootPanel = BorderLayoutPanel()
private lateinit var contentPanel: DialogPanel
private val recentWorkspacesContentPanel = JBScrollPane()

private lateinit var searchBar: SearchTextField

override val id = "CoderGatewayRecentConnections"
override val id = CoderGatewayConstants.GATEWAY_RECENT_CONNECTIONS_ID

override val recentsIcon = CoderIcons.LOGO_16

override fun createRecentsView(lifetime: Lifetime): JComponent {
return panel {
contentPanel = panel {
indent {
row {
label(CoderGatewayBundle.message("gateway.connector.recentconnections.title")).applyToComponent {
font = JBFont.h3().asBold()
}
searchBar = cell(SearchTextField(false)).applyToComponent {
minimumSize = Dimension(350, -1)
textEditor.border = JBUI.Borders.empty(2, 5, 2, 0)
}.horizontalAlign(HorizontalAlign.RIGHT).component
searchBar.addDocumentListener(object : DocumentAdapter() {
override fun textChanged(e: DocumentEvent) {
val toSearchFor = searchBar.text
val filteredConnections = recentConnectionsService.getAllRecentConnections().filter { it.coderWorkspaceHostname?.toLowerCase()?.contains(toSearchFor) ?: false || it.projectPath?.toLowerCase()?.contains(toSearchFor) ?: false }
updateContentView(filteredConnections.groupBy { it.coderWorkspaceHostname })
panel {
row {
searchBar = cell(SearchTextField(false)).applyToComponent {
minimumSize = Dimension(350, -1)
textEditor.border = JBUI.Borders.empty(2, 5, 2, 0)
addDocumentListener(object : DocumentAdapter() {
override fun textChanged(e: DocumentEvent) {
val toSearchFor = [email protected]
val filteredConnections = recentConnectionsService.getAllRecentConnections().filter { it.coderWorkspaceHostname?.toLowerCase()?.contains(toSearchFor) ?: false || it.projectPath?.toLowerCase()?.contains(toSearchFor) ?: false }
updateContentView(filteredConnections.groupBy { it.coderWorkspaceHostname })
}
})
}.component

actionButton(
object : DumbAwareAction(CoderGatewayBundle.message("gateway.connector.recentconnections.new.wizard.button.tooltip"), null, AllIcons.General.Add) {
override fun actionPerformed(e: AnActionEvent) {
rootPanel.apply {
removeAll()
addToCenter(CoderGatewayConnectorWizardWrapperView {
rootPanel.apply {
removeAll()
addToCenter(contentPanel)
updateUI()
}
}.component)
updateUI()
}
}
},
).gap(RightGap.SMALL)
}
})
}.horizontalAlign(HorizontalAlign.RIGHT)
}.bottomGap(BottomGap.MEDIUM)
separator(background = WelcomeScreenUIManager.getSeparatorColor())
row {
resizableRow()
cell(contentPanel).resizableColumn().horizontalAlign(HorizontalAlign.FILL).verticalAlign(VerticalAlign.FILL).component
cell(recentWorkspacesContentPanel).resizableColumn().horizontalAlign(HorizontalAlign.FILL).verticalAlign(VerticalAlign.FILL).component
}
}
}.apply {
background = WelcomeScreenUIManager.getMainAssociatedComponentBackground()
border = JBUI.Borders.empty(12, 0, 0, 12)
}

return rootPanel.addToCenter(contentPanel)
}

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

private fun updateContentView(groupedConnections: Map<String?, List<RecentWorkspaceConnection>>) {
contentPanel.viewport.view = panel {
recentWorkspacesContentPanel.viewport.view = panel {
groupedConnections.entries.forEach { (hostname, recentConnections) ->
row {
if (hostname != null) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/messages/CoderGatewayBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ gateway.connector.view.coder.remoteproject.ide.error.text=Could not retrieve any
gateway.connector.view.coder.remoteproject.next.text=Download and Start IDE
gateway.connector.view.coder.remoteproject.choose.text=Choose IDE and project for workspace {0}
gateway.connector.recentconnections.title=Recent Coder Workspaces
gateway.connector.recentconnections.new.wizard.button.tooltip=Open a new Coder Workspace
gateway.connector.recentconnections.remove.button.tooltip=Remove from Recent Connections
gateway.connector.recentconnections.terminal.button.tooltip=Open SSH Web Terminal