A small menubar app that allows you to switch between R versions quickly (if you have multiple versions of R framework installed). https://rud.is/rswitch
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

78 lines
2.8 KiB

//
// MenuAction.swift
// RSwitch
//
// Created by hrbrmstr on 8/30/19.
// Copyright © 2019 Bob Rudis. All rights reserved.
//
import Foundation
import Cocoa
extension AppDelegate {
@objc func browseFromMenu(_ sender: NSMenuItem) {
let url = (sender.representedObject as! BrowseMenuAction).url
NSWorkspace.shared.open(url)
}
}
class BrowseMenuAction {
public var title : String
public var selector : Selector
public var keyEquivalent : String
public var url : URL
private static let webItemsR = [
BrowseMenuAction(title: "R for macOS Developer's…", url: "https://mac.r-project.org/"),
BrowseMenuAction(title: "R for macOS CRAN…", url: "https://cran.rstudio.org/bin/macosx/"),
BrowseMenuAction(title: "R-SIG-Mac Archives…", url: "https://stat.ethz.ch/pipermail/r-sig-mac/"),
BrowseMenuAction(title: "R-devel News…", url: "https://developer.r-project.org/blosxom.cgi/R-devel/NEWS"),
BrowseMenuAction(title: "R-Forge macOS Subversion…", url: "http://svn.rforge.net/osx/trunk/"),
BrowseMenuAction(title: "R Installation/Admin macOS Section…", url: "https://cran.rstudio.org/doc/manuals/R-admin.html#Installing-R-under-macOS"),
]
private static let webItemsExt = [
BrowseMenuAction(title: "RStudio macOS Dailies…", url: "https://dailies.rstudio.com/rstudio/oss/mac/"),
BrowseMenuAction(title: "R StackOverflow…", url: "https://stackoverflow.com/questions/tagged/r"),
BrowseMenuAction(title: "RStudio Community…", url: "https://community.rstudio.com/"),
BrowseMenuAction(title: "Unofficial R-O GitHub CRAN Mirror…", url: "https://github.com/cran"),
BrowseMenuAction(title: "XQuartz (X11 for macOS)…", url: "https://www.xquartz.org/"),
BrowseMenuAction(title: "Homebrew (macOS Package Manager)…", url: "https://brew.sh/"),
BrowseMenuAction(title: "Apple Developer Portal…", url: "https://developer.apple.com/")
]
init(title: String, url: String, selector: String = "browseFromMenu", keyEquivalent: String = "") {
self.title = title
self.url = URL(string: url)!
self.selector = Selector((selector+":"))
self.keyEquivalent = keyEquivalent
}
public func asMenuItem() -> NSMenuItem {
let mi = NSMenuItem(title: title, action: selector, keyEquivalent: keyEquivalent)
mi.representedObject = self
return(mi)
}
public static func populateWebItems(menu : NSMenu) {
menu.addItem(NSMenuItem.separator())
let webDropdown = NSMenuItem(title: "Web resources", action: nil, keyEquivalent: "")
let webSub = NSMenu()
menu.addItem(webDropdown)
menu.setSubmenu(webSub, for: webDropdown)
for item in webItemsR { webSub.addItem(item.asMenuItem()) }
webSub.addItem(NSMenuItem.separator())
for item in webItemsExt { webSub.addItem(item.asMenuItem()) }
}
}