aboutsummaryrefslogtreecommitdiffstats
path: root/WireGuard/WireGuard/UI/macOS
diff options
context:
space:
mode:
authorRoopesh Chander <roop@roopc.net>2019-03-10 16:32:26 +0530
committerRoopesh Chander <roop@roopc.net>2019-03-10 19:22:33 +0530
commitdb6f0729c69a580357e194a454de19eaa6f3bd39 (patch)
tree02e1a3f2228a40b4c71f10576ffa624a09311faf /WireGuard/WireGuard/UI/macOS
parentwireguard-go-bridge: use system go installation (diff)
downloadwireguard-apple-db6f0729c69a580357e194a454de19eaa6f3bd39.tar.xz
wireguard-apple-db6f0729c69a580357e194a454de19eaa6f3bd39.zip
macOS: Generalize NoTunnelsDetailVC into a ButtonedDetailVC
Signed-off-by: Roopesh Chander <roop@roopc.net>
Diffstat (limited to 'WireGuard/WireGuard/UI/macOS')
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/ButtonedDetailViewController.swift48
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/ManageTunnelsRootViewController.swift7
-rw-r--r--WireGuard/WireGuard/UI/macOS/ViewController/NoTunnelsDetailViewController.swift46
3 files changed, 54 insertions, 47 deletions
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/ButtonedDetailViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/ButtonedDetailViewController.swift
new file mode 100644
index 00000000..defa09fd
--- /dev/null
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/ButtonedDetailViewController.swift
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: MIT
+// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
+
+import Cocoa
+
+class ButtonedDetailViewController: NSViewController {
+
+ var onButtonClicked: (() -> Void)?
+
+ let button: NSButton = {
+ let button = NSButton()
+ button.title = ""
+ button.setButtonType(.momentaryPushIn)
+ button.bezelStyle = .rounded
+ return button
+ }()
+
+ init() {
+ super.init(nibName: nil, bundle: nil)
+ }
+
+ required init?(coder: NSCoder) {
+ fatalError("init(coder:) has not been implemented")
+ }
+
+ override func loadView() {
+ let view = NSView()
+
+ button.target = self
+ button.action = #selector(buttonClicked)
+
+ view.addSubview(button)
+ button.translatesAutoresizingMaskIntoConstraints = false
+ NSLayoutConstraint.activate([
+ button.centerXAnchor.constraint(equalTo: view.centerXAnchor),
+ button.centerYAnchor.constraint(equalTo: view.centerYAnchor)
+ ])
+ self.view = view
+ }
+
+ func setButtonTitle(_ title: String) {
+ button.title = title
+ }
+
+ @objc func buttonClicked() {
+ onButtonClicked?()
+ }
+}
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/ManageTunnelsRootViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/ManageTunnelsRootViewController.swift
index 8d281570..58065475 100644
--- a/WireGuard/WireGuard/UI/macOS/ViewController/ManageTunnelsRootViewController.swift
+++ b/WireGuard/WireGuard/UI/macOS/ViewController/ManageTunnelsRootViewController.swift
@@ -84,7 +84,12 @@ extension ManageTunnelsRootViewController: TunnelsListTableViewControllerDelegat
}
func tunnelsListEmpty() {
- let noTunnelsVC = NoTunnelsDetailViewController(tunnelsManager: tunnelsManager)
+ let noTunnelsVC = ButtonedDetailViewController()
+ noTunnelsVC.setButtonTitle(tr("macButtonImportTunnels"))
+ noTunnelsVC.onButtonClicked = { [weak self] in
+ guard let self = self else { return }
+ ImportPanelPresenter.presentImportPanel(tunnelsManager: self.tunnelsManager, sourceVC: self)
+ }
setTunnelDetailContentVC(noTunnelsVC)
self.tunnelDetailVC = nil
}
diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/NoTunnelsDetailViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/NoTunnelsDetailViewController.swift
deleted file mode 100644
index 49f61974..00000000
--- a/WireGuard/WireGuard/UI/macOS/ViewController/NoTunnelsDetailViewController.swift
+++ /dev/null
@@ -1,46 +0,0 @@
-// SPDX-License-Identifier: MIT
-// Copyright © 2018-2019 WireGuard LLC. All Rights Reserved.
-
-import Cocoa
-
-class NoTunnelsDetailViewController: NSViewController {
-
- let tunnelsManager: TunnelsManager
-
- let importButton: NSButton = {
- let button = NSButton()
- button.title = tr("macButtonImportTunnels")
- button.setButtonType(.momentaryPushIn)
- button.bezelStyle = .rounded
- return button
- }()
-
- init(tunnelsManager: TunnelsManager) {
- self.tunnelsManager = tunnelsManager
- super.init(nibName: nil, bundle: nil)
- }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- override func loadView() {
- let view = NSView()
-
- importButton.target = self
- importButton.action = #selector(importTunnelClicked)
-
- view.addSubview(importButton)
- importButton.translatesAutoresizingMaskIntoConstraints = false
- NSLayoutConstraint.activate([
- importButton.centerXAnchor.constraint(equalTo: view.centerXAnchor),
- importButton.centerYAnchor.constraint(equalTo: view.centerYAnchor)
- ])
- self.view = view
- }
-
- @objc func importTunnelClicked() {
- // We pass sourceVC as parent instead of self because this VC will not be visible when the import completes
- ImportPanelPresenter.presentImportPanel(tunnelsManager: tunnelsManager, sourceVC: parent)
- }
-}