diff --git a/RSwitch.xcodeproj/project.pbxproj b/RSwitch.xcodeproj/project.pbxproj index ed0def4..dbbe5d5 100644 --- a/RSwitch.xcodeproj/project.pbxproj +++ b/RSwitch.xcodeproj/project.pbxproj @@ -36,6 +36,10 @@ 01F3EF0E230E635300DF5DF9 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01F3EF0D230E635300DF5DF9 /* ViewController.swift */; }; 01F3EF10230E635500DF5DF9 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 01F3EF0F230E635500DF5DF9 /* Assets.xcassets */; }; 01F3EF13230E635500DF5DF9 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 01F3EF11230E635500DF5DF9 /* Main.storyboard */; }; + 01FC5D01232874F600771CD7 /* plotPopupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01FC5CFD232874F500771CD7 /* plotPopupViewController.swift */; }; + 01FC5D02232874F600771CD7 /* ToolbarWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01FC5CFE232874F600771CD7 /* ToolbarWebViewController.swift */; }; + 01FC5D03232874F600771CD7 /* RStudioServerSessionWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01FC5CFF232874F600771CD7 /* RStudioServerSessionWebViewController.swift */; }; + 01FC5D04232874F600771CD7 /* PlotWebViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01FC5D00232874F600771CD7 /* PlotWebViewController.swift */; }; 52B8A14237DA712A6A2ABDE0 /* Pods_RSwitch.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0E2F8556B6C8EF8ED93F7E99 /* Pods_RSwitch.framework */; }; C4290DD6231F190F00AA5955 /* AppMenuActions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4290DD5231F190E00AA5955 /* AppMenuActions.swift */; }; /* End PBXBuildFile section */ @@ -76,6 +80,10 @@ 01F3EF0F230E635500DF5DF9 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 01F3EF12230E635500DF5DF9 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 01F3EF14230E635500DF5DF9 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 01FC5CFD232874F500771CD7 /* plotPopupViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = plotPopupViewController.swift; sourceTree = ""; }; + 01FC5CFE232874F600771CD7 /* ToolbarWebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ToolbarWebViewController.swift; sourceTree = ""; }; + 01FC5CFF232874F600771CD7 /* RStudioServerSessionWebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RStudioServerSessionWebViewController.swift; sourceTree = ""; }; + 01FC5D00232874F600771CD7 /* PlotWebViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlotWebViewController.swift; sourceTree = ""; }; 0E2F8556B6C8EF8ED93F7E99 /* Pods_RSwitch.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_RSwitch.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 53FF56D90FA7100C1726A4F7 /* Pods-RSwitch.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RSwitch.debug.xcconfig"; path = "Target Support Files/Pods-RSwitch/Pods-RSwitch.debug.xcconfig"; sourceTree = ""; }; 574911021B3B7938E36AB013 /* Pods-RSwitch.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RSwitch.release.xcconfig"; path = "Target Support Files/Pods-RSwitch/Pods-RSwitch.release.xcconfig"; sourceTree = ""; }; @@ -106,6 +114,10 @@ 0198B9A2231971D1003F7578 /* String+Version */, 0198B9A623197C8E003F7578 /* Utils */, 0178970C230ED25100F8F5BC /* AboutViewController.swift */, + 01FC5CFD232874F500771CD7 /* plotPopupViewController.swift */, + 01FC5D00232874F600771CD7 /* PlotWebViewController.swift */, + 01FC5CFF232874F600771CD7 /* RStudioServerSessionWebViewController.swift */, + 01FC5CFE232874F600771CD7 /* ToolbarWebViewController.swift */, 01073F202311E6BD007162C9 /* HandleRSwitch.swift */, 01073F1E2311E67D007162C9 /* HandleUpdate.swift */, 018A8C402312F4940006E87D /* HandleSwitchTo.swift */, @@ -377,14 +389,18 @@ 0197554A231BD919003FAD7B /* RVersions.swift in Sources */, 01073F152311E370007162C9 /* Notify.swift in Sources */, C4290DD6231F190F00AA5955 /* AppMenuActions.swift in Sources */, + 01FC5D03232874F600771CD7 /* RStudioServerSessionWebViewController.swift in Sources */, 01073F1D2311E64E007162C9 /* DownloadRStudio.swift in Sources */, 01073F172311E397007162C9 /* Menu.swift in Sources */, 01F3EF0E230E635300DF5DF9 /* ViewController.swift in Sources */, + 01FC5D04232874F600771CD7 /* PlotWebViewController.swift in Sources */, 01F3EF0C230E635300DF5DF9 /* AppDelegate.swift in Sources */, + 01FC5D01232874F600771CD7 /* plotPopupViewController.swift in Sources */, 01D3E441232131F300E3BC02 /* RStudioServerSessionManager.swift in Sources */, 01B611EC232176A200432807 /* NewSessionViewController.swift in Sources */, 01073F0F2311AE2E007162C9 /* String+Version.swift in Sources */, 0198B99E23196689003F7578 /* BrowseMenuAction.swift in Sources */, + 01FC5D02232874F600771CD7 /* ToolbarWebViewController.swift in Sources */, 01073F132311E1CF007162C9 /* Globals.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/RSwitch/Base.lproj/Main.storyboard b/RSwitch/Base.lproj/Main.storyboard index 1b578bb..0f06429 100644 --- a/RSwitch/Base.lproj/Main.storyboard +++ b/RSwitch/Base.lproj/Main.storyboard @@ -1,9 +1,8 @@ - + - - + @@ -698,81 +697,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -874,33 +798,7 @@ DQ - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1011,5 +909,130 @@ Just by Daniel Duan + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RSwitch/Swift/HandleSwitchTo.swift b/RSwitch/Swift/HandleSwitchTo.swift index fab5352..d8501af 100644 --- a/RSwitch/Swift/HandleSwitchTo.swift +++ b/RSwitch/Swift/HandleSwitchTo.swift @@ -16,6 +16,7 @@ extension AppDelegate { @objc func switch_to(_ sender: NSMenuItem?) { (sender!.representedObject as! NSRunningApplication).activate(options: NSApplication.ActivationOptions.activateIgnoringOtherApps) + (sender!.representedObject as! NSRunningApplication).unhide() } } diff --git a/RSwitch/Swift/PlotWebViewController.swift b/RSwitch/Swift/PlotWebViewController.swift new file mode 100644 index 0000000..650a797 --- /dev/null +++ b/RSwitch/Swift/PlotWebViewController.swift @@ -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() + + } + +} diff --git a/RSwitch/Swift/RStudioServerSessionWebViewController.swift b/RSwitch/Swift/RStudioServerSessionWebViewController.swift new file mode 100644 index 0000000..a95249a --- /dev/null +++ b/RSwitch/Swift/RStudioServerSessionWebViewController.swift @@ -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!) { + } +} diff --git a/RSwitch/Swift/Sessions/RStudioServerSession.swift b/RSwitch/Swift/Sessions/RStudioServerSession.swift index 10fb348..21aa805 100644 --- a/RSwitch/Swift/Sessions/RStudioServerSession.swift +++ b/RSwitch/Swift/Sessions/RStudioServerSession.swift @@ -13,8 +13,8 @@ class RStudioServerSession : Codable { var url : String var menuTitle : String - var wk : NSWindowController? - var wv : WebViewController? + var wk : ToolbarWebViewController? + var wv : RstudioServerSessionWebViewController? private enum CodingKeys: String, CodingKey { case url @@ -30,18 +30,19 @@ class RStudioServerSession : Codable { 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 - wv!.nickname = menuTitle + + wk = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "windowWithWkViewAndToolbar") as? ToolbarWebViewController + + wk?.nicknname.stringValue = menuTitle + wk?.url.stringValue = url + + wv = (wk?.contentViewController as! RstudioServerSessionWebViewController) + } - - wk?.window?.orderFront(appDelegate) - wk?.showWindow(appDelegate) + + wk?.showWindow(self) + wv?.loadWebView(urlIn: url) NSApp.activate(ignoringOtherApps: true) diff --git a/RSwitch/Swift/ToolbarWebViewController.swift b/RSwitch/Swift/ToolbarWebViewController.swift new file mode 100644 index 0000000..813a918 --- /dev/null +++ b/RSwitch/Swift/ToolbarWebViewController.swift @@ -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) + } + +} diff --git a/RSwitch/Swift/plotPopupViewController.swift b/RSwitch/Swift/plotPopupViewController.swift new file mode 100644 index 0000000..36173d4 --- /dev/null +++ b/RSwitch/Swift/plotPopupViewController.swift @@ -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!) { + } +}