Skip to content

Commit ef3392b

Browse files
committed
fix: override default delete confirmation dialog
- right now there are two confirmation dialogs when removing a workspace from Toolbox - with this patch we force Toolbox to discard its default dialog and show a custom one with the Coder titles and messages.
1 parent 2ce2aa1 commit ef3392b

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixed
66

77
- SSH config is regenerated correctly when Workspaces are added or removed
8+
- only one confirmation dialog is shown when removing a Workspace
89

910
## 0.1.0 - 2025-04-01
1011

src/main/kotlin/com/coder/toolbox/CoderRemoteEnvironment.kt

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.coder.toolbox.sdk.v2.models.WorkspaceAgent
99
import com.coder.toolbox.util.withPath
1010
import com.coder.toolbox.views.Action
1111
import com.coder.toolbox.views.EnvironmentView
12+
import com.jetbrains.toolbox.api.remoteDev.DeleteEnvironmentConfirmationParams
1213
import com.jetbrains.toolbox.api.remoteDev.EnvironmentVisibilityState
1314
import com.jetbrains.toolbox.api.remoteDev.RemoteProviderEnvironment
1415
import com.jetbrains.toolbox.api.remoteDev.environments.EnvironmentContentsView
@@ -149,42 +150,36 @@ class CoderRemoteEnvironment(
149150
}
150151
}
151152

153+
override fun getDeleteEnvironmentConfirmationParams(): DeleteEnvironmentConfirmationParams? {
154+
return object : DeleteEnvironmentConfirmationParams {
155+
override val cancelButtonText: String = "Cancel"
156+
override val confirmButtonText: String = "Delete"
157+
override val message: String =
158+
if (wsRawStatus.canStop()) "Workspace will be closed and all the information will be lost, including all files, unsaved changes, historical info and usage data."
159+
else "All the information in this workspace will be lost, including all files, unsaved changes, historical info and usage data."
160+
override val title: String = if (wsRawStatus.canStop()) "Delete running workspace?" else "Delete workspace?"
161+
}
162+
}
163+
152164
override fun onDelete() {
153165
context.cs.launch {
154-
val shouldDelete = if (wsRawStatus.canStop()) {
155-
context.ui.showOkCancelPopup(
156-
context.i18n.ptrl("Delete running workspace?"),
157-
context.i18n.ptrl("Workspace will be closed and all the information in this workspace will be lost, including all files, unsaved changes and historical."),
158-
context.i18n.ptrl("Delete"),
159-
context.i18n.ptrl("Cancel")
160-
)
161-
} else {
162-
context.ui.showOkCancelPopup(
163-
context.i18n.ptrl("Delete workspace?"),
164-
context.i18n.ptrl("All the information in this workspace will be lost, including all files, unsaved changes and historical."),
165-
context.i18n.ptrl("Delete"),
166-
context.i18n.ptrl("Cancel")
167-
)
168-
}
169-
if (shouldDelete) {
170-
try {
171-
client.removeWorkspace(workspace)
172-
context.cs.launch {
173-
withTimeout(5.minutes) {
174-
var workspaceStillExists = true
175-
while (context.cs.isActive && workspaceStillExists) {
176-
if (wsRawStatus == WorkspaceAndAgentStatus.DELETING || wsRawStatus == WorkspaceAndAgentStatus.DELETED) {
177-
workspaceStillExists = false
178-
context.envPageManager.showPluginEnvironmentsPage()
179-
} else {
180-
delay(1.seconds)
181-
}
166+
try {
167+
client.removeWorkspace(workspace)
168+
context.cs.launch {
169+
withTimeout(5.minutes) {
170+
var workspaceStillExists = true
171+
while (context.cs.isActive && workspaceStillExists) {
172+
if (wsRawStatus == WorkspaceAndAgentStatus.DELETING || wsRawStatus == WorkspaceAndAgentStatus.DELETED) {
173+
workspaceStillExists = false
174+
context.envPageManager.showPluginEnvironmentsPage()
175+
} else {
176+
delay(1.seconds)
182177
}
183178
}
184179
}
185-
} catch (e: APIResponseException) {
186-
context.ui.showErrorInfoPopup(e)
187180
}
181+
} catch (e: APIResponseException) {
182+
context.ui.showErrorInfoPopup(e)
188183
}
189184
}
190185
}

0 commit comments

Comments
 (0)