//
// V e r s i o n s U t i l s . s w i f t
// R S w i t c h
//
// C r e a t e d b y h r b r m s t r o n 8 / 3 0 / 1 9 .
// C o p y r i g h t © 2 0 1 9 B o b R u d i s . A l l r i g h t s r e s e r v e d .
//
import Foundation
import Cocoa
extension AppDelegate {
// S h o w t h e f r a m e w o r k d i r i n a n e w F i n d e r w i n d o w
@objc func openFrameworksDir ( _ sender : NSMenuItem ? ) {
NSWorkspace . shared . openFile ( RVersions . macos_r_framework , withApplication : " Finder " )
}
func populateRunningApps ( menu : NSMenu ) {
// g a t h e r r u n n i n g R S t u d i o i n s t a n c e s
let running_rstudios = NSWorkspace . shared . runningApplications . filter {
$0 . bundleIdentifier = = " org.rstudio.RStudio "
}
// g a t h e r r u n n i n g R G U I i n s t a n c e s
let running_rapps = NSWorkspace . shared . runningApplications . filter {
$0 . bundleIdentifier = = " org.R-project.R "
}
// i f w e h a v e a n y r u n n i n g i n s t a n c e s o f a n y t h i n g
if ( ( running_rstudios . count ) + ( running_rapps . count ) > 0 ) {
menu . addItem ( NSMenuItem . separator ( ) )
let switchToDropdown = NSMenuItem ( title : " Switch to " , action : nil , keyEquivalent : " " )
let switchToSub = NSMenu ( )
menu . addItem ( switchToDropdown )
menu . setSubmenu ( switchToSub , for : switchToDropdown )
// p o p u l a t e R S t u d i o f i r s t ( i t ' l l b e i n l a u n c h o r d e r ) t h e n R G U I
for app in running_rstudios + running_rapps {
let args = getArgs ( app . processIdentifier ) !
let title = app . localizedName ! + ( args . count > 1 ? " : " + ( args [ 1 ] as ! NSString ) . lastPathComponent . replacingOccurrences ( of : " .Rproj " , with : " " ) : " " )
let mi = NSMenuItem ( title : title , action : #selector ( switch_to ) , keyEquivalent : " " )
mi . representedObject = app
switchToSub . addItem ( mi )
}
}
}
}