From d1a82c94b39b1366db8afbdb877913f1ac7a747b Mon Sep 17 00:00:00 2001 From: Garrick Aden-Buie Date: Fri, 1 Nov 2019 08:44:33 -0400 Subject: [PATCH] Choose directory for theme installation for RStudio 1.2 or 1.3 For #3 https://github.com/gadenbuie/rsthemes/issues/3#issuecomment-548264955 --- DESCRIPTION | 2 +- NEWS.md | 9 +++++++++ R/rsthemes.R | 19 ++++++++++++++----- R/utils.R | 6 +++++- man/rsthemes.Rd | 11 ++++++++--- 5 files changed, 37 insertions(+), 10 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 0446854..225ca17 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rsthemes Title: Full Themes for RStudio v1.2+ -Version: 0.0.2 +Version: 0.0.3 Authors@R: person(given = "Garrick", family = "Aden-Buie", diff --git a/NEWS.md b/NEWS.md index 344ff8e..86cd3a2 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,12 @@ +# rsthemes 0.0.3 + +* Choose theme installation directory based on RStudio version. For 1.3.555+ the + themes are now installed into `~/.config/rstudio/themes`. An additional + `destdir` argument was added to `install_rsthemes()` for future flexibility. + Related to this RStudio desktop issue: + https://github.com/rstudio/rstudio/issues/5674#issuecomment-548484300. + (thanks @pat-s) + # rsthemes 0.0.2 * Added automatic light/dark mode switching with `use_theme_auto()` and diff --git a/R/rsthemes.R b/R/rsthemes.R index 747c329..c1481e9 100644 --- a/R/rsthemes.R +++ b/R/rsthemes.R @@ -7,8 +7,8 @@ #' provide an easy-to-extend framework for customizing the look of RStudio. See #' [new_rstheme()] for more information about creating your own theme. I've done #' my best to avoid hacky CSS rules wherever possible, and the themes are tested -#' against the current production release of RStudio (verision 1.2.1335 as of -#' June 11, 2019). Please report any issues you encounter here: +#' against the current production release of RStudio (version 1.2.1335 through +#' 1.3+ as of November 1, 2019). Please report any issues you encounter here: #' [github.com/gadenbuie/rsthemes/issues](https://github.com/gadenbuie/rsthemes/issues). #' #' @name rsthemes @@ -18,17 +18,26 @@ NULL #' @param style Limit to a subgroup of themes, chosen from the options returned #' by [rsthemes_styles()]. #' @param include_base16 Should the `base16` themes be included? +#' @param destdir The desination directory for the `.rstheme` files. By default +#' will attempt to choose the correct directory for the current RStudio +#' version 1.2 or 1.3+. #' @export -install_rsthemes <- function(style = "all", include_base16 = FALSE) { +install_rsthemes <- function(style = "all", include_base16 = FALSE, destdir = NULL) { theme_files <- list_pkg_rsthemes(style, include_base16) theme_files <- unname(theme_files) theme_rstudio_files <- paste0("rsthemes_", fs::path_file(theme_files)) - fs::dir_create(rstudio_theme_home()) + if (is.null(destdir)) { + destdir <- rstudio_theme_home() + message("Installing themes to ", destdir) + } + destdir <- fs::path_abs(destdir) + fs::dir_create(destdir) + fs::file_copy( theme_files, - fs::path(rstudio_theme_home(), theme_rstudio_files), + fs::path(destdir, theme_rstudio_files), overwrite = TRUE ) message("Installed ", length(theme_files), " themes, ", diff --git a/R/utils.R b/R/utils.R index 2ed0726..11a0676 100644 --- a/R/utils.R +++ b/R/utils.R @@ -29,7 +29,11 @@ package_template <- function(...) { } rstudio_theme_home <- function(...) { - fs::path_home_r(".R", "rstudio", "themes", ...) + if (rstudioapi::versionInfo()$version >= "1.3.555") { + fs::path_home_r(".config", "rstudio", "themes", ...) + } else { + fs::path_home_r(".R", "rstudio", "themes", ...) + } } cp_to_rstudio <- function(file, overwrite = TRUE) { diff --git a/man/rsthemes.Rd b/man/rsthemes.Rd index 96697db..d8b4234 100644 --- a/man/rsthemes.Rd +++ b/man/rsthemes.Rd @@ -9,7 +9,8 @@ \alias{rsthemes_styles} \title{Full RStudio Themes} \usage{ -install_rsthemes(style = "all", include_base16 = FALSE) +install_rsthemes(style = "all", include_base16 = FALSE, + destdir = NULL) remove_rsthemes(style = rsthemes_styles(), include_base16 = TRUE) @@ -26,6 +27,10 @@ by \code{\link[=rsthemes_styles]{rsthemes_styles()}}.} \item{include_base16}{Should the \code{base16} themes be included?} +\item{destdir}{The desination directory for the \code{.rstheme} files. By default +will attempt to choose the correct directory for the current RStudio +version 1.2 or 1.3+.} + \item{list_installed}{Should the installed \pkg{rsthemes} themes be listed (default). If \code{FALSE}, the available themes in the \pkg{rsthemes} package are listed instead.} @@ -46,8 +51,8 @@ ultimately, contain the CSS files that provide the themes. The sass templates provide an easy-to-extend framework for customizing the look of RStudio. See \code{\link[=new_rstheme]{new_rstheme()}} for more information about creating your own theme. I've done my best to avoid hacky CSS rules wherever possible, and the themes are tested -against the current production release of RStudio (verision 1.2.1335 as of -June 11, 2019). Please report any issues you encounter here: +against the current production release of RStudio (version 1.2.1335 through +1.3+ as of November 1, 2019). Please report any issues you encounter here: \href{https://github.com/gadenbuie/rsthemes/issues}{github.com/gadenbuie/rsthemes/issues}. } \section{Functions}{