@@ -217,53 +217,52 @@ define_keywords <- function(..., ask = TRUE, file = NA) {
217217 dialog_error <- FALSE
218218 if (isTRUE(resp )) {
219219 while (! filename_ok ) {
220- dir_name <- rstudioapi :: selectDirectory(
221- caption = " Choose directory for custom language file"
220+ filename <- rstudioapi :: selectFile(
221+ caption = " Save custom language file" ,
222+ label = " Save" ,# Enter file name, including extension (.csv)",
223+ path = getwd(),
224+ filter = " CSV file (*.csv)" ,
225+ existing = FALSE
222226 )
223- if (is.null(dir_name )) {
224- # dialog cancelled
227+ if (is.null(filename )) {
228+ # dialog cancelled -- validate cancel action
225229 filename <- " "
226230 filename_ok <- TRUE
227- message(" Custom language file not saved" )
228231 } else {
229- filename <- rstudioapi :: showPrompt(
230- title = " Custom language file" ,
231- message = " Enter file name, including extension (.csv)" ,
232- default = " custom_lang.csv"
233- )
234- if (is.null(filename )) {
235- # dialog cancelled -- validate cancel action
236- filename <- " "
237- filename_ok <- ! rstudioapi :: showQuestion(
238- title = " Custom language file" ,
239- message = " Invalid file name." ,
232+ # make sure csv / txt extension is there
233+ if (! grepl(" \\ .(csv|txt)$" , filename )) {
234+ rv <- rstudioapi :: showQuestion(
235+ title = " Save custom language file" ,
236+ message = " Invalid file extension (must be .csv)" ,
237+ ok = " Retry"
238+ )
239+ if (rv == " cancel" ) {
240+ filename <- " "
241+ filename_ok <- TRUE
242+ } else {
243+ filename_ok <- FALSE
244+ next
245+ }
246+ }
247+ filename <- normalizePath(filename , mustWork = FALSE )
248+ if (! isTRUE(check_path_for_output(filename ,
249+ overwrite = TRUE ))) {
250+ rv <- rstudioapi :: showQuestion(
251+ title = " Custom language file" ,
252+ message = " Invalid file name or location" ,
240253 ok = " Retry" ,
241254 cancel = " Cancel"
242255 )
243- } else {
244- filename <- normalizePath(
245- paste(dir_name , filename , sep = .Platform $ file.sep ),
246- mustWork = FALSE
247- )
248- if (! isTRUE(check_path_for_output(filename ,
249- overwrite = TRUE ))) {
250- rv <- rstudioapi :: showQuestion(
251- title = " Custom language file" ,
252- message = " Invalid file name or location" ,
253- ok = " Retry" ,
254- cancel = " Cancel"
255- )
256- if (! rv ) {
257- # cancel confirmed
258- filename <- " "
259- filename_ok <- TRUE
260- }
261- } else {
262- # Filename is valid
256+ if (! rv ) {
257+ # cancel confirmed
258+ filename <- " "
263259 filename_ok <- TRUE
264260 }
265- }
266- }
261+ } else {
262+ # Filename is valid
263+ filename_ok <- TRUE
264+ }
265+ }
267266 } # while
268267 } # save yes
269268 }
0 commit comments