diff --git a/ZeroTier One.xcodeproj/project.pbxproj b/ZeroTier One.xcodeproj/project.pbxproj index 2730b9873..4fb0a76e2 100644 --- a/ZeroTier One.xcodeproj/project.pbxproj +++ b/ZeroTier One.xcodeproj/project.pbxproj @@ -287,6 +287,7 @@ 93326BE71CE7C816005CA2AC /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/ZeroTier One/JoinNetworkViewController.swift b/ZeroTier One/JoinNetworkViewController.swift index d071ce912..0aaaf10f0 100644 --- a/ZeroTier One/JoinNetworkViewController.swift +++ b/ZeroTier One/JoinNetworkViewController.swift @@ -8,11 +8,77 @@ import Cocoa -class JoinNetworkViewController: NSViewController { +extension String { + func contains(find: String) -> Bool { + return self.rangeOfString(find) != nil + } + + func trunc(length: Int, trailing: String? = "...") -> String { + if self.characters.count > length { + return self.substringToIndex(self.startIndex.advancedBy(length)) + (trailing ?? "") + } else { + return self + } + } +} + +class JoinNetworkViewController: NSViewController, NSComboBoxDelegate { + + @IBOutlet var network: NSComboBox! + @IBOutlet var joinButton: NSButton! override func viewDidLoad() { super.viewDidLoad() - // Do view setup here. + network.setDelegate(self) } - + + @IBAction func onJoinClicked(sender: AnyObject?) { + let networkId = UInt64(network.stringValue, radix: 16) + + // TODO: Execute join network call + + network.stringValue = "" + } + + + // NSComboBoxDelegate Methods + + override func controlTextDidChange(obj: NSNotification) { + let cb = obj.object as! NSComboBox + let value = cb.stringValue + + + let allowedCharacters = "abcdefABCDEF0123456789" + + var outValue = "" + + for char in value.characters { + if !allowedCharacters.contains(String(char)) { + NSBeep() + } + else { + outValue += String(char) + } + } + + + + if outValue.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) == 16 { + joinButton.enabled = true + } + else { + + if outValue.lengthOfBytesUsingEncoding(NSUTF8StringEncoding) > 16 { + outValue = outValue.trunc(16, trailing: "") + NSBeep() + joinButton.enabled = true + } + else { + joinButton.enabled = false + } + } + + cb.stringValue = outValue + } + // end NSComboBoxDelegate Methods } diff --git a/ZeroTier One/JoinNetworkViewController.xib b/ZeroTier One/JoinNetworkViewController.xib index 7f3f13297..2de44c9df 100644 --- a/ZeroTier One/JoinNetworkViewController.xib +++ b/ZeroTier One/JoinNetworkViewController.xib @@ -1,5 +1,5 @@ - + @@ -7,14 +7,45 @@ + + - + + + + + + + + + + + + + + + + + + + + +