aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-01-02 03:04:01 +0530
committerRoopesh Chander <roop@roopc.net>2019-01-14 14:52:30 +0530
commit37fce31d162cd04dc9147b88775a3a5d1dcb2e9a (patch)
tree0044977f82e03328815e63a5cd7d394be9a12fb3
parentmacOS: Manage tunnels window: Tunnels list (diff)
downloadwireguard-apple-37fce31d162cd04dc9147b88775a3a5d1dcb2e9a.tar.xz
wireguard-apple-37fce31d162cd04dc9147b88775a3a5d1dcb2e9a.zip
macOS: Manage tunnels: Add buttons to the bottom of the list view
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to '')
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift89
1 files changed, 88 insertions, 1 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
index 47658d67..160dc7fe 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift
@@ -15,6 +15,34 @@ class TunnelsListTableViewController: NSViewController {
return tableView
}()
+ let buttonBar: NSSegmentedControl = {
+ let addButtonImage = NSImage(named: NSImage.addTemplateName)!
+ let removeButtonImage = NSImage(named: NSImage.removeTemplateName)!
+ let actionButtonImage = NSImage(named: NSImage.actionTemplateName)!
+ let buttonBar = NSSegmentedControl(images: [addButtonImage, removeButtonImage, actionButtonImage],
+ trackingMode: .momentary, target: nil, action: #selector(buttonBarClicked(sender:)))
+ buttonBar.segmentStyle = .smallSquare
+ buttonBar.segmentDistribution = .fit
+ buttonBar.setShowsMenuIndicator(true, forSegment: 0)
+ buttonBar.setShowsMenuIndicator(false, forSegment: 1)
+ buttonBar.setShowsMenuIndicator(true, forSegment: 2)
+ return buttonBar
+ }()
+
+ let addMenu: NSMenu = {
+ let addMenu = NSMenu(title: "TunnelsListAdd")
+ addMenu.addItem(withTitle: "Add empty tunnel", action: #selector(addEmptyTunnelClicked), keyEquivalent: "")
+ addMenu.addItem(withTitle: "Import tunnel(s) from file...", action: #selector(importTunnelClicked), keyEquivalent: "")
+ return addMenu
+ }()
+
+ let actionMenu: NSMenu = {
+ let actionMenu = NSMenu(title: "TunnelsListAction")
+ actionMenu.addItem(withTitle: "Export log to file", action: #selector(exportLogClicked), keyEquivalent: "")
+ actionMenu.addItem(withTitle: "Export tunnels to zip", action: #selector(exportTunnelsClicked), keyEquivalent: "")
+ return actionMenu
+ }()
+
init(tunnelsManager: TunnelsManager) {
self.tunnelsManager = tunnelsManager
super.init(nibName: nil, bundle: nil)
@@ -36,7 +64,66 @@ class TunnelsListTableViewController: NSViewController {
clipView.documentView = tableView
scrollView.contentView = clipView
- self.view = scrollView
+ let containerView = NSView()
+ containerView.addSubview(scrollView)
+ containerView.addSubview(buttonBar)
+ scrollView.translatesAutoresizingMaskIntoConstraints = false
+ buttonBar.translatesAutoresizingMaskIntoConstraints = false
+
+ NSLayoutConstraint.activate([
+ containerView.topAnchor.constraint(equalTo: scrollView.topAnchor),
+ containerView.leadingAnchor.constraint(equalTo: scrollView.leadingAnchor),
+ containerView.trailingAnchor.constraint(equalTo: scrollView.trailingAnchor),
+ scrollView.bottomAnchor.constraint(equalTo: buttonBar.topAnchor),
+ containerView.leadingAnchor.constraint(equalTo: buttonBar.leadingAnchor),
+ containerView.bottomAnchor.constraint(equalTo: buttonBar.bottomAnchor)
+ ])
+
+ NSLayoutConstraint.activate([
+ containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: 120),
+ containerView.heightAnchor.constraint(greaterThanOrEqualToConstant: 120)
+ ])
+
+ buttonBar.target = self
+ addMenu.items.forEach { $0.target = self }
+ actionMenu.items.forEach { $0.target = self }
+
+ view = containerView
+ }
+
+ @objc func buttonBarClicked(sender: AnyObject?) {
+ guard let buttonBar = sender as? NSSegmentedControl else { return }
+ // We have to resort to explicitly showing the menu instead of using NSSegmentedControl.setMenu()
+ // because we have a mix of menu and non-menu segments.
+ // See: http://openradar.appspot.com/radar?id=61419
+ if buttonBar.selectedSegment == 0 {
+ let segmentBottomLeft = NSPoint(x: 0, y: buttonBar.bounds.height + 2)
+ addMenu.popUp(positioning: nil, at: segmentBottomLeft, in: buttonBar)
+ } else if buttonBar.selectedSegment == 1 {
+ removeTunnelClicked()
+ } else if buttonBar.selectedSegment == 2 {
+ let segmentBottomLeft = NSPoint(x: buttonBar.bounds.width * 0.66, y: buttonBar.bounds.height + 2)
+ actionMenu.popUp(positioning: nil, at: segmentBottomLeft, in: buttonBar)
+ }
+ }
+
+ @objc func addEmptyTunnelClicked() {
+ print("addEmptyTunnelClicked")
+ }
+
+ @objc func importTunnelClicked() {
+ print("importTunnelClicked")
+ }
+
+ @objc func removeTunnelClicked() {
+ print("removeTunnelClicked")
+ }
+
+ @objc func exportLogClicked() {
+ print("exportLogClicked")
+ }
+ @objc func exportTunnelsClicked() {
+ print("exportTunnelsClicked")
}
}