diff --git a/CHANGELOG.md b/CHANGELOG.md index 33c14236..6bb23337 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ ## Unreleased +### Added + +- Added setting "Default IDE Selection" which will look for a matching IDE + code/version/build number to set as the preselected IDE in the select + component. + ## 2.15.2 - 2025-01-06 ### Changed diff --git a/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt b/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt index 5b69f39e..9bd02350 100644 --- a/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt +++ b/src/main/kotlin/com/coder/gateway/CoderSettingsConfigurable.kt @@ -149,6 +149,14 @@ class CoderSettingsConfigurable : BoundConfigurable("Coder") { .bindText(state::workspaceFilter) .comment(CoderGatewayBundle.message("gateway.connector.settings.workspace-filter.comment")) }.layout(RowLayout.PARENT_GRID) + row(CoderGatewayBundle.message("gateway.connector.settings.default-ide")) { + textField().resizableColumn().align(AlignX.FILL) + .bindText(state::defaultIde) + .comment( + "The default IDE version to display in the IDE selection dropdown. " + + "Example format: CL 2023.3.6 233.15619.8", + ) + } } } diff --git a/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt b/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt index 4a33a091..492db8e6 100644 --- a/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt +++ b/src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt @@ -100,6 +100,8 @@ open class CoderSettingsState( open var sshLogDirectory: String = "", // Default filter for fetching workspaces open var workspaceFilter: String = "owner:me", + // Default version of IDE to display in IDE selection dropdown + open var defaultIde: String = "", ) /** @@ -174,6 +176,12 @@ open class CoderSettings( val setupCommand: String get() = state.setupCommand + /** + * The default IDE version to display in the selection menu + */ + val defaultIde: String + get() = state.defaultIde + /** * Whether to ignore a failed setup command. */ diff --git a/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt b/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt index 8478e355..69709018 100644 --- a/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt +++ b/src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt @@ -8,6 +8,7 @@ import com.coder.gateway.models.toIdeWithStatus import com.coder.gateway.models.withWorkspaceProject import com.coder.gateway.sdk.v2.models.Workspace import com.coder.gateway.sdk.v2.models.WorkspaceAgent +import com.coder.gateway.services.CoderSettingsService import com.coder.gateway.util.Arch import com.coder.gateway.util.OS import com.coder.gateway.util.humanizeDuration @@ -20,6 +21,7 @@ import com.coder.gateway.views.LazyBrowserLink import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ModalityState import com.intellij.openapi.application.asContextElement +import com.intellij.openapi.components.service import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.ui.ComboBox import com.intellij.openapi.ui.ComponentValidator @@ -79,6 +81,11 @@ import javax.swing.ListCellRenderer import javax.swing.SwingConstants import javax.swing.event.DocumentEvent +// Just extracting the way we display the IDE info into a helper function. +private fun displayIdeWithStatus(ideWithStatus: IdeWithStatus): String = "${ideWithStatus.product.productCode} ${ideWithStatus.presentableVersion} ${ideWithStatus.buildNumber} | ${ideWithStatus.status.name.lowercase( + Locale.getDefault(), +)}" + /** * View for a single workspace. In particular, show available IDEs and a button * to select an IDE and project to run on the workspace. @@ -88,6 +95,8 @@ class CoderWorkspaceProjectIDEStepView( ) : CoderWizardStep( CoderGatewayBundle.message("gateway.connector.view.coder.remoteproject.next.text"), ) { + private val settings: CoderSettingsService = service() + private val cs = CoroutineScope(Dispatchers.IO) private var ideComboBoxModel = DefaultComboBoxModel() private var state: CoderWorkspacesStepSelection? = null @@ -258,9 +267,24 @@ class CoderWorkspaceProjectIDEStepView( ) }, ) + + // Check the provided setting to see if there's a default IDE to set. + val defaultIde = ides.find { it -> + // Using contains on the displayable version of the ide means they can be as specific or as vague as they want + // CL 2023.3.6 233.15619.8 -> a specific Clion build + // CL 2023.3.6 -> a specific Clion version + // 2023.3.6 -> a specific version (some customers will only have one specific IDE in their list anyway) + if (settings.defaultIde.isEmpty()) { + false + } else { + displayIdeWithStatus(it).contains(settings.defaultIde) + } + } + val index = ides.indexOf(defaultIde ?: ides.firstOrNull()) + withContext(Dispatchers.IO) { ideComboBoxModel.addAll(ides) - cbIDE.selectedIndex = 0 + cbIDE.selectedIndex = index } } catch (e: Exception) { if (isCancellation(e)) { @@ -457,9 +481,9 @@ class CoderWorkspaceProjectIDEStepView( add(JLabel(ideWithStatus.product.ideName, ideWithStatus.product.icon, SwingConstants.LEFT)) add( JLabel( - "${ideWithStatus.product.productCode} ${ideWithStatus.presentableVersion} ${ideWithStatus.buildNumber} | ${ideWithStatus.status.name.lowercase( - Locale.getDefault(), - )}", + displayIdeWithStatus( + ideWithStatus, + ), ).apply { foreground = UIUtil.getLabelDisabledForeground() }, diff --git a/src/main/resources/messages/CoderGatewayBundle.properties b/src/main/resources/messages/CoderGatewayBundle.properties index 0f684b71..71000593 100644 --- a/src/main/resources/messages/CoderGatewayBundle.properties +++ b/src/main/resources/messages/CoderGatewayBundle.properties @@ -138,3 +138,4 @@ gateway.connector.settings.workspace-filter.comment=The filter to apply when \ the plugin fetches resources individually for each non-running workspace, \ which can be slow with many workspaces, and it adds every agent to the SSH \ config, which can result in a large SSH config with many workspaces. +gateway.connector.settings.default-ide=Default IDE Selection