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.
74 lines
1.8 KiB
74 lines
1.8 KiB
5 years ago
|
//
|
||
|
// NewSessionViewController.swift
|
||
|
// RSwitch
|
||
|
//
|
||
|
// Created by hrbrmstr on 9/5/19.
|
||
|
// Copyright © 2019 Bob Rudis. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import Cocoa
|
||
|
|
||
|
extension String {
|
||
|
var isValidURL: Bool {
|
||
|
let detector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue)
|
||
|
if let match = detector.firstMatch(in: self, options: [], range: NSRange(location: 0, length: self.utf16.count)) {
|
||
|
// it is a link, if the match covers the whole string
|
||
|
return match.range.length == self.utf16.count
|
||
|
} else {
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class NewSessionViewController: NSViewController {
|
||
|
|
||
|
let appDelegate = NSApplication.shared.delegate as! AppDelegate
|
||
|
|
||
|
@IBOutlet weak var nickname: NSTextField!
|
||
|
@IBOutlet weak var serverURL: NSTextField!
|
||
|
|
||
|
@IBOutlet weak var okButton: NSButton!
|
||
|
|
||
|
@IBAction func okPressed(_ sender: Any) {
|
||
|
appDelegate.sess.newSession(url: serverURL.stringValue, title: nickname.stringValue)
|
||
|
self.view.window?.windowController?.close()
|
||
|
}
|
||
|
|
||
|
@IBAction func cancelPressed(_ sender: Any) {
|
||
|
self.view.window?.windowController?.close()
|
||
|
}
|
||
|
|
||
|
override func viewDidLoad() {
|
||
|
print("VIEW IS LOADING")
|
||
|
super.viewDidLoad()
|
||
|
|
||
|
nickname.delegate = self
|
||
|
serverURL.delegate = self
|
||
|
|
||
|
okButton.isEnabled = false
|
||
|
// Do view setup here.
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
extension NewSessionViewController : NSTextFieldDelegate {
|
||
|
|
||
|
func controlTextDidEndEditing(_ notification: Notification) {
|
||
|
|
||
|
let nick = nickname.stringValue
|
||
|
let sURL = serverURL.stringValue
|
||
|
|
||
|
let currNames = appDelegate.sess.sessions!.map {
|
||
|
$0.menuTitle
|
||
|
}
|
||
|
|
||
|
print(currNames)
|
||
|
|
||
|
let nickUnique = !(currNames.firstIndex(of: nick) != nil)
|
||
|
|
||
|
okButton.isEnabled = ((nick.count > 0) && nickUnique && sURL.isValidURL)
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|