# CutBox.app

## Coverage Report

#### Created: 2024-03-12 03:40

    .../Source/App/JSFuncSearchPreview/JSFuncSearchViewControllerTableViewDelegate.swift

    Line

    Count

    Source (jump to first uncovered line)

    1

    //

    2

    //  JSFuncSearchViewControllerTableViewDelegate.swift

    3

    //  CutBox

    4

    //

    5

    //  Created by Jason Milkins on 17/5/18.

    6

    //  Copyright © 2018-2023 ocodo. All rights reserved.

    7

    //

    8

    9

    import Cocoa

    10

    11

    extension JSFuncSearchViewController: NSTableViewDataSource {

    12

    13

    73

        func numberOfRows(in tableView: NSTableView) -> Int {

    14

    73

            return self.js.count

    15

    73

        }

    16

    }

    17

    18

    extension JSFuncSearchViewController: NSTableViewDelegate {

    19

    1

        func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat {

    20

    1

            return 30

    21

    1

        }

    22

    23

    2

        func updateSearchItemPreview() {

    24

    2

            let row = self.jsFuncView.itemsList.selectedRow

    25

    2

            let name = self.js.funcList[row]

    26

    2

            let preview = self.js.process(name, items: self.selectedClips)

    27

    2

            self.jsFuncView.preview?.string = preview

    28

    2

        }

    29

    30

    1

        func tableViewSelectionDidChange(_ notification: Notification) {

    31

    1

            self.updateSearchItemPreview()

    32

    1

        }

    33

    34

    1

        func tableView(_ tableView: NSTableView, rowViewForRow row: Int) -> NSTableRowView? {

    35

    1

            let rowView = JSFuncItemTableRowContainerView()

    36

    1

            rowView.jsFuncView = self.jsFuncView

    37

    1

            return rowView

    38

    1

        }

    39

    40

        func tableView(_ tableView: NSTableView,

    41

    3

                       viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {

    42

    3

            guard let column = tableColumn else {

    43

    0

                return nil

    44

    3

            }

    45

    3

    46

    3

            let funcItem = self.js.funcList[row]

    47

    3

            let theme = CutBoxPreferencesService.shared.currentTheme

    48

    3

            let rowView: JSFuncItemTableRowContainerView? = tableView.rowView(

    49

    3

                atRow: row,

    50

    3

                makeIfNecessary: false

    51

    3

                ) as? JSFuncItemTableRowContainerView

    52

    3

    53

    3

            switch column.identifier.rawValue {

    54

    3

            case "icon":

    55

    1

                let rowImageView = tableView.getRowView() as JSFuncItemTableRowImageView

    56

    1

                rowImageView.setup()

    57

    1

                rowImageView.color = theme.clip.textColor

    58

    1

                rowView?.imageView = rowImageView

    59

    1

                return rowImageView

    60

    3

    61

    3

            case "string":

    62

    1

                let rowTextView = tableView.getRowView() as JSFuncItemTableRowTextView

    63

    1

                rowTextView.data = ["string": funcItem]

    64

    1

                rowTextView.color = theme.clip.textColor

    65

    1

                rowView?.textView = rowTextView

    66

    1

                return rowTextView

    67

    3

    68

    3

            default:

    69

    1

                return nil

    70

    3

            }

    71

    3

        }

    72

    73

        func tableView(_ tableView: NSTableView,

    74

                       selectionIndexesForProposedSelection proposedSelectionIndexes: IndexSet

    75

    1

            ) -> IndexSet {

    76

    1

    77

    1

            let proposed = proposedSelectionIndexes

    78

    1

    79

    1

            guard !proposed.isEmpty else {

    80

    0

                return proposedSelectionIndexes

    81

    1

            }

    82

    1

    83

    1

            let selected = tableView.selectedRowIndexes

    84

    1

            let removed: IndexSet = selected.subtracting(proposed)

    85

    1

            let theme = CutBoxPreferencesService.shared.currentTheme

    86

    1

    87

    1

            removed

    88

    1

                .map {

    89

    0

                    tableView.rowView(

    90

    0

                        atRow: $0,

    91

    0

                        makeIfNecessary: true

    92

    0

                        ) as? ItemTableRowContainerView

    93

    0

                }

    94

    1

                .forEach {

    95

    0

                    $0?.imageView?.color = theme.clip.textColor

    96

    0

                    $0?.textView?.color = theme.clip.textColor

    97

    0

            }

    98

    1

    99

    1

            return proposedSelectionIndexes

    100

    1

        }

    101

    }