boB Rudis
5 years ago
8 changed files with 377 additions and 117 deletions
@ -0,0 +1,22 @@ |
|||
// |
|||
// PlotWebViewController.swift |
|||
// wktest |
|||
// |
|||
// Created by hrbrmstr on 9/9/19. |
|||
// Copyright © 2019 Bob Rudis. All rights reserved. |
|||
// |
|||
|
|||
import Cocoa |
|||
|
|||
class PlotWebViewController: NSWindowController { |
|||
|
|||
override func windowDidLoad() { |
|||
|
|||
shouldCascadeWindows = false |
|||
window?.setFrameAutosaveName(window!.title) |
|||
|
|||
super.windowDidLoad() |
|||
|
|||
} |
|||
|
|||
} |
@ -0,0 +1,96 @@ |
|||
// |
|||
// RStudioServerSessionWebViewController.swift |
|||
// wktest |
|||
// |
|||
// Created by hrbrmstr on 9/9/19. |
|||
// Copyright © 2019 Bob Rudis. All rights reserved. |
|||
// |
|||
|
|||
import Cocoa |
|||
import WebKit |
|||
|
|||
class RstudioServerSessionWebViewController: NSViewController, NSWindowDelegate { |
|||
|
|||
var webView: WKWebView! |
|||
var popupWebView: WKWebView? |
|||
|
|||
open override func viewDidLoad() { |
|||
super.viewDidLoad() |
|||
setupWebView() |
|||
} |
|||
|
|||
func setupWebView() { |
|||
|
|||
let preferences = WKPreferences() |
|||
preferences.javaScriptEnabled = true |
|||
preferences.javaScriptCanOpenWindowsAutomatically = true |
|||
|
|||
let configuration = WKWebViewConfiguration() |
|||
configuration.preferences = preferences |
|||
|
|||
webView = WKWebView(frame: view.bounds, configuration: configuration) |
|||
webView.autoresizingMask = [.width, .height] |
|||
webView.uiDelegate = self |
|||
webView.navigationDelegate = self |
|||
|
|||
view.addSubview(webView) |
|||
|
|||
} |
|||
|
|||
func loadWebView(urlIn: String) { |
|||
|
|||
if let url = URL(string: urlIn) { |
|||
let urlRequest = URLRequest(url: url) |
|||
webView.load(urlRequest) |
|||
} |
|||
|
|||
} |
|||
|
|||
} |
|||
|
|||
extension RstudioServerSessionWebViewController: WKUIDelegate { |
|||
|
|||
func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? { |
|||
|
|||
if navigationAction.targetFrame == nil { |
|||
|
|||
let plotWindowController = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "plotPopupPanel") as! PlotWebViewController |
|||
|
|||
let plotWV = (plotWindowController.contentViewController as! plotPopupViewController) |
|||
plotWV.view.window?.title = navigationAction.request.url!.absoluteString |
|||
plotWV.setupWebView(configuration: configuration) |
|||
plotWindowController.showWindow(self) |
|||
plotWV.loadWebView(urlIn: navigationAction.request.url!.absoluteString) |
|||
|
|||
return(plotWV.webView) |
|||
|
|||
} |
|||
|
|||
return(nil) |
|||
|
|||
} |
|||
|
|||
// func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? { |
|||
// popupWebView = WKWebView(frame: view.bounds, configuration: configuration) |
|||
// popupWebView!.autoresizingMask = [.width, .height] |
|||
// popupWebView!.navigationDelegate = self |
|||
// popupWebView!.uiDelegate = self |
|||
// view.addSubview(popupWebView!) |
|||
// return popupWebView! |
|||
// } |
|||
// |
|||
func webViewDidClose(_ webView: WKWebView) { |
|||
if webView == popupWebView { |
|||
popupWebView?.removeFromSuperview() |
|||
popupWebView = nil |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
extension RstudioServerSessionWebViewController: WKNavigationDelegate { |
|||
open func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { |
|||
} |
|||
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { |
|||
} |
|||
} |
@ -0,0 +1,40 @@ |
|||
// |
|||
// ToolbarWebViewController.swift |
|||
// wktest |
|||
// |
|||
// Created by hrbrmstr on 9/9/19. |
|||
// Copyright © 2019 Bob Rudis. All rights reserved. |
|||
// |
|||
|
|||
import Cocoa |
|||
|
|||
class ToolbarWebViewController: NSWindowController { |
|||
|
|||
@IBOutlet weak var nicknname: NSTextField! |
|||
@IBOutlet weak var url: NSTextField! |
|||
@IBOutlet weak var deleteSession: NSButton! |
|||
|
|||
@IBAction func performDeleteSession(_ sender: Any) { |
|||
|
|||
let appDelegate = NSApp.delegate as! AppDelegate |
|||
appDelegate.sess.deleteSession(title: nicknname.stringValue) |
|||
|
|||
super.close() |
|||
|
|||
} |
|||
|
|||
override func windowWillLoad() { |
|||
super.windowWillLoad() |
|||
shouldCascadeWindows = false |
|||
} |
|||
|
|||
override func windowDidLoad() { |
|||
super.windowDidLoad() |
|||
} |
|||
|
|||
override func showWindow(_ sender: Any?) { |
|||
super.showWindow(sender) |
|||
window?.setFrameAutosaveName(nicknname.stringValue) |
|||
} |
|||
|
|||
} |
@ -0,0 +1,61 @@ |
|||
// |
|||
// plotPopupViewController.swift |
|||
// wktest |
|||
// |
|||
// Created by hrbrmstr on 9/9/19. |
|||
// Copyright © 2019 Bob Rudis. All rights reserved. |
|||
// |
|||
|
|||
import Cocoa |
|||
import WebKit |
|||
|
|||
class plotPopupViewController: NSViewController { |
|||
|
|||
var webView: WKWebView! |
|||
var urlPath: String = "" |
|||
|
|||
open override func viewDidLoad() { |
|||
super.viewDidLoad() |
|||
} |
|||
|
|||
func setupWebView(configuration: WKWebViewConfiguration) { |
|||
|
|||
webView = WKWebView(frame: view.bounds, configuration: configuration) |
|||
webView.autoresizingMask = [.width, .height] |
|||
webView.uiDelegate = self |
|||
webView.navigationDelegate = self |
|||
|
|||
view.addSubview(webView) |
|||
|
|||
} |
|||
|
|||
func loadWebView(urlIn: String) { |
|||
|
|||
urlPath = urlIn |
|||
if let url = URL(string: urlPath) { |
|||
let urlRequest = URLRequest(url: url) |
|||
webView.load(urlRequest) |
|||
} |
|||
|
|||
} |
|||
|
|||
override func viewDidAppear() { |
|||
super.viewDidAppear() |
|||
} |
|||
|
|||
} |
|||
|
|||
extension plotPopupViewController: WKUIDelegate { |
|||
|
|||
func webViewDidClose(_ webView: WKWebView) { |
|||
self.view.window?.close() |
|||
} |
|||
|
|||
} |
|||
|
|||
extension plotPopupViewController: WKNavigationDelegate { |
|||
open func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) { |
|||
} |
|||
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) { |
|||
} |
|||
} |
Loading…
Reference in new issue