boB Rudis
5 years ago
8 changed files with 250 additions and 6 deletions
@ -0,0 +1,57 @@ |
|||||
|
// |
||||
|
// RStudioServerAction.swift |
||||
|
// RSwitch |
||||
|
// |
||||
|
// Created by hrbrmstr on 9/5/19. |
||||
|
// Copyright © 2019 Bob Rudis. All rights reserved. |
||||
|
// |
||||
|
|
||||
|
import Foundation |
||||
|
import Cocoa |
||||
|
|
||||
|
extension AppDelegate { |
||||
|
|
||||
|
@objc func newRstudioServerSession(_ sender: NSMenuItem) { |
||||
|
print("New Session") |
||||
|
} |
||||
|
|
||||
|
@objc func activateServerSession(_ sender: NSMenuItem) { |
||||
|
|
||||
|
print("activate Session") |
||||
|
|
||||
|
let sess = (sender.representedObject as! RStudioServerSession) |
||||
|
|
||||
|
sess.show() |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
class RStudioServerMenuAction { |
||||
|
|
||||
|
public static func populateRStudioServerSessions(menu: NSMenu, manager : RStudioServerSessionManager) { |
||||
|
|
||||
|
menu.addItem(NSMenuItem.separator()) |
||||
|
|
||||
|
let rsDropdown = NSMenuItem(title: "RStudio Server Sessions", action: nil, keyEquivalent: "") |
||||
|
let rsSub = NSMenu() |
||||
|
|
||||
|
menu.addItem(rsDropdown) |
||||
|
menu.setSubmenu(rsSub, for: rsDropdown) |
||||
|
|
||||
|
let newRStudioSessItem = NSMenuItem(title: "New RStudio Server Connection…", action: Selector(("newRstudioServerSession:")), keyEquivalent: "") |
||||
|
|
||||
|
rsSub.addItem(newRStudioSessItem) |
||||
|
rsSub.addItem(NSMenuItem.separator()) |
||||
|
|
||||
|
for sess in manager.sessions { |
||||
|
|
||||
|
let sessItem = NSMenuItem(title: sess.menuTitle, action: Selector(("activateServerSession:")), keyEquivalent: "") |
||||
|
sessItem.representedObject = sess |
||||
|
rsSub.addItem(sessItem) |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,43 @@ |
|||||
|
// |
||||
|
// RStudioServerSession.swift |
||||
|
// RSwitch |
||||
|
// |
||||
|
// Created by hrbrmstr on 9/5/19. |
||||
|
// Copyright © 2019 Bob Rudis. All rights reserved. |
||||
|
// |
||||
|
|
||||
|
import Foundation |
||||
|
import Cocoa |
||||
|
|
||||
|
class RStudioServerSession { |
||||
|
|
||||
|
var url : String |
||||
|
var menuTitle : String |
||||
|
var wk : NSWindowController? |
||||
|
var wv : WebViewController? |
||||
|
|
||||
|
init(url: String, title: String) { |
||||
|
self.url = url |
||||
|
self.menuTitle = title |
||||
|
} |
||||
|
|
||||
|
func show() { |
||||
|
|
||||
|
let appDelegate = NSApplication.shared.delegate as! AppDelegate |
||||
|
let mainStoryboard = appDelegate.mainStoryboard! |
||||
|
|
||||
|
if (wk == nil) { |
||||
|
wk = (mainStoryboard.instantiateController(withIdentifier: "wkPanelController") as! NSWindowController) |
||||
|
wv = wk!.window?.contentViewController as? WebViewController |
||||
|
wv!.url = url |
||||
|
} |
||||
|
|
||||
|
wk?.window?.orderFront(appDelegate) |
||||
|
wk?.showWindow(appDelegate) |
||||
|
wk?.window?.orderFront(appDelegate) |
||||
|
|
||||
|
NSApp.activate(ignoringOtherApps: true) |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,29 @@ |
|||||
|
// |
||||
|
// RStudioServerSessionManager.swift |
||||
|
// RSwitch |
||||
|
// |
||||
|
// Created by hrbrmstr on 9/5/19. |
||||
|
// Copyright © 2019 Bob Rudis. All rights reserved. |
||||
|
// |
||||
|
|
||||
|
import Foundation |
||||
|
import Cocoa |
||||
|
import WebKit |
||||
|
|
||||
|
class RStudioServerSessionManager { |
||||
|
|
||||
|
var sessions = [ RStudioServerSession ]() |
||||
|
|
||||
|
func newSession(url: String, title: String) { |
||||
|
sessions.append(RStudioServerSession(url: url, title: title)) |
||||
|
} |
||||
|
|
||||
|
func debugSessions() { |
||||
|
|
||||
|
for s in sessions { |
||||
|
print(s.menuTitle) |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
@ -0,0 +1,29 @@ |
|||||
|
// |
||||
|
// WebViewController.swift |
||||
|
// RSwitch |
||||
|
// |
||||
|
// Created by hrbrmstr on 9/5/19. |
||||
|
// Copyright © 2019 Bob Rudis. All rights reserved. |
||||
|
// |
||||
|
|
||||
|
import Cocoa |
||||
|
import WebKit |
||||
|
|
||||
|
class WebViewController: NSViewController { |
||||
|
|
||||
|
@IBOutlet weak var rstudioServerView: WKWebView! |
||||
|
|
||||
|
var url = "https://rstudio.hrbrmstr.de/" |
||||
|
|
||||
|
override func viewDidLoad() { |
||||
|
super.viewDidLoad() |
||||
|
} |
||||
|
|
||||
|
override func viewDidAppear() { |
||||
|
super.viewDidAppear() |
||||
|
self.view.window?.title = url |
||||
|
let request = URLRequest(url: URL(string: url)!) |
||||
|
rstudioServerView.load(request) |
||||
|
} |
||||
|
|
||||
|
} |
Loading…
Reference in new issue