diff options
| author | Mike Vink <59492084+ivi-vink@users.noreply.github.com> | 2025-01-20 20:45:21 +0100 |
|---|---|---|
| committer | Mike Vink <59492084+ivi-vink@users.noreply.github.com> | 2025-01-20 20:45:21 +0100 |
| commit | 57c3c64e71ae156855f8b6c84cd71d7d692a8b0a (patch) | |
| tree | e3b25d811a89570b6a3ef880aa0e8992069c5773 /kies/InputField.swift | |
Squashed 'mut/keuze/' content from commit 720bb27
git-subtree-dir: mut/keuze
git-subtree-split: 720bb270aeb006ec2f3ca1104e78785de31f2630
Diffstat (limited to 'kies/InputField.swift')
| -rw-r--r-- | kies/InputField.swift | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/kies/InputField.swift b/kies/InputField.swift new file mode 100644 index 0000000..6e8e27c --- /dev/null +++ b/kies/InputField.swift @@ -0,0 +1,67 @@ +// +// KiesInputField.swift +// kies +// +// Created by Thomas Billiet on 08/04/2019. +// Copyright © 2019 Thomas Billiet. All rights reserved. +// + +import Foundation +import Cocoa + +class InputField: NSTextField, NSTextFieldDelegate { + var appDelegate: AppDelegate! + + init(appDelegate: AppDelegate) { + super.init(frame: layouts.inputRect) + self.appDelegate = appDelegate + stringValue = "" + isEditable = true + isSelectable = true + delegate = self + bezelStyle = .squareBezel + isBordered = false + drawsBackground = false + focusRingType = .none + target = self + font = settings.font + allowsEditingTextAttributes = false + isAutomaticTextCompletionEnabled = false + allowsDefaultTighteningForTruncation = false + maximumNumberOfLines = 1 + cell?.wraps = false + cell?.isScrollable = true + autoresizingMask = [NSView.AutoresizingMask.width] + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func control(_ control: NSControl, textView: NSTextView, doCommandBy commandSelector: Selector) -> Bool { + if (commandSelector == #selector(NSStandardKeyBindingResponding.cancelOperation(_:))){ + appDelegate.cancel() + return true + } + if (commandSelector == #selector(NSStandardKeyBindingResponding.insertNewline(_:))){ + appDelegate.handleSelect() + return true + } + if (commandSelector == #selector(NSStandardKeyBindingResponding.moveUp(_:))){ + appDelegate.handleMoveUp() + return true + } + if (commandSelector == #selector(NSStandardKeyBindingResponding.moveDown(_:))){ + appDelegate.handleMoveDown() + return true + } + if (commandSelector == #selector(NSStandardKeyBindingResponding.insertTab(_:))){ + return true + } + return false + } + + func controlTextDidChange(_ obj: Notification) { + appDelegate.handleInputChange(input: stringValue) + } +} |
