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:
parent
411c919cbf
commit
c9974f9119
|
@ -101,14 +101,31 @@
|
||||||
</toolbarItems>
|
</toolbarItems>
|
||||||
<navigationItem key="navigationItem" title="WireGuard" largeTitleDisplayMode="always" id="j0L-5U-jDs">
|
<navigationItem key="navigationItem" title="WireGuard" largeTitleDisplayMode="always" id="j0L-5U-jDs">
|
||||||
<barButtonItem key="backBarButtonItem" title="Tunnels" id="pxL-gR-QXU"/>
|
<barButtonItem key="backBarButtonItem" title="Tunnels" id="pxL-gR-QXU"/>
|
||||||
<barButtonItem key="rightBarButtonItem" title=" ⚙︎" id="DZP-sp-Hsg">
|
<rightBarButtonItems>
|
||||||
<connections>
|
<barButtonItem title=" ⚙︎" id="DZP-sp-Hsg">
|
||||||
<action selector="showSettings:" destination="kTU-BV-32R" id="UfC-XY-zhW"/>
|
<connections>
|
||||||
</connections>
|
<action selector="showSettings:" destination="kTU-BV-32R" id="UfC-XY-zhW"/>
|
||||||
</barButtonItem>
|
</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>
|
</navigationItem>
|
||||||
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
|
<simulatedNavigationBarMetrics key="simulatedTopBarMetrics" prompted="NO"/>
|
||||||
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
|
<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>
|
</tableViewController>
|
||||||
<placeholder placeholderIdentifier="IBFirstResponder" id="4uZ-Vv-Fry" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
<placeholder placeholderIdentifier="IBFirstResponder" id="4uZ-Vv-Fry" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||||
</objects>
|
</objects>
|
||||||
|
|
|
@ -24,6 +24,10 @@ class TunnelsTableViewController: UITableViewController {
|
||||||
|
|
||||||
var viewContext: NSManagedObjectContext!
|
var viewContext: NSManagedObjectContext!
|
||||||
|
|
||||||
|
@IBOutlet var settingsButton: UIBarButtonItem!
|
||||||
|
@IBOutlet var editButton: UIBarButtonItem!
|
||||||
|
@IBOutlet var doneButton: UIBarButtonItem!
|
||||||
|
|
||||||
private lazy var fetchedResultsController: FetchedResultsController<Tunnel> = {
|
private lazy var fetchedResultsController: FetchedResultsController<Tunnel> = {
|
||||||
let fetchRequest = NSFetchRequest<Tunnel>()
|
let fetchRequest = NSFetchRequest<Tunnel>()
|
||||||
fetchRequest.entity = Tunnel.entity()
|
fetchRequest.entity = Tunnel.entity()
|
||||||
|
@ -66,6 +70,26 @@ class TunnelsTableViewController: UITableViewController {
|
||||||
tableView.tableFooterView = UIView(frame: CGRect.zero)
|
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) {
|
@IBAction func showSettings(_ sender: Any) {
|
||||||
delegate?.showSettings()
|
delegate?.showSettings()
|
||||||
}
|
}
|
||||||
|
@ -254,6 +278,11 @@ class TunnelTableViewCell: UITableViewCell {
|
||||||
tunnelSwitch.onTintColor = status == .invalid || status == .reasserting ? .gray : .green
|
tunnelSwitch.onTintColor = status == .invalid || status == .reasserting ? .gray : .green
|
||||||
tunnelSwitch.isEnabled = true
|
tunnelSwitch.isEnabled = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func setEditing(_ editing: Bool, animated: Bool) {
|
||||||
|
super.setEditing(editing, animated: animated)
|
||||||
|
tunnelSwitch.isHidden = editing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension TunnelTableViewCell: Identifyable {}
|
extension TunnelTableViewCell: Identifyable {}
|
||||||
|
|
Loading…
Reference in New Issue