<commit_before>//
//  GeneralPreferenceViewController.swift
//  Jumpcut
//
//  Created by <NAME> on 4/16/22.
//

import Cocoa
import Preferences
import ServiceManagement

final class GeneralPreferenceViewController: NSViewController, PreferencePane {
    let preferencePaneIdentifier = Preferences.PaneIdentifier.general
    let preferencePaneTitle = "General"
    let toolbarItemIcon = NSImage(named: "gearshape")!

    // Dummy nib; we'll build the UI programatically
    override func loadView() {
        self.view = NSView()
    }
    override var nibName: NSNib.Name? { nil }

    @objc func dispatchResetPreferences() {
        let alert = NSAlert()
        alert.messageText = "Do you want to reset preferences?"
        alert.informativeText = "This action cannot be undone."
        alert.alertStyle = .warning
        alert.addButton(withTitle: "OK")
        alert.addButton(withTitle: "Cancel")
        let response = alert.runModal()
        if response == .alertFirstButtonReturn {
            Settings.reset()
        }
    }

    @objc func toggleLaunchOnLogin(sender: NSButton) {
        let helper = "net.sf.Jumpcut.JumpcutHelper"
        if sender.state == .on {
            if !SMLoginItemSetEnabled(helper as CFString, true) {
                #if DEBUG
                    print("SMLoginItemSetEnabled for \(helper) (true) failed")
                #endif
            }
        } else {
            if !SMLoginItemSetEnabled(helper as CFString, false) {
                #if DEBUG
                    print("SMLoginItemSetEnabled for \(helper) (false) failed")
                #endif
            }
        }
    }

    private func makeSeparator() -> NSBox {
        let separator = NSBox()
        separator.boxType = .separator
        return separator
    }

    private func makeBezelToTopRow(settings: Settings) -> NSStackView {
        let options = [
            (title: "Bezel position is unchanged", value: 0),
            (title: "Bezel position returns to top", value: 1)
        ]
        let popup = settings.popup(title: "After recording a new clipping…",
                                   key: SettingsPath.bezelToTop, options: options)
        let popupStack = NSStackView(views: [popup])
        return popupStack
    }

    private func makeAdvancedMenuRow(settings: Settings) -> NSStackView {
        let options = [
            (title: "None", value: MenuBehaviorFlags.none.rawValue),
            (title: "Right click for additional options", value: MenuBehaviorFlags.rightAlt.rawValue),
            (title: "…and shift click to switch paste behavior",
             value: MenuBehaviorFlags.rightAltShiftToggle.rawValue),
            (title: "Shift click for additional options", value: MenuBehaviorFlags.shiftAlt.rawValue),
            (title: "…and right click to switch paste behavior",
             value: MenuBehaviorFlags.shiftAltRightToggle.rawValue)
        ]
        let popup = settings.popup(title: "Alternate menu behavior",
                                   key: SettingsPath.menuBehaviorFlags, options: options)
        let popupStack = NSStackView(views: [popup])
        return popupStack
    }

    private func makeResetRow() -> NSStackView {
        let resetButton = NSButton()
        resetButton.title = "Reset Preferences"
        resetButton.target = self
        resetButton.action = #selector(self.dispatchResetPreferences)
        resetButton.controlSize = .small
        resetButton.bezelStyle = .rounded
        let resetRow = NSStackView(views: [resetButton])
        resetRow.alignment = .right
        return resetRow
    }

    private func makeLaunchOnLogin(settings: Settings) -> NSButton {
        return settings.checkbox(
            title: "Launch on login",
            key: SettingsPath.launchOnStartup,
            target: self,
            action: #selector(self.toggleLaunchOnLogin)
        )
    }<commit_msg>Tweak to wording of alternate menu options dropdown<commit_after>//
//  GeneralPreferenceViewController.swift
//  Jumpcut
//
//  Created by <NAME> on 4/16/22.
//

import Cocoa
import Preferences
import ServiceManagement

final class GeneralPreferenceViewController: NSViewController, PreferencePane {
    let preferencePaneIdentifier = Preferences.PaneIdentifier.general
    let preferencePaneTitle = "General"
    let toolbarItemIcon = NSImage(named: "gearshape")!

    // Dummy nib; we'll build the UI programatically
    override func loadView() {
        self.view = NSView()
    }
    override var nibName: NSNib.Name? { nil }

    @objc func dispatchResetPreferences() {
        let alert = NSAlert()
        alert.messageText = "Do you want to reset preferences?"
        alert.informativeText = "This action cannot be undone."
        alert.alertStyle = .warning
        alert.addButton(withTitle: "OK")
        alert.addButton(withTitle: "Cancel")
        let response = alert.runModal()
        if response == .alertFirstButtonReturn {
            Settings.reset()
        }
    }

    @objc func toggleLaunchOnLogin(sender: NSButton) {
        let helper = "net.sf.Jumpcut.JumpcutHelper"
        if sender.state == .on {
            if !SMLoginItemSetEnabled(helper as CFString, true) {
                #if DEBUG
                    print("SMLoginItemSetEnabled for \(helper) (true) failed")
                #endif
            }
        } else {
            if !SMLoginItemSetEnabled(helper as CFString, false) {
                #if DEBUG
                    print("SMLoginItemSetEnabled for \(helper) (false) failed")
                #endif
            }
        }
    }

    private func makeSeparator() -> NSBox {
        let separator = NSBox()
        separator.boxType = .separator
        return separator
    }

    private func makeBezelToTopRow(settings: Settings) -> NSStackView {
        let options = [
            (title: "Bezel position is unchanged", value: 0),
            (title: "Bezel position returns to top", value: 1)
        ]
        let popup = settings.popup(title: "After recording a new clipping…",
                                   key: SettingsPath.bezelToTop, options: options)
        let popupStack = NSStackView(views: [popup])
        return popupStack
    }

    private func makeAdvancedMenuRow(settings: Settings) -> NSStackView {
        let options = [
            (title: "None", value: MenuBehaviorFlags.none.rawValue),
            (title: "Right click for additional options", value: MenuBehaviorFlags.rightAlt.rawValue),
            (title: "…and shift click to toggle paste",
             value: MenuBehaviorFlags.rightAltShiftToggle.rawValue),
            (title: "Shift click for additional options", value: MenuBehaviorFlags.shiftAlt.rawValue),
            (title: "…and right click to toggle-paste",
             value: MenuBehaviorFlags.shiftAltRightToggle.rawValue)
        ]
        let popup = settings.popup(title: "Alternate menu behavior",
                                   key: SettingsPath.menuBehaviorFlags, options: options)
        let popupStack = NSStackView(views: [popup])
        return popupStack
    }

    private func makeResetRow() -> NSStackView {
        let resetButton = NSButton()
        resetButton.title = "Reset Preferences"
        resetButton.target = self
        resetButton.action = #selector(self.dispatchResetPreferences)
        resetButton.controlSize = .small
        resetButton.bezelStyle = .rounded
        let resetRow = NSStackView(views: [resetButton])
        resetRow.alignment = .right
        return resetRow
    }

    private func makeLaunchOnLogin(settings: Settings) -> NSButton {
        return settings.checkbox(
            title: "Launch on login",
            key: SettingsPath.launchOnStartup,
            target: self,
            action: #selector(self.toggleLaunchOnLogin)
        )
    }
{'fraction_non_alphanumeric': 0.08924455825864276, 'fraction_numerical': 0.001792573623559539, 'mean_word_length': 2.2197032151690026, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2768948', 'n_tokens_mistral': 2079, 'n_tokens_neox': 1998, 'n_words': 550}