# CutBox.app

## Coverage Report

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

    .../Source/App/SearchAndPreview/ClipItems/ClipItemTableRowImageButtonView.swift

    Line

    Count

    Source

    1

    //

    2

    //  ClipItemTableRowImageButtonView.swift

    3

    //  CutBox

    4

    //

    5

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

    6

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

    7

    //

    8

    9

    import Cocoa

    10

    11

    class ClipItemTableRowImageButtonView: NSView {

    12

    13

        @IBOutlet weak var imageButton: NSButton!

    14

    15

    2

        private var isFavorite: Bool {

    16

    2

            if let data = data,

    17

    2

               let favoriteData = data["favorite"],

    18

    2

                !favoriteData.isEmpty {

    19

    1

                return true

    20

    1

            }

    21

    1

            return false

    22

    2

        }

    23

    24

    1

        private var internalColor: NSColor = NSColor.textColor

    25

        var color: NSColor {

    26

    7

            get {

    27

    7

                return internalColor

    28

    7

            }

    29

    30

    3

            set {

    31

    3

                internalColor = newValue

    32

    3

                self.tintImage()

    33

    3

            }

    34

        }

    35

    36

        private var internalData: [String: String]?

    37

        var data: [String: String]? {

    38

    5

            get {

    39

    5

                return internalData

    40

    5

            }

    41

    3

            set {

    42

    3

                internalData = newValue

    43

    3

                setup()

    44

    3

            }

    45

        }

    46

    47

    3

        private func setup() {

    48

    3

            guard self.data != nil else {

    49

    1

                fatalError("Data must be initialized on ClipItemTableRowView before setup.")

    50

    3

            }

    51

    3

    52

    3

            self.imageButton.image = self.isFavorite

    53

    3

            ? CutBoxImageRef.star.image()

    54

    3

            : CutBoxImageRef.page.image()

    55

    3

    56

    3

            self.tintImage()

    57

    3

        }

    58

    59

    5

        private func tintImage() {

    60

    5

            guard let imageData = self.imageButton.image else { return }

    61

    4

            let blended = imageData.tint(color: self.color)

    62

    4

            self.imageButton.image = blended

    63

    4

        }

    64

    }