blob: 09f72540de36f28ec6e0049305b8746e0d16c8b6 [file] [log] [blame]
#=============================================================================#
# Copyright (c) 2009, 2021 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================#
## R IDE
#' Opens a file in an editor in StatET
#' @param filename name of file to open
#'
#' @export
openInEditor <- function(name, fileName, elementName, filename) {
if (!missing(filename)) {
fileName <- filename
}
if (missing(name) && missing(fileName) && missing(elementName)) {
stop("Missing argument: name")
}
if (missing(fileName) && missing(elementName)) {
# auto
fileName <- NULL
elementName <- NULL
if (is.character(name) && length(name) == 1) {
fileName <- name
}
else {
elementName <- substitute(name)
}
}
else if (!missing(elementName)) {
fileName <- NULL
elementName # test, if it refers to an existing element
elementName <- substitute(elementName)
}
else if (!missing(fileName)) {
elementName <- NULL
}
if (!is.null(fileName)) {
if (!is.character(fileName) || length(fileName) != 1) {
stop("Illegal argument: fileName")
}
.client.execCommand("common/showFile", list(
filename= fileName ), wait= TRUE)
}
else {
elementName <- deparse(elementName, backtick= TRUE, control= c(),
width.cutoff= 500, nlines= 2L)
if (length(elementName) != 1) {
stop("Illegal argument: elementName")
}
.client.execCommand("showElement", list(
elementName= elementName ), wait= TRUE)
}
return (invisible())
}
#' Opens the package manager in StatET
#'
#' @export
openPackageManager <- function() {
.client.execCommand("r/openPackageManager", wait= FALSE)
return (invisible())
}
#' Asks the user to choose a file using the StatET GUI.
#'
#' @param new if the choosen file can be new (does not yet exits)
#' @export
chooseFile <- function(new= FALSE) {
if (!is.logical(new) || length(new) != 1) {
stop("Illegal argument: new");
}
answer <- .client.execCommand("common/chooseFile", list(
newResource= new ),
wait= TRUE );
if (is.null(answer)) { # operation cancelled
return (invisible());
}
return (answer$filename);
}
#' Shows the content of the specified text files in the StatET/RJ client.
#'
#' @param ... the path of the files to show
#' @param fileEncoding the encoding of the files
#' @param title an overall title to display
#' @param headers headers to display for each file to show
#' @param deleteFiles \code{TRUE} if files should be deleted
#' @param pager (currently not used)
#' @export
showTextFiles <- function(..., fileEncoding= utils::localeToCharset()[1],
title= "R Information", headers= character(n),
deleteFiles= FALSE,
pager= NA_character_) {
filePaths <- path.expand(c(...));
n <- length(filePaths);
if (!is.character(fileEncoding) || length(fileEncoding) != 1) {
stop("Illegal argument: fileEncoding");
}
if (!is.character(title) || length(title) != 1) {
stop("Illegal argument: title");
}
if (!is.character(headers) || length(headers) != n) {
stop("Illegal argument: headers");
}
if (!is.logical(deleteFiles) || length(deleteFiles) != 1) {
stop("Illegal argument: deleteFiles");
}
if (!is.character(pager) || length(pager) != 1) {
stop("Illegal argument: pager");
}
.Call("Re_ExecJCommand", "re:showContents", list(
filePaths= filePaths, fileEncoding= fileEncoding,
title= title, headers= headers,
deleteFiles= deleteFiles,
pager= pager ),
0L,
PACKAGE= "(embedding)" );
return (invisible());
}
#' Shows the content of the specified text files in the StatET/RJ client.
#'
#' This is an R implementation of a pager for \link[base]{file.show} /
#' \code{\link[base]{options}(pager)} for StatET/RJ clients.
#'
#' @export
rj.pager <- function(files, header, title, delete.file, ...) {
showTextFiles(files,
title= title, headers= header,
deleteFiles= delete.file );
}
#' Shows the Cmd History view in StatET
#'
#' @export
statet.showHistory <- function() {
.client.execCommand("common/showHistory", wait= FALSE)
return (invisible())
}
#' Initializes extensions for StatET IDE
#'
#' @param mode debug mode
#' @param ext enable extensions for better debugging experience
#'
#' @export
.statet.initDebug <- function(mode= FALSE, ext, ...) {
if (mode) {
dbg.init(...);
}
}
#' Configures R help for StatET IDE
#'
#' @export
.statet.initHelp <- function(...) {
}