mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-10 03:11:53 +00:00
set the combo box to use a data source and remember the last 20 networks input
This commit is contained in:
parent
ccbd6f97cd
commit
acd6978a30
@ -22,22 +22,54 @@ extension String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class JoinNetworkViewController: NSViewController, NSComboBoxDelegate {
|
let joinedNetworksKey = "com.zerotier.one.joined-networks"
|
||||||
|
|
||||||
|
|
||||||
|
class JoinNetworkViewController: NSViewController, NSComboBoxDelegate, NSComboBoxDataSource {
|
||||||
|
|
||||||
@IBOutlet var network: NSComboBox!
|
@IBOutlet var network: NSComboBox!
|
||||||
@IBOutlet var joinButton: NSButton!
|
@IBOutlet var joinButton: NSButton!
|
||||||
|
|
||||||
|
var values: [String] = [String]()
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
network.setDelegate(self)
|
network.setDelegate(self)
|
||||||
|
network.dataSource = self
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewWillAppear() {
|
||||||
|
let defaults = NSUserDefaults.standardUserDefaults()
|
||||||
|
|
||||||
|
let vals = defaults.stringArrayForKey(joinedNetworksKey)
|
||||||
|
|
||||||
|
if let v = vals {
|
||||||
|
values = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override func viewDidDisappear() {
|
||||||
|
let defaults = NSUserDefaults.standardUserDefaults()
|
||||||
|
|
||||||
|
defaults.setObject(values, forKey: joinedNetworksKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func onJoinClicked(sender: AnyObject?) {
|
@IBAction func onJoinClicked(sender: AnyObject?) {
|
||||||
let networkId = UInt64(network.stringValue, radix: 16)
|
let networkString = network.stringValue
|
||||||
|
let networkId = UInt64(networkString, radix: 16)
|
||||||
|
|
||||||
// TODO: Execute join network call
|
// TODO: Execute join network call
|
||||||
|
|
||||||
network.stringValue = ""
|
network.stringValue = ""
|
||||||
|
|
||||||
|
|
||||||
|
if !values.contains(networkString) {
|
||||||
|
values.insert(networkString, atIndex: 0)
|
||||||
|
|
||||||
|
while values.count > 20 {
|
||||||
|
values.removeLast()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -81,4 +113,39 @@ class JoinNetworkViewController: NSViewController, NSComboBoxDelegate {
|
|||||||
cb.stringValue = outValue
|
cb.stringValue = outValue
|
||||||
}
|
}
|
||||||
// end NSComboBoxDelegate Methods
|
// end NSComboBoxDelegate Methods
|
||||||
|
|
||||||
|
|
||||||
|
// NSComboBoxDataSource methods
|
||||||
|
|
||||||
|
func numberOfItemsInComboBox(aComboBox: NSComboBox) -> Int {
|
||||||
|
return values.count
|
||||||
|
}
|
||||||
|
|
||||||
|
func comboBox(aComboBox: NSComboBox, objectValueForItemAtIndex index: Int) -> AnyObject {
|
||||||
|
return values[index]
|
||||||
|
}
|
||||||
|
|
||||||
|
func comboBox(aComboBox: NSComboBox, indexOfItemWithStringValue string: String) -> Int {
|
||||||
|
|
||||||
|
var counter = 0
|
||||||
|
for val in values {
|
||||||
|
if val == string {
|
||||||
|
return counter
|
||||||
|
}
|
||||||
|
counter += 1
|
||||||
|
}
|
||||||
|
return NSNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
func comboBox(aComboBox: NSComboBox, completedString string: String) -> String? {
|
||||||
|
for val in values {
|
||||||
|
if val.hasPrefix(string) {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// end NSComboBoxDataSorce methods
|
||||||
}
|
}
|
||||||
|
@ -26,14 +26,6 @@
|
|||||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||||
</textFieldCell>
|
</textFieldCell>
|
||||||
</textField>
|
</textField>
|
||||||
<comboBox verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="BQy-d9-BNg">
|
|
||||||
<rect key="frame" x="131" y="57" width="221" height="26"/>
|
|
||||||
<comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" completes="NO" numberOfVisibleItems="5" id="n71-4S-AaI">
|
|
||||||
<font key="font" metaFont="system"/>
|
|
||||||
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
|
||||||
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
|
||||||
</comboBoxCell>
|
|
||||||
</comboBox>
|
|
||||||
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="BGy-vd-NQX">
|
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="BGy-vd-NQX">
|
||||||
<rect key="frame" x="274" y="13" width="81" height="32"/>
|
<rect key="frame" x="274" y="13" width="81" height="32"/>
|
||||||
<buttonCell key="cell" type="push" title="Join" bezelStyle="rounded" alignment="center" enabled="NO" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="6Rp-TA-XLl">
|
<buttonCell key="cell" type="push" title="Join" bezelStyle="rounded" alignment="center" enabled="NO" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="6Rp-TA-XLl">
|
||||||
@ -44,6 +36,14 @@
|
|||||||
<action selector="onJoinClicked:" target="-2" id="kzC-GT-JKb"/>
|
<action selector="onJoinClicked:" target="-2" id="kzC-GT-JKb"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
|
<comboBox verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="BQy-d9-BNg">
|
||||||
|
<rect key="frame" x="131" y="57" width="221" height="26"/>
|
||||||
|
<comboBoxCell key="cell" scrollable="YES" lineBreakMode="clipping" selectable="YES" editable="YES" sendsActionOnEndEditing="YES" borderStyle="bezel" drawsBackground="YES" usesDataSource="YES" numberOfVisibleItems="5" id="n71-4S-AaI">
|
||||||
|
<font key="font" metaFont="system"/>
|
||||||
|
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
|
||||||
|
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
|
||||||
|
</comboBoxCell>
|
||||||
|
</comboBox>
|
||||||
</subviews>
|
</subviews>
|
||||||
<point key="canvasLocation" x="249.5" y="361.5"/>
|
<point key="canvasLocation" x="249.5" y="361.5"/>
|
||||||
</customView>
|
</customView>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user