Skip to content

Commit 1ba763b

Browse files
committed
Initial impl of defaultIde selection setting
1 parent faddd24 commit 1ba763b

File tree

5 files changed

+47
-6
lines changed

5 files changed

+47
-6
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ To simulate opening a workspace from the dashboard pass the Gateway link via
3434
`--args`. For example:
3535

3636
```
37-
./gradlew clean runIDE --args="jetbrains-gateway://connect#type=coder&workspace=dev&agent=coder&folder=/home/coder&url=https://dev.coder.com&token=<redacted>&ide_product_code=IU&ide_build_number=223.8836.41&ide_download_link=https://download.jetbrains.com/idea/ideaIU-2022.3.3.tar.gz"
37+
./gradlew clean runIDE --args="jetbrains-gateway://connect#type=coder&workspace=bcpeinhardt&owner=benpeinhardt&agent=dev&folder=/home/coder&url=https://dev.coder.com&token=<redacted>"
3838
```
3939

4040
Alternatively, if you have separately built the plugin and already installed it

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

+6
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ class CoderSettingsConfigurable : BoundConfigurable("Coder") {
149149
.bindText(state::workspaceFilter)
150150
.comment(CoderGatewayBundle.message("gateway.connector.settings.workspace-filter.comment"))
151151
}.layout(RowLayout.PARENT_GRID)
152+
row(CoderGatewayBundle.message("gateway.connector.settings.default-ide")) {
153+
textField().resizableColumn().align(AlignX.FILL)
154+
.bindText(state::defaultIde)
155+
.comment("The default IDE version to display in the IDE selection dropdown. " +
156+
"Example format: CL 2023.3.6 233.15619.8")
157+
}
152158
}
153159
}
154160

src/main/kotlin/com/coder/gateway/settings/CoderSettings.kt

+8
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ open class CoderSettingsState(
100100
open var sshLogDirectory: String = "",
101101
// Default filter for fetching workspaces
102102
open var workspaceFilter: String = "owner:me",
103+
// Default version of IDE to display in IDE selection dropdown
104+
open var defaultIde: String = "",
103105
)
104106

105107
/**
@@ -174,6 +176,12 @@ open class CoderSettings(
174176
val setupCommand: String
175177
get() = state.setupCommand
176178

179+
/**
180+
* The default IDE version to display in the selection menu
181+
*/
182+
val defaultIde: String
183+
get() = state.defaultIde
184+
177185
/**
178186
* Whether to ignore a failed setup command.
179187
*/

src/main/kotlin/com/coder/gateway/views/steps/CoderWorkspaceProjectIDEStepView.kt

+31-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.coder.gateway.models.toIdeWithStatus
88
import com.coder.gateway.models.withWorkspaceProject
99
import com.coder.gateway.sdk.v2.models.Workspace
1010
import com.coder.gateway.sdk.v2.models.WorkspaceAgent
11+
import com.coder.gateway.services.CoderSettingsService
1112
import com.coder.gateway.util.Arch
1213
import com.coder.gateway.util.OS
1314
import com.coder.gateway.util.humanizeDuration
@@ -20,6 +21,7 @@ import com.coder.gateway.views.LazyBrowserLink
2021
import com.intellij.openapi.application.ApplicationManager
2122
import com.intellij.openapi.application.ModalityState
2223
import com.intellij.openapi.application.asContextElement
24+
import com.intellij.openapi.components.service
2325
import com.intellij.openapi.diagnostic.Logger
2426
import com.intellij.openapi.ui.ComboBox
2527
import com.intellij.openapi.ui.ComponentValidator
@@ -54,6 +56,7 @@ import com.jetbrains.gateway.ssh.IdeWithStatus
5456
import com.jetbrains.gateway.ssh.IntelliJPlatformProduct
5557
import com.jetbrains.gateway.ssh.deploy.DeployException
5658
import com.jetbrains.gateway.ssh.util.validateRemotePath
59+
import com.jetbrains.rd.generator.nova.PredefinedType
5760
import kotlinx.coroutines.CoroutineScope
5861
import kotlinx.coroutines.Dispatchers
5962
import kotlinx.coroutines.Job
@@ -79,6 +82,13 @@ import javax.swing.ListCellRenderer
7982
import javax.swing.SwingConstants
8083
import javax.swing.event.DocumentEvent
8184

85+
// Just extracting the way we display the IDE info into a helper function.
86+
private fun displayIdeWithStatus(ideWithStatus: IdeWithStatus): String {
87+
return "${ideWithStatus.product.productCode} ${ideWithStatus.presentableVersion} ${ideWithStatus.buildNumber} | ${ideWithStatus.status.name.lowercase(
88+
Locale.getDefault(),
89+
)}"
90+
}
91+
8292
/**
8393
* View for a single workspace. In particular, show available IDEs and a button
8494
* to select an IDE and project to run on the workspace.
@@ -88,6 +98,8 @@ class CoderWorkspaceProjectIDEStepView(
8898
) : CoderWizardStep<WorkspaceProjectIDE>(
8999
CoderGatewayBundle.message("gateway.connector.view.coder.remoteproject.next.text"),
90100
) {
101+
private val settings: CoderSettingsService = service<CoderSettingsService>()
102+
91103
private val cs = CoroutineScope(Dispatchers.IO)
92104
private var ideComboBoxModel = DefaultComboBoxModel<IdeWithStatus>()
93105
private var state: CoderWorkspacesStepSelection? = null
@@ -258,9 +270,24 @@ class CoderWorkspaceProjectIDEStepView(
258270
)
259271
},
260272
)
273+
274+
// Check the provided setting to see if there's a default IDE to set.
275+
val defaultIde = ides.find { it ->
276+
// Using contains on the displayable version of the ide means they can be as specific or as vague as they want
277+
// CL 2023.3.6 233.15619.8 -> a specific Clion build
278+
// CL 2023.3.6 -> a specific Clion version
279+
// 2023.3.6 -> a specific version (some customers will on have one specific IDE in their list anyway)
280+
if (settings.defaultIde.isEmpty()) {
281+
false
282+
} else {
283+
displayIdeWithStatus(it).contains(settings.defaultIde)
284+
}
285+
}
286+
val index = ides.indexOf(defaultIde ?: ides.firstOrNull())
287+
261288
withContext(Dispatchers.IO) {
262289
ideComboBoxModel.addAll(ides)
263-
cbIDE.selectedIndex = 0
290+
cbIDE.selectedIndex = index
264291
}
265292
} catch (e: Exception) {
266293
if (isCancellation(e)) {
@@ -456,10 +483,9 @@ class CoderWorkspaceProjectIDEStepView(
456483
layout = FlowLayout(FlowLayout.LEFT)
457484
add(JLabel(ideWithStatus.product.ideName, ideWithStatus.product.icon, SwingConstants.LEFT))
458485
add(
459-
JLabel(
460-
"${ideWithStatus.product.productCode} ${ideWithStatus.presentableVersion} ${ideWithStatus.buildNumber} | ${ideWithStatus.status.name.lowercase(
461-
Locale.getDefault(),
462-
)}",
486+
JLabel(displayIdeWithStatus(
487+
ideWithStatus
488+
),
463489
).apply {
464490
foreground = UIUtil.getLabelDisabledForeground()
465491
},

src/main/resources/messages/CoderGatewayBundle.properties

+1
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,4 @@ gateway.connector.settings.workspace-filter.comment=The filter to apply when \
138138
the plugin fetches resources individually for each non-running workspace, \
139139
which can be slow with many workspaces, and it adds every agent to the SSH \
140140
config, which can result in a large SSH config with many workspaces.
141+
gateway.connector.settings.default-ide=Default IDE Selection

0 commit comments

Comments
 (0)