diff --git a/src/main/kotlin/com/coder/gateway/CoderGatewayConstants.kt b/src/main/kotlin/com/coder/gateway/CoderGatewayConstants.kt new file mode 100644 index 00000000..2b4f8bdf --- /dev/null +++ b/src/main/kotlin/com/coder/gateway/CoderGatewayConstants.kt @@ -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" +} \ No newline at end of file diff --git a/src/main/kotlin/com/coder/gateway/CoderGatewayMainView.kt b/src/main/kotlin/com/coder/gateway/CoderGatewayMainView.kt index 5b9f0395..6f43603c 100644 --- a/src/main/kotlin/com/coder/gateway/CoderGatewayMainView.kt +++ b/src/main/kotlin/com/coder/gateway/CoderGatewayMainView.kt @@ -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 diff --git a/src/main/kotlin/com/coder/gateway/views/CoderGatewayConnectorWizardView.kt b/src/main/kotlin/com/coder/gateway/views/CoderGatewayConnectorWizardView.kt index 1cd46e37..a4dc130c 100644 --- a/src/main/kotlin/com/coder/gateway/views/CoderGatewayConnectorWizardView.kt +++ b/src/main/kotlin/com/coder/gateway/views/CoderGatewayConnectorWizardView.kt @@ -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() private var currentStep = 0 private val model = CoderWorkspacesWizardModel() @@ -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() diff --git a/src/main/kotlin/com/coder/gateway/views/CoderGatewayConnectorWizardWrapperView.kt b/src/main/kotlin/com/coder/gateway/views/CoderGatewayConnectorWizardWrapperView.kt index f48732ee..8e25b44f 100644 --- a/src/main/kotlin/com/coder/gateway/views/CoderGatewayConnectorWizardWrapperView.kt +++ b/src/main/kotlin/com/coder/gateway/views/CoderGatewayConnectorWizardWrapperView.kt @@ -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() } } \ No newline at end of file diff --git a/src/main/kotlin/com/coder/gateway/views/CoderGatewayRecentWorkspaceConnectionsView.kt b/src/main/kotlin/com/coder/gateway/views/CoderGatewayRecentWorkspaceConnectionsView.kt index 221f1bc9..9b919585 100644 --- a/src/main/kotlin/com/coder/gateway/views/CoderGatewayRecentWorkspaceConnectionsView.kt +++ b/src/main/kotlin/com/coder/gateway/views/CoderGatewayRecentWorkspaceConnectionsView.kt @@ -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 @@ -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 @@ -41,43 +45,69 @@ class CoderGatewayRecentWorkspaceConnectionsView : GatewayRecentConnections, Dis private val recentConnectionsService = service() 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 = this@applyToComponent.text + 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") @@ -87,7 +117,7 @@ class CoderGatewayRecentWorkspaceConnectionsView : GatewayRecentConnections, Dis } private fun updateContentView(groupedConnections: Map>) { - contentPanel.viewport.view = panel { + recentWorkspacesContentPanel.viewport.view = panel { groupedConnections.entries.forEach { (hostname, recentConnections) -> row { if (hostname != null) { diff --git a/src/main/resources/messages/CoderGatewayBundle.properties b/src/main/resources/messages/CoderGatewayBundle.properties index 2fd16be0..1f6314fe 100644 --- a/src/main/resources/messages/CoderGatewayBundle.properties +++ b/src/main/resources/messages/CoderGatewayBundle.properties @@ -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 \ No newline at end of file