# CutBox.app

## Coverage Report

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

    .../Source/App/Preferences/PreferencesAdvancedView+HistoryLimit.swift

    Line

    Count

    Source (jump to first uncovered line)

    1

    //

    2

    //  PreferencesAdvancedView+HistoryLimit.swift

    3

    //  CutBox

    4

    //

    5

    //  Created by Jason Milkins on 14/4/18.

    6

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

    7

    //

    8

    9

    import RxCocoa

    10

    import RxSwift

    11

    12

    extension PreferencesAdvancedView {

    13

    14

    50

        func setupHistoryLimitControls() {

    15

    50

            self.setupHistoryUnlimitedCheckbox()

    16

    50

            self.setupHistoryLimitTextField()

    17

    50

        }

    18

    19

    50

        func setupHistoryUnlimitedCheckbox() {

    20

    50

            self.historyUnlimitedCheckbox.title = "preferences_history_limit_checkbox_label".l7n

    21

    50

    22

    50

            self.historyUnlimitedCheckbox.state = prefs

    23

    50

                .historyLimited

    24

    50

                ? .off

    25

    50

                : .on

    26

    50

    27

    50

            self.historyUnlimitedCheckbox.rx.state

    28

    50

                .map { $0 == .off }

    29

    100

                .subscribe(onNext: onNextHistoryUnlimitedCheckboxEvent)

    $s15CutBoxUnitTests23PreferencesAdvancedViewC29setupHistoryUnlimitedCheckboxyyFySbcACcfu_

    Line

    Count

    Source

    29

    50

                .subscribe(onNext: onNextHistoryUnlimitedCheckboxEvent)

    $s15CutBoxUnitTests23PreferencesAdvancedViewC29setupHistoryUnlimitedCheckboxyyFySbcACcfu_ySbcfu0_

    Line

    Count

    Source

    29

    50

                .subscribe(onNext: onNextHistoryUnlimitedCheckboxEvent)

    30

    50

                .disposed(by: disposeBag)

    31

    50

        }

    32

    33

    50

        func onNextHistoryUnlimitedCheckboxEvent(state: Bool) {

    34

    50

            self.prefs.historyLimited = state

    35

    50

            self.historyLimitTextField.isEnabled = state

    36

    50

            if !state {

    37

    50

                self.historyLimitTextField.stringValue = ""

    38

    50

            }

    39

    50

        }

    40

    41

    50

        func setupHistoryLimitTextField() {

    42

    50

            let historyLimit = prefs.historyLimit

    43

    50

    44

    50

            self.historyLimitTitle.stringValue = "preferences_history_limit_title".l7n

    45

    50

            self.historyLimitTextField.placeholderString = "preferences_history_limit_placeholder".l7n

    46

    50

    47

    50

            self.historyLimitTextField.formatter = HistoryLimitNumberFormatter()

    48

    50

    49

    50

            self.historyLimitTextField.stringValue = String(historyLimit)

    50

    50

    51

    50

            self.historyLimitTextField.rx.controlEvent

    52

    50

                .map { Int(self.historyLimitTextField.stringValue) ?? 0 }

    53

    50

                .subscribe(onNext: setHistoryLimitWithConfirmation)

    $s15CutBoxUnitTests23PreferencesAdvancedViewC26setupHistoryLimitTextFieldyyFySicACcfu_

    Line

    Count

    Source

    53

    50

                .subscribe(onNext: setHistoryLimitWithConfirmation)

    Unexecuted instantiation: $s15CutBoxUnitTests23PreferencesAdvancedViewC26setupHistoryLimitTextFieldyyFySicACcfu_ySicfu0_

    54

    50

                .disposed(by: disposeBag)

    55

    50

        }

    56

    57

    2

        func setHistoryLimitWithConfirmation(_ limit: Int) {

    58

    2

            let currentLimit = self.prefs.historyLimit

    59

    2

    60

    2

            if limitChangeIsDestructive(limit: limit, currentLimit: currentLimit) {

    61

    2

                if dialogFactory.suppressibleConfirmationDialog(

    62

    2

                    messageText: "confirm_warning_clear_history_title".l7n,

    63

    2

                    informativeText: "confirm_warning_clear_history".l7n,

    64

    2

                    dialogName: .destructiveLimitChangeWarning) {

    65

    1

                    self.prefs.historyLimit = limit

    66

    2

                } else {

    67

    1

                    self.historyLimitTextField?.stringValue = String(currentLimit)

    68

    2

                }

    69

    2

            }

    70

    2

        }

    71

    72

    6

        func limitChangeIsDestructive(limit: Int, currentLimit: Int) -> Bool {

    73

    6

            return (limit > 0 && currentLimit == 0) ||

    74

    6

                (limit > 0 && currentLimit > limit)

    75

    6

        }

    76

    }