2020-04-07 04:06:42 +02:00
|
|
|
//
|
2020-04-07 22:25:33 +02:00
|
|
|
// ExtensionPointAddViewController.swift
|
2020-04-07 04:06:42 +02:00
|
|
|
// NetNewsWire
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 4/6/20.
|
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import AppKit
|
|
|
|
|
2020-04-07 22:25:33 +02:00
|
|
|
class ExtensionPointAddViewController: NSViewController {
|
2020-04-07 04:06:42 +02:00
|
|
|
|
|
|
|
@IBOutlet weak var tableView: NSTableView!
|
|
|
|
|
2020-04-14 23:47:05 +02:00
|
|
|
private var availableExtensionPointTypes = [ExtensionPoint.Type]()
|
2020-04-07 22:25:33 +02:00
|
|
|
private var extensionPointAddWindowController: NSWindowController?
|
2020-04-07 04:06:42 +02:00
|
|
|
|
|
|
|
init() {
|
2020-04-07 22:25:33 +02:00
|
|
|
super.init(nibName: "ExtensionPointAdd", bundle: nil)
|
2020-04-07 04:06:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public required init?(coder: NSCoder) {
|
|
|
|
super.init(coder: coder)
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
tableView.dataSource = self
|
|
|
|
tableView.delegate = self
|
2020-04-08 17:12:06 +02:00
|
|
|
availableExtensionPointTypes = ExtensionPointManager.shared.availableExtensionPointTypes
|
2020-04-07 04:06:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - NSTableViewDataSource
|
|
|
|
|
2020-04-07 22:25:33 +02:00
|
|
|
extension ExtensionPointAddViewController: NSTableViewDataSource {
|
2020-04-07 04:06:42 +02:00
|
|
|
|
|
|
|
func numberOfRows(in tableView: NSTableView) -> Int {
|
2020-04-08 17:12:06 +02:00
|
|
|
return availableExtensionPointTypes.count
|
2020-04-07 04:06:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func tableView(_ tableView: NSTableView, objectValueFor tableColumn: NSTableColumn?, row: Int) -> Any? {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - NSTableViewDelegate
|
|
|
|
|
2020-04-07 22:25:33 +02:00
|
|
|
extension ExtensionPointAddViewController: NSTableViewDelegate {
|
2020-04-07 04:06:42 +02:00
|
|
|
|
|
|
|
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
|
|
|
|
|
2020-04-07 22:25:33 +02:00
|
|
|
if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "Cell"), owner: nil) as? ExtensionPointAddTableCellView {
|
2020-04-08 17:12:06 +02:00
|
|
|
let extensionPointType = availableExtensionPointTypes[row]
|
|
|
|
cell.titleLabel?.stringValue = extensionPointType.title
|
|
|
|
cell.imageView?.image = extensionPointType.templateImage
|
2020-04-07 04:06:42 +02:00
|
|
|
return cell
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func tableViewSelectionDidChange(_ notification: Notification) {
|
|
|
|
let selectedRow = tableView.selectedRow
|
|
|
|
guard selectedRow != -1 else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-04-09 03:22:13 +02:00
|
|
|
let extensionPointType = availableExtensionPointTypes[selectedRow]
|
2020-04-14 18:05:15 +02:00
|
|
|
|
2020-04-14 23:47:05 +02:00
|
|
|
let windowController = ExtensionPointEnableWindowController()
|
|
|
|
windowController.extensionPointType = extensionPointType
|
|
|
|
windowController.runSheetOnWindow(self.view.window!)
|
|
|
|
extensionPointAddWindowController = windowController
|
2020-04-07 04:06:42 +02:00
|
|
|
|
|
|
|
tableView.selectRowIndexes([], byExtendingSelection: false)
|
2020-04-14 18:05:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|