NetNewsWire/Mac/Preferences/ExtensionPoints/ExtensionPointAddViewContro...

80 lines
2.2 KiB
Swift
Raw Normal View History

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!
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
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 {
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 {
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
}
let extensionPointType = availableExtensionPointTypes[selectedRow]
2020-04-14 18:05:15 +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
}
}