Skip to content

Commit a9e37d1

Browse files
committed
Made Positron compatible: fallsback to text version of the dialogs when not implemented in Positron
1 parent a0d8eb0 commit a9e37d1

7 files changed

Lines changed: 49 additions & 11 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: svDialogs
22
Type: Package
3-
Version: 1.1.1
3+
Version: 1.1.2
44
Title: 'SciViews::R' - Standard Dialog Boxes for Windows, MacOS and Linuxes
55
Description: Quickly construct standard dialog boxes for your GUI, including
66
message boxes, input boxes, list, file or directory selection, ... In case R

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# svDialogs 1.1.2
2+
3+
- Made compatible with Positron as much as possible (many RStudio dialog boxes are NOT implemented in Positron, resulting in a fallback to the console text version).
4+
15
# svDialogs 1.1.1
26

37
- Updated CITATION file to the new format.

R/dlg_dir.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,14 @@ rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI) {
129129

130130
# RStudio version
131131
.rstudio_dlg_dir <- function(default = getwd(), title = "") {
132-
res <- rstudioapi::selectDirectory(caption = title, path = default)
132+
# Positron current (2025-11-06) fools rstudioapi, and it is recognized
133+
# as RStudio (desktop). However, it does not implements
134+
# rstudioapi::selectDirectory()
135+
# Catch the error, and move to next implementation
136+
res <- try(rstudioapi::selectDirectory(caption = title, path = default),
137+
silent = TRUE)
138+
if (inherits(res, "try-error"))
139+
return(NULL)
133140
if (is.null(res)) {
134141
res <- character(0)
135142
} else{
@@ -140,13 +147,13 @@ rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI) {
140147

141148
# Windows version
142149
.win_dlg_dir <- function(default = getwd(), title = "") {
143-
res <- choose.dir(default = default, caption = title)
150+
res <- choose.dir(default = default, caption = title)
144151
if (is.na(res)) {
145152
res <- character(0)
146153
} else {
147154
res <- path.expand(gsub("\\\\", "/", res))
148155
}
149-
res
156+
res
150157
}
151158

152159
# MacOS version

R/dlg_input.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,14 @@ rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI) {
119119
.rstudio_dlg_input <- function(message, default) {
120120
if (rstudioapi::getVersion() < '1.1.67')
121121
return(NULL)
122-
res <- rstudioapi::showPrompt(title = "R prompt", message = message,
123-
default = default)
122+
# Positron current (2025-11-06) fools rstudioapi, and it is recognized
123+
# as RStudio (desktop). However, it does not implements
124+
# rstudioapi::selectDirectory()
125+
# Catch the error, and move to next implementation
126+
res <- try(rstudioapi::showPrompt(title = "R prompt", message = message,
127+
default = default), silent = TRUE)
128+
if (inherits(res, "try-error"))
129+
return(NULL)
124130
if (is.null(res)) {
125131
character(0)
126132
} else{

R/dlg_open.R

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,17 @@ filters = dlg_filters["All", ], rstudio = getOption("svDialogs.rstudio", TRUE),
249249
label = "Open", existing = TRUE)
250250
}
251251
} else {# Single file
252-
res <- rstudioapi::selectFile(caption = title, path = default,
253-
label = "Open", existing = TRUE) #, filter = filters) # Does not work: filters are specified differently in RStudio!
252+
# Positron current (2025-11-06) fools rstudioapi, and it is recognized
253+
# as RStudio (desktop). However, it does not implements
254+
# rstudioapi::selectDirectory()
255+
# Catch the error, and move to next implementation
256+
res <- try(rstudioapi::selectFile(caption = title, path = default,
257+
label = "Open", existing = TRUE), #, filter = filters) # Does not work: filters are specified differently in RStudio!
258+
silent = TRUE)
259+
if (inherits(res, "try-error"))
260+
return(NULL)
254261
}
255-
if (is.null(res) || res == "") {
262+
if (is.null(res) || (length(res) == 1L && res == "")) {
256263
res <- character(0)
257264
} else{
258265
res <- path.expand(gsub("\\\\", "/", res))

R/dlg_save.R

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,18 @@ rstudio = getOption("svDialogs.rstudio", TRUE), ..., gui = .GUI) {
166166
title = "", filters = dlg_filters["All", ]) {
167167
if (rstudioapi::getVersion() < '1.1.287')
168168
return(NULL)
169+
# Positron current (2025-11-06) fools rstudioapi, and it is recognized
170+
# as RStudio (desktop). However, it does not implements
171+
# rstudioapi::selectDirectory()
172+
# Catch the error, and move to next implementation
173+
169174
# I don't understand how filter is used in selectFile(). So, I prefer **not**
170175
# to use it for now!
171-
res <- rstudioapi::selectFile(caption = title, path = default,
172-
label = "Save", existing = FALSE) #, filter = filters) # Filter implemented differently on RStudio
176+
res <- try(rstudioapi::selectFile(caption = title, path = default,
177+
label = "Save", existing = FALSE), #, filter = filters) # Filter implemented differently on RStudio
178+
silent = TRUE)
179+
if (inherits(res, "try-error"))
180+
return(NULL)
173181
if (is.null(res)) {
174182
res <- character(0)
175183
} else{

R/svDialogs-internal.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323
.is_rstudio_desktop <- function() rstudioapi::versionInfo()$mode == "desktop"
2424

25+
# Positron fools rstudioapi, letting it beleive it is RStudio
26+
# This trick is the only one I found to get Positron from rstudioapi
27+
# (but one could also seach for "tools:positron" on the search path)
28+
.is_positron <- function()
29+
grepl("Positron", rstudioapi::versionInfo()$citation, fixed = TRUE)
30+
2531
# With yad or zenity, I cannot have double quotes inside strings: escape them
2632
.escape_quotes <- function(str) {
2733
# For yad messages, we need to escape double quotes **inside** messages

0 commit comments

Comments
 (0)