在RStudio中将项目添加到上下文菜单(右键单击)

时间:2018-09-27 17:30:52

标签: rstudio

(交叉发布到https://github.com/rstudio/rstudioapi/issues/112) 我想将一个项目添加到我的RStudio副本的右键单击上下文菜单中,但是如果可能的话,我还没有弄清楚;)

此代码在左上方的“源代码”窗口中使用突出显示的块并反转反斜杠(以便Windows路径由R适当处理,而不是抛出诸如try-Catch-able的错误,如下所示)

  

> try(print("c:\ljafasfsf"),silent=TRUE)

     

错误:'\ l'是无法识别的以“” c:\ l“开头的字符串的转义符

makewinpath<-function() {
  try({
    adc<-rstudioapi::getSourceEditorContext()
    ps<-rstudioapi::primary_selection(adc)
    t<-ps$text
    t<-gsub("\\\\","/",t)
    rstudioapi::modifyRange(ps$`range`,t,adc$id)
    rstudioapi::setSelectionRanges(ps$`range`,adc$id)
  })
}

.rs.addJsonRpcHandler("convert_windows_path_to_R_style",makewinpath)

但是,我似乎无法弄清楚如何将项目添加到上下文菜单或如何将调用挂接到现有onContextMenu事件处理程序的textarea.ace_text-input元素的末尾,即通过从现有的上下文菜单中选择“检查”即可显示。

0 个答案:

没有答案