source: launchers/macosx/I2PLauncher/userinterface/preferences/PreferencesViewController+TableView.swift @ 56eb11bc

Last change on this file since 56eb11bc was 56eb11bc, checked in by meeh <meeh@…>, 13 months ago

Mac OSX Launcher: Adding Swift 4.2 support to the preferences UI classes.

  • Property mode set to 100644
File size: 2.5 KB
Line 
1//
2//  PreferencesViewController+TableView.swift
3//  I2PLauncher
4//
5//  Created by Mikal Villa on 08/12/2018.
6//  Copyright © 2018 The I2P Project. All rights reserved.
7//
8
9import Cocoa
10
11extension PreferencesViewController: NSTableViewDataSource {
12 
13  func numberOfRows(in tableView: NSTableView) -> Int {
14    return Preferences.shared().count
15  }
16 
17}
18
19extension PreferencesViewController: NSTableViewDelegate {
20 
21  fileprivate enum CellIdentifiers {
22    static let NameCell = "KeyColumnID"
23    static let DefaultCell = "DefaultColumnID"
24    static let ValueCell = "ValueColumnID"
25  }
26 
27  @objc func tableViewDoubleClick(_ sender:AnyObject) {
28    print("Double click")
29    // 1
30    print(self.advPrefTableView.selectedRow)
31    guard self.advPrefTableView.selectedRow >= 0,
32      let item = Preferences.shared()[self.advPrefTableView.selectedRow] else {
33        return
34    }
35    print(item.name as Any)
36     /*
37     if item.isFolder {
38     // 2
39     self.representedObject = item.url as Any
40     }
41     else {
42     // 3
43     NSWorkspace.shared().open(item.url as URL)
44     }
45     */
46  }
47 
48  func tableView(_ tableView: NSTableView, sortDescriptorsDidChange oldDescriptors: [NSSortDescriptor]) {
49    // 1
50    guard let /*sortDescriptor*/ _ = self.advPrefTableView.sortDescriptors.first else {
51      return
52    }
53    /*if let order = Directory.FileOrder(rawValue: sortDescriptor.key!) {
54     // 2
55     sortOrder = order
56     sortAscending = sortDescriptor.ascending
57     reloadFileList()
58     }*/
59  }
60 
61 
62  func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
63   
64    //var image: NSImage?
65    var text: String = ""
66    var cellIdentifier: String = ""
67   
68   
69    // 1
70    guard let item = Preferences.shared()[row] else {
71      return nil
72    }
73   
74    // 2
75    if tableColumn == tableView.tableColumns[0] {
76      text = item.name!
77      cellIdentifier = CellIdentifiers.NameCell
78    } else if tableColumn == tableView.tableColumns[1] {
79      text = "\(item.defaultValue ?? "")"
80      cellIdentifier = CellIdentifiers.DefaultCell
81    } else if tableColumn == tableView.tableColumns[2] {
82      let thing = (item.selectedValue ?? "none")
83      text = "\(thing)"
84      cellIdentifier = CellIdentifiers.ValueCell
85    }
86   
87    // 3
88    if let cell = tableView.makeView(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: cellIdentifier), owner: nil) as? NSTableCellView {
89      cell.textField?.stringValue = text
90      //cell.imageView?.image = image ?? nil
91      return cell
92    }
93    return nil
94  }
95 
96}
Note: See TracBrowser for help on using the repository browser.