Add edit/done buttons to have a more discoverable way to remove tunnels.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jeroen Leenarts 2018-09-18 22:46:28 +02:00
parent 411c919cbf
commit c9974f9119
2 changed files with 51 additions and 5 deletions

View File

@ -101,14 +101,31 @@
</toolbarItems>
<navigationItem key="navigationItem" title="WireGuard" largeTitleDisplayMode="always" id="j0L-5U-jDs">
<barButtonItem key="backBarButtonItem" title="Tunnels" id="pxL-gR-QXU"/>
<barButtonItem key="rightBarButtonItem" title=" ⚙︎" id="DZP-sp-Hsg">
<connections>
<action selector="showSettings:" destination="kTU-BV-32R" id="UfC-XY-zhW"/>
</connections>
</barButtonItem>
<rightBarButtonItems>
<barButtonItem title=" ⚙︎" id="DZP-sp-Hsg">
<connections>
<action selector="showSettings:" destination="kTU-BV-32R" id="UfC-XY-zhW"/>
</connections>
</barButtonItem>
<barButtonItem systemItem="edit" id="Bj0-7o-icS">
<connections>
<action selector="editTunnels:" destination="kTU-BV-32R" id="NzT-sl-F5r"/>
</connections>
</barButtonItem>
<barButtonItem systemItem="done" id="X9a-Od-S2p">
<connections>
<action selector="editTunnels:" destination="kTU-BV-32R" id="n7j-D7-moO"/>
</connections>
</barButtonItem>
</rightBarButtonItems>
</navigationItem>
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
<connections>
<outlet property="doneButton" destination="X9a-Od-S2p" id="Dc9-5g-IBV"/>
<outlet property="editButton" destination="Bj0-7o-icS" id="iAH-Vk-xLg"/>
<outlet property="settingsButton" destination="DZP-sp-Hsg" id="6YI-c0-U9w"/>
</connections>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="4uZ-Vv-Fry" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>

View File

@ -24,6 +24,10 @@ class TunnelsTableViewController: UITableViewController {
var viewContext: NSManagedObjectContext!
@IBOutlet var settingsButton: UIBarButtonItem!
@IBOutlet var editButton: UIBarButtonItem!
@IBOutlet var doneButton: UIBarButtonItem!
private lazy var fetchedResultsController: FetchedResultsController<Tunnel> = {
let fetchRequest = NSFetchRequest<Tunnel>()
fetchRequest.entity = Tunnel.entity()
@ -66,6 +70,26 @@ class TunnelsTableViewController: UITableViewController {
tableView.tableFooterView = UIView(frame: CGRect.zero)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateBarButtons()
}
@IBAction func editTunnels(_ sender: Any) {
tableView.setEditing(!tableView.isEditing, animated: true)
updateBarButtons()
}
private func updateBarButtons() {
navigationController?.setToolbarHidden(tableView.isEditing, animated: true)
if tableView.isEditing {
self.navigationItem.setRightBarButtonItems([doneButton], animated: true)
} else {
self.navigationItem.setRightBarButtonItems([settingsButton, editButton], animated: true)
}
}
@IBAction func showSettings(_ sender: Any) {
delegate?.showSettings()
}
@ -254,6 +278,11 @@ class TunnelTableViewCell: UITableViewCell {
tunnelSwitch.onTintColor = status == .invalid || status == .reasserting ? .gray : .green
tunnelSwitch.isEnabled = true
}
override func setEditing(_ editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
tunnelSwitch.isHidden = editing
}
}
extension TunnelTableViewCell: Identifyable {}