source: launchers/macosx/I2PLauncher/userinterface/preferences/PreferencesViewController+TableView.swift @ 5d389c8

Last change on this file since 5d389c8 was 68ad4eec, checked in by meeh <meeh@…>, 3 years ago

Mac OS X Launcher: Adding user interface classes for the different Preferences views so far.

  • Property mode set to 100644
File size: 2.3 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  func tableViewDoubleClick(_ sender:AnyObject) {
28   
29    // 1
30    /*guard tableView.selectedRow >= 0,
31     let item = Preferences.shared()[tableView.selectedRow] else {
32     return
33     }
34     
35     if item.isFolder {
36     // 2
37     self.representedObject = item.url as Any
38     }
39     else {
40     // 3
41     NSWorkspace.shared().open(item.url as URL)
42     }
43     */
44  }
45 
46  func tableView(_ tableView: NSTableView, sortDescriptorsDidChange oldDescriptors: [NSSortDescriptor]) {
47    // 1
48    guard let sortDescriptor = tableView.sortDescriptors.first else {
49      return
50    }
51    /*if let order = Directory.FileOrder(rawValue: sortDescriptor.key!) {
52     // 2
53     sortOrder = order
54     sortAscending = sortDescriptor.ascending
55     reloadFileList()
56     }*/
57  }
58 
59 
60  func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
61   
62    //var image: NSImage?
63    var text: String = ""
64    var cellIdentifier: String = ""
65   
66   
67    // 1
68    guard let item = Preferences.shared()[row] else {
69      return nil
70    }
71   
72    // 2
73    if tableColumn == tableView.tableColumns[0] {
74      text = item.name!
75      cellIdentifier = CellIdentifiers.NameCell
76    } else if tableColumn == tableView.tableColumns[1] {
77      text = "\(item.defaultValue!)"
78      cellIdentifier = CellIdentifiers.DefaultCell
79    } else if tableColumn == tableView.tableColumns[2] {
80      let thing = (item.selectedValue ?? "none")
81      text = "\(thing)"
82      cellIdentifier = CellIdentifiers.ValueCell
83    }
84   
85    // 3
86    if let cell = tableView.make(withIdentifier: cellIdentifier, owner: nil) as? NSTableCellView {
87      cell.textField?.stringValue = text
88      //cell.imageView?.image = image ?? nil
89      return cell
90    }
91    return nil
92  }
93 
94}
Note: See TracBrowser for help on using the repository browser.