-
-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improves PreferencesPanel UX, partially implements #49
implements requested changes from Code-Review and contains also refactoring, additions & improvements - PreferencesPanel: does not handle NSApp.activate & .deactivate anymore - PreferencesPanel: maxThumbnailsPerRow & windowDisplayDelay are now sliders - PreferencesPanel: Sliders do not use tickmarks anymore (to allow finer settings) - PreferencesPanel: tweaked Sliders min/max values - PreferencesPanel: adds Hyperlink to KeyCodes Reference as suffix for Tab key control (with additional required sub-class of NSTextField) - PreferencesPanel: adds makeSuffix() method for code clarity
- Loading branch information
Showing
5 changed files
with
99 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 0 additions & 34 deletions
34
alt-tab-macos/logic/PreferencesPanelNSTextFieldEditable.swift
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Cocoa | ||
|
||
class HyperlinkLabel: NSTextField { | ||
|
||
public convenience init(labelWithUrl stringValue: String, nsUrl: NSURL) { | ||
self.init(labelWithString: stringValue) | ||
isSelectable = true | ||
allowsEditingTextAttributes = true | ||
let linkTextAttributes: [NSAttributedString.Key: Any] = [ | ||
NSAttributedString.Key.link: nsUrl as Any, | ||
NSAttributedString.Key.font: NSFont.labelFont(ofSize: NSFont.systemFontSize), | ||
] | ||
|
||
attributedStringValue = NSAttributedString(string: stringValue, attributes: linkTextAttributes) | ||
} | ||
|
||
// the whole point for this sub-class: always display a pointing-hand cursor (not only when the TextField is focused) | ||
override func resetCursorRects() { | ||
addCursorRect(bounds, cursor: NSCursor.pointingHand) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import Cocoa | ||
|
||
class TextField: NSTextField, NSTextFieldDelegate { | ||
|
||
var validationHandler: ((String)->Bool)? | ||
|
||
public convenience init(_ value: String) { | ||
self.init(string: value) | ||
wantsLayer = true | ||
layer?.borderWidth = 1 | ||
} | ||
|
||
func controlTextDidChange(_ obj: Notification) { | ||
visualizeValidationState() | ||
let textField = obj.object as! TextField | ||
sendAction(textField.action, to: textField.target) | ||
} | ||
|
||
func visualizeValidationState() -> Void { | ||
if !isValid() { | ||
layer?.borderColor = NSColor.systemRed.cgColor | ||
} else { | ||
layer?.borderColor = .clear | ||
} | ||
} | ||
|
||
func isValid() -> Bool { | ||
if let handler = validationHandler { | ||
return handler(stringValue) | ||
} | ||
|
||
return true | ||
} | ||
|
||
} |