-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from Pavo-IM/hyperlink-textfield
Make OpenCore Desktop Guide url a hyperlink
- Loading branch information
Showing
5 changed files
with
74 additions
and
12 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
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
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 @@ | ||
// | ||
// HyperlinkTextField.swift | ||
// OC Gen-X | ||
// | ||
// Created by Stephen Heaps on 2020-06-27. | ||
// Copyright © 2020 Henry Brock. All rights reserved. | ||
// | ||
|
||
import AppKit | ||
|
||
/// Subclass of NSTextField used to display hyperlinks. From https://stackoverflow.com/a/34093140 with minor additionalAttributes update. | ||
class HyperlinkTextField: NSTextField { | ||
|
||
/// Set content to be a hyperlink | ||
/// | ||
/// Based on code at <https://developer.apple.com/library/mac/qa/qa1487/_index.html> | ||
/// | ||
/// - parameters: | ||
/// - title: text displayed in field | ||
/// - URL: destination of hyperlink | ||
func setHyperlinkWithTitle(title: String, URL: NSURL, additionalAttributes: [NSAttributedString.Key: Any]?) { | ||
allowsEditingTextAttributes = true | ||
isSelectable = true | ||
|
||
let attributedString = NSMutableAttributedString(string: title, attributes: additionalAttributes ?? [:]) | ||
attributedString.addAttribute(.link, value: URL, range: NSRange(location: 0, length: attributedString.length)) | ||
|
||
attributedStringValue = attributedString | ||
} | ||
|
||
/// Always display a pointing-hand cursor | ||
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