macOS: Manage tunnels: Update tunnels list on changes
Signed-off-by: Roopesh Chander <roop@roopc.net>
This commit is contained in:
parent
60cfceec4f
commit
dfc4b37518
|
@ -13,9 +13,10 @@ class StatusMenu: NSMenu {
|
||||||
var firstTunnelMenuItemIndex: Int = 0
|
var firstTunnelMenuItemIndex: Int = 0
|
||||||
var numberOfTunnelMenuItems: Int = 0
|
var numberOfTunnelMenuItems: Int = 0
|
||||||
|
|
||||||
|
var manageTunnelsRootVC: ManageTunnelsRootViewController?
|
||||||
lazy var manageTunnelsWindow: NSWindow = {
|
lazy var manageTunnelsWindow: NSWindow = {
|
||||||
let manageTunnelsRootVC = ManageTunnelsRootViewController(tunnelsManager: tunnelsManager)
|
manageTunnelsRootVC = ManageTunnelsRootViewController(tunnelsManager: tunnelsManager)
|
||||||
let window = NSWindow(contentViewController: manageTunnelsRootVC)
|
let window = NSWindow(contentViewController: manageTunnelsRootVC!)
|
||||||
window.title = tr("macWindowTitleManageTunnels")
|
window.title = tr("macWindowTitleManageTunnels")
|
||||||
window.setFrameAutosaveName(NSWindow.FrameAutosaveName("ManageTunnelsWindow")) // Auto-save window position and size
|
window.setFrameAutosaveName(NSWindow.FrameAutosaveName("ManageTunnelsWindow")) // Auto-save window position and size
|
||||||
return window
|
return window
|
||||||
|
@ -196,19 +197,23 @@ extension StatusMenu: TunnelsManagerListDelegate {
|
||||||
func tunnelAdded(at index: Int) {
|
func tunnelAdded(at index: Int) {
|
||||||
let tunnel = tunnelsManager.tunnel(at: index)
|
let tunnel = tunnelsManager.tunnel(at: index)
|
||||||
insertTunnelMenuItem(for: tunnel, at: index)
|
insertTunnelMenuItem(for: tunnel, at: index)
|
||||||
|
manageTunnelsRootVC?.tunnelsListVC?.tunnelAdded(at: index)
|
||||||
}
|
}
|
||||||
|
|
||||||
func tunnelModified(at index: Int) {
|
func tunnelModified(at index: Int) {
|
||||||
if let tunnelMenuItem = item(at: firstTunnelMenuItemIndex + index) {
|
if let tunnelMenuItem = item(at: firstTunnelMenuItemIndex + index) {
|
||||||
updateTunnelMenuItem(tunnelMenuItem)
|
updateTunnelMenuItem(tunnelMenuItem)
|
||||||
}
|
}
|
||||||
|
manageTunnelsRootVC?.tunnelsListVC?.tunnelModified(at: index)
|
||||||
}
|
}
|
||||||
|
|
||||||
func tunnelMoved(from oldIndex: Int, to newIndex: Int) {
|
func tunnelMoved(from oldIndex: Int, to newIndex: Int) {
|
||||||
moveTunnelMenuItem(from: oldIndex, to: newIndex)
|
moveTunnelMenuItem(from: oldIndex, to: newIndex)
|
||||||
|
manageTunnelsRootVC?.tunnelsListVC?.tunnelMoved(from: oldIndex, to: newIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
func tunnelRemoved(at index: Int) {
|
func tunnelRemoved(at index: Int) {
|
||||||
removeTunnelMenuItem(at: index)
|
removeTunnelMenuItem(at: index)
|
||||||
|
manageTunnelsRootVC?.tunnelsListVC?.tunnelRemoved(at: index)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import Cocoa
|
||||||
class ManageTunnelsRootViewController: NSViewController {
|
class ManageTunnelsRootViewController: NSViewController {
|
||||||
|
|
||||||
let tunnelsManager: TunnelsManager
|
let tunnelsManager: TunnelsManager
|
||||||
|
var tunnelsListVC: TunnelsListTableViewController?
|
||||||
let tunnelDetailContainerView = NSView()
|
let tunnelDetailContainerView = NSView()
|
||||||
var tunnelDetailContentVC: NSViewController?
|
var tunnelDetailContentVC: NSViewController?
|
||||||
|
|
||||||
|
@ -34,11 +35,11 @@ class ManageTunnelsRootViewController: NSViewController {
|
||||||
view.trailingAnchor.constraint(equalTo: container.trailingAnchor, constant: horizontalSpacing)
|
view.trailingAnchor.constraint(equalTo: container.trailingAnchor, constant: horizontalSpacing)
|
||||||
])
|
])
|
||||||
|
|
||||||
let tunnelsListVC = TunnelsListTableViewController(tunnelsManager: tunnelsManager)
|
tunnelsListVC = TunnelsListTableViewController(tunnelsManager: tunnelsManager)
|
||||||
tunnelsListVC.delegate = self
|
tunnelsListVC!.delegate = self
|
||||||
let tunnelsListView = tunnelsListVC.view
|
let tunnelsListView = tunnelsListVC!.view
|
||||||
|
|
||||||
addChild(tunnelsListVC)
|
addChild(tunnelsListVC!)
|
||||||
view.addSubview(tunnelsListView)
|
view.addSubview(tunnelsListView)
|
||||||
view.addSubview(tunnelDetailContainerView)
|
view.addSubview(tunnelDetailContainerView)
|
||||||
|
|
||||||
|
|
|
@ -206,6 +206,24 @@ class TunnelsListTableViewController: NSViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension TunnelsListTableViewController {
|
||||||
|
func tunnelAdded(at index: Int) {
|
||||||
|
tableView.insertRows(at: IndexSet(integer: index), withAnimation: .slideLeft)
|
||||||
|
}
|
||||||
|
|
||||||
|
func tunnelModified(at index: Int) {
|
||||||
|
tableView.reloadData(forRowIndexes: IndexSet(integer: index), columnIndexes: IndexSet(integer: 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
func tunnelMoved(from oldIndex: Int, to newIndex: Int) {
|
||||||
|
tableView.moveRow(at: oldIndex, to: newIndex)
|
||||||
|
}
|
||||||
|
|
||||||
|
func tunnelRemoved(at index: Int) {
|
||||||
|
tableView.removeRows(at: IndexSet(integer: index), withAnimation: .slideLeft)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension TunnelsListTableViewController: NSTableViewDataSource {
|
extension TunnelsListTableViewController: NSTableViewDataSource {
|
||||||
func numberOfRows(in tableView: NSTableView) -> Int {
|
func numberOfRows(in tableView: NSTableView) -> Int {
|
||||||
return tunnelsManager.numberOfTunnels()
|
return tunnelsManager.numberOfTunnels()
|
||||||
|
|
Loading…
Reference in New Issue