From f7b2f73015b51d939d38ed5284f40cd46c73237f Mon Sep 17 00:00:00 2001 From: Roopesh Chander Date: Mon, 7 Jan 2019 13:04:50 +0530 Subject: macOS: Rename *Cell to *Row Signed-off-by: Roopesh Chander --- .../WireGuard/UI/macOS/View/KeyValueCell.swift | 76 ---------------------- .../WireGuard/UI/macOS/View/KeyValueRow.swift | 76 ++++++++++++++++++++++ .../WireGuard/UI/macOS/View/TunnelListCell.swift | 75 --------------------- .../WireGuard/UI/macOS/View/TunnelListRow.swift | 75 +++++++++++++++++++++ .../TunnelDetailTableViewController.swift | 4 +- .../TunnelsListTableViewController.swift | 2 +- 6 files changed, 154 insertions(+), 154 deletions(-) delete mode 100644 WireGuard/WireGuard/UI/macOS/View/KeyValueCell.swift create mode 100644 WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift delete mode 100644 WireGuard/WireGuard/UI/macOS/View/TunnelListCell.swift create mode 100644 WireGuard/WireGuard/UI/macOS/View/TunnelListRow.swift (limited to 'WireGuard/WireGuard/UI/macOS') diff --git a/WireGuard/WireGuard/UI/macOS/View/KeyValueCell.swift b/WireGuard/WireGuard/UI/macOS/View/KeyValueCell.swift deleted file mode 100644 index 47f9263..0000000 --- a/WireGuard/WireGuard/UI/macOS/View/KeyValueCell.swift +++ /dev/null @@ -1,76 +0,0 @@ -// SPDX-License-Identifier: MIT -// Copyright © 2018 WireGuard LLC. All Rights Reserved. - -import Cocoa - -class KeyValueCell: NSView { - let keyLabel: NSTextField = { - let keyLabel = NSTextField() - keyLabel.isEditable = false - keyLabel.isSelectable = false - keyLabel.isBordered = false - keyLabel.alignment = .right - keyLabel.maximumNumberOfLines = 1 - keyLabel.lineBreakMode = .byTruncatingTail - keyLabel.backgroundColor = .clear - return keyLabel - }() - - let valueLabel: NSTextField = { - let valueLabel = NSTextField() - valueLabel.isEditable = false - valueLabel.isSelectable = true - valueLabel.isBordered = false - valueLabel.maximumNumberOfLines = 1 - valueLabel.lineBreakMode = .byTruncatingTail - valueLabel.backgroundColor = .clear - return valueLabel - }() - - var key: String { - get { return keyLabel.stringValue } - set(value) { keyLabel.stringValue = value } - } - var value: String { - get { return valueLabel.stringValue } - set(value) { valueLabel.stringValue = value } - } - var isKeyInBold: Bool { - get { return keyLabel.font == NSFont.boldSystemFont(ofSize: 0) } - set(value) { - if value { - keyLabel.font = NSFont.boldSystemFont(ofSize: 0) - } else { - keyLabel.font = NSFont.systemFont(ofSize: 0) - } - } - } - - init() { - super.init(frame: CGRect.zero) - - addSubview(keyLabel) - addSubview(valueLabel) - keyLabel.translatesAutoresizingMaskIntoConstraints = false - valueLabel.translatesAutoresizingMaskIntoConstraints = false - - NSLayoutConstraint.activate([ - keyLabel.centerYAnchor.constraint(equalTo: self.centerYAnchor), - keyLabel.firstBaselineAnchor.constraint(equalTo: valueLabel.firstBaselineAnchor), - self.leadingAnchor.constraint(equalTo: keyLabel.leadingAnchor), - keyLabel.trailingAnchor.constraint(equalTo: valueLabel.leadingAnchor, constant: -5), - valueLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor), - keyLabel.widthAnchor.constraint(equalToConstant: 120) - ]) - } - - required init?(coder decoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override func prepareForReuse() { - key = "" - value = "" - isKeyInBold = false - } -} diff --git a/WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift b/WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift new file mode 100644 index 0000000..4e9fa7d --- /dev/null +++ b/WireGuard/WireGuard/UI/macOS/View/KeyValueRow.swift @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: MIT +// Copyright © 2018 WireGuard LLC. All Rights Reserved. + +import Cocoa + +class KeyValueRow: NSView { + let keyLabel: NSTextField = { + let keyLabel = NSTextField() + keyLabel.isEditable = false + keyLabel.isSelectable = false + keyLabel.isBordered = false + keyLabel.alignment = .right + keyLabel.maximumNumberOfLines = 1 + keyLabel.lineBreakMode = .byTruncatingTail + keyLabel.backgroundColor = .clear + return keyLabel + }() + + let valueLabel: NSTextField = { + let valueLabel = NSTextField() + valueLabel.isEditable = false + valueLabel.isSelectable = true + valueLabel.isBordered = false + valueLabel.maximumNumberOfLines = 1 + valueLabel.lineBreakMode = .byTruncatingTail + valueLabel.backgroundColor = .clear + return valueLabel + }() + + var key: String { + get { return keyLabel.stringValue } + set(value) { keyLabel.stringValue = value } + } + var value: String { + get { return valueLabel.stringValue } + set(value) { valueLabel.stringValue = value } + } + var isKeyInBold: Bool { + get { return keyLabel.font == NSFont.boldSystemFont(ofSize: 0) } + set(value) { + if value { + keyLabel.font = NSFont.boldSystemFont(ofSize: 0) + } else { + keyLabel.font = NSFont.systemFont(ofSize: 0) + } + } + } + + init() { + super.init(frame: CGRect.zero) + + addSubview(keyLabel) + addSubview(valueLabel) + keyLabel.translatesAutoresizingMaskIntoConstraints = false + valueLabel.translatesAutoresizingMaskIntoConstraints = false + + NSLayoutConstraint.activate([ + keyLabel.centerYAnchor.constraint(equalTo: self.centerYAnchor), + keyLabel.firstBaselineAnchor.constraint(equalTo: valueLabel.firstBaselineAnchor), + self.leadingAnchor.constraint(equalTo: keyLabel.leadingAnchor), + keyLabel.trailingAnchor.constraint(equalTo: valueLabel.leadingAnchor, constant: -5), + valueLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor), + keyLabel.widthAnchor.constraint(equalToConstant: 120) + ]) + } + + required init?(coder decoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + override func prepareForReuse() { + key = "" + value = "" + isKeyInBold = false + } +} diff --git a/WireGuard/WireGuard/UI/macOS/View/TunnelListCell.swift b/WireGuard/WireGuard/UI/macOS/View/TunnelListCell.swift deleted file mode 100644 index 11bf73c..0000000 --- a/WireGuard/WireGuard/UI/macOS/View/TunnelListCell.swift +++ /dev/null @@ -1,75 +0,0 @@ -// SPDX-License-Identifier: MIT -// Copyright © 2018 WireGuard LLC. All Rights Reserved. - -import Cocoa - -class TunnelListCell: NSView { - var tunnel: TunnelContainer? { - didSet(value) { - // Bind to the tunnel's name - nameLabel.stringValue = tunnel?.name ?? "" - nameObservationToken = tunnel?.observe(\TunnelContainer.name) { [weak self] tunnel, _ in - self?.nameLabel.stringValue = tunnel.name - } - // Bind to the tunnel's status - statusImageView.image = TunnelListCell.image(for: tunnel?.status) - statusObservationToken = tunnel?.observe(\TunnelContainer.status) { [weak self] tunnel, _ in - self?.statusImageView.image = TunnelListCell.image(for: tunnel.status) - } - } - } - - let nameLabel: NSTextField = { - let nameLabel = NSTextField() - nameLabel.isEditable = false - nameLabel.isSelectable = false - nameLabel.isBordered = false - nameLabel.maximumNumberOfLines = 1 - nameLabel.lineBreakMode = .byTruncatingTail - return nameLabel - }() - - let statusImageView = NSImageView() - - private var statusObservationToken: AnyObject? - private var nameObservationToken: AnyObject? - - init() { - super.init(frame: CGRect.zero) - - addSubview(statusImageView) - addSubview(nameLabel) - statusImageView.translatesAutoresizingMaskIntoConstraints = false - nameLabel.translatesAutoresizingMaskIntoConstraints = false - nameLabel.backgroundColor = .clear - NSLayoutConstraint.activate([ - self.leadingAnchor.constraint(equalTo: statusImageView.leadingAnchor), - statusImageView.trailingAnchor.constraint(equalTo: nameLabel.leadingAnchor), - statusImageView.widthAnchor.constraint(equalToConstant: 20), - nameLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor), - statusImageView.centerYAnchor.constraint(equalTo: self.centerYAnchor), - nameLabel.centerYAnchor.constraint(equalTo: self.centerYAnchor) - ]) - } - - required init?(coder decoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - static func image(for status: TunnelStatus?) -> NSImage? { - guard let status = status else { return nil } - switch status { - case .active, .restarting, .reasserting: - return NSImage(named: NSImage.statusAvailableName) - case .activating, .waiting: - return NSImage(named: NSImage.statusPartiallyAvailableName) - case .deactivating, .inactive: - return nil - } - } - - override func prepareForReuse() { - nameLabel.stringValue = "" - statusImageView.image = nil - } -} diff --git a/WireGuard/WireGuard/UI/macOS/View/TunnelListRow.swift b/WireGuard/WireGuard/UI/macOS/View/TunnelListRow.swift new file mode 100644 index 0000000..1a2f6a8 --- /dev/null +++ b/WireGuard/WireGuard/UI/macOS/View/TunnelListRow.swift @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: MIT +// Copyright © 2018 WireGuard LLC. All Rights Reserved. + +import Cocoa + +class TunnelListRow: NSView { + var tunnel: TunnelContainer? { + didSet(value) { + // Bind to the tunnel's name + nameLabel.stringValue = tunnel?.name ?? "" + nameObservationToken = tunnel?.observe(\TunnelContainer.name) { [weak self] tunnel, _ in + self?.nameLabel.stringValue = tunnel.name + } + // Bind to the tunnel's status + statusImageView.image = TunnelListRow.image(for: tunnel?.status) + statusObservationToken = tunnel?.observe(\TunnelContainer.status) { [weak self] tunnel, _ in + self?.statusImageView.image = TunnelListRow.image(for: tunnel.status) + } + } + } + + let nameLabel: NSTextField = { + let nameLabel = NSTextField() + nameLabel.isEditable = false + nameLabel.isSelectable = false + nameLabel.isBordered = false + nameLabel.maximumNumberOfLines = 1 + nameLabel.lineBreakMode = .byTruncatingTail + return nameLabel + }() + + let statusImageView = NSImageView() + + private var statusObservationToken: AnyObject? + private var nameObservationToken: AnyObject? + + init() { + super.init(frame: CGRect.zero) + + addSubview(statusImageView) + addSubview(nameLabel) + statusImageView.translatesAutoresizingMaskIntoConstraints = false + nameLabel.translatesAutoresizingMaskIntoConstraints = false + nameLabel.backgroundColor = .clear + NSLayoutConstraint.activate([ + self.leadingAnchor.constraint(equalTo: statusImageView.leadingAnchor), + statusImageView.trailingAnchor.constraint(equalTo: nameLabel.leadingAnchor), + statusImageView.widthAnchor.constraint(equalToConstant: 20), + nameLabel.trailingAnchor.constraint(equalTo: self.trailingAnchor), + statusImageView.centerYAnchor.constraint(equalTo: self.centerYAnchor), + nameLabel.centerYAnchor.constraint(equalTo: self.centerYAnchor) + ]) + } + + required init?(coder decoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + static func image(for status: TunnelStatus?) -> NSImage? { + guard let status = status else { return nil } + switch status { + case .active, .restarting, .reasserting: + return NSImage(named: NSImage.statusAvailableName) + case .activating, .waiting: + return NSImage(named: NSImage.statusPartiallyAvailableName) + case .deactivating, .inactive: + return nil + } + } + + override func prepareForReuse() { + nameLabel.stringValue = "" + statusImageView.image = nil + } +} diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift index 4a10f7d..8e7db43 100644 --- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift +++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelDetailTableViewController.swift @@ -215,14 +215,14 @@ extension TunnelDetailTableViewController: NSTableViewDelegate { let modelRow = tableViewModelRows[row] switch modelRow { case .interfaceFieldRow(let field): - let cell: KeyValueCell = tableView.dequeueReusableCell() + let cell: KeyValueRow = tableView.dequeueReusableCell() let localizedKeyString = modelRow.isTitleRow() ? modelRow.localizedSectionKeyString() : field.localizedUIString cell.key = tr(format: "macDetailFieldKey (%@)", localizedKeyString) cell.value = tunnelViewModel.interfaceData[field] cell.isKeyInBold = modelRow.isTitleRow() return cell case .peerFieldRow(let peerData, let field): - let cell: KeyValueCell = tableView.dequeueReusableCell() + let cell: KeyValueRow = tableView.dequeueReusableCell() let localizedKeyString = modelRow.isTitleRow() ? modelRow.localizedSectionKeyString() : field.localizedUIString cell.key = tr(format: "macDetailFieldKey (%@)", localizedKeyString) cell.value = peerData[field] diff --git a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift index 7eee345..723814e 100644 --- a/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift +++ b/WireGuard/WireGuard/UI/macOS/ViewController/TunnelsListTableViewController.swift @@ -258,7 +258,7 @@ extension TunnelsListTableViewController: NSTableViewDataSource { extension TunnelsListTableViewController: NSTableViewDelegate { func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? { - let cell: TunnelListCell = tableView.dequeueReusableCell() + let cell: TunnelListRow = tableView.dequeueReusableCell() cell.tunnel = tunnelsManager.tunnel(at: row) return cell } -- cgit v1.2.3-59-g8ed1b