From 9a1bc23baf61010388f97b71e2d8374d41e54527 Mon Sep 17 00:00:00 2001 From: Stephen Heaps Date: Sat, 27 Jun 2020 13:39:23 -0400 Subject: [PATCH] - Added HyperlinkTextField, updated desktop guide link to be clickable, minor constraint updates to resolve warnings --- OC Gen-X.xcodeproj/project.pbxproj | 12 +++++++++ OC Gen-X/Base.lproj/Main.storyboard | 25 ++++++++++-------- OC Gen-X/MainVC.swift | 13 ++++++++- OC Gen-X/Views/HyperlinkTextField.swift | 35 +++++++++++++++++++++++++ README.md | 1 + 5 files changed, 74 insertions(+), 12 deletions(-) create mode 100644 OC Gen-X/Views/HyperlinkTextField.swift diff --git a/OC Gen-X.xcodeproj/project.pbxproj b/OC Gen-X.xcodeproj/project.pbxproj index 9df40d2..a3026dd 100644 --- a/OC Gen-X.xcodeproj/project.pbxproj +++ b/OC Gen-X.xcodeproj/project.pbxproj @@ -52,6 +52,7 @@ CFE8A230249E662400D72669 /* AppIcon.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CFE8A22F249E662400D72669 /* AppIcon.xcassets */; }; CFEA3A7C249E3FB500EDE7CB /* Bootstrap.efi in Resources */ = {isa = PBXBuildFile; fileRef = CFEA3A7B249E3FB500EDE7CB /* Bootstrap.efi */; }; CFEACE92249E5C8300A7F0B3 /* IntelMausi.kext in Resources */ = {isa = PBXBuildFile; fileRef = CFEACE91249E5C8300A7F0B3 /* IntelMausi.kext */; }; + D5B5BBF824A7B6CC004E5D7C /* HyperlinkTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B5BBF724A7B6CC004E5D7C /* HyperlinkTextField.swift */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -104,6 +105,7 @@ CFE8A22F249E662400D72669 /* AppIcon.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = AppIcon.xcassets; sourceTree = ""; }; CFEA3A7B249E3FB500EDE7CB /* Bootstrap.efi */ = {isa = PBXFileReference; lastKnownFileType = file; path = Bootstrap.efi; sourceTree = ""; }; CFEACE91249E5C8300A7F0B3 /* IntelMausi.kext */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.kernel-extension"; path = IntelMausi.kext; sourceTree = ""; }; + D5B5BBF724A7B6CC004E5D7C /* HyperlinkTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HyperlinkTextField.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -190,6 +192,7 @@ CF4C2008243D067000D2F187 /* Kexts */, CF4C2035243D077E00D2F187 /* OC Files */, CF4C200A243D069000D2F187 /* Drivers */, + D5B5BBF924A7B6FB004E5D7C /* Views */, CF59E727241DA2D500A7C5EC /* AppDelegate.swift */, CF59E739241DA57A00A7C5EC /* MainVC.swift */, CF59E73D241DA7F500A7C5EC /* MainWindowController.swift */, @@ -219,6 +222,14 @@ path = Config; sourceTree = ""; }; + D5B5BBF924A7B6FB004E5D7C /* Views */ = { + isa = PBXGroup; + children = ( + D5B5BBF724A7B6CC004E5D7C /* HyperlinkTextField.swift */, + ); + path = Views; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -327,6 +338,7 @@ CF59E73A241DA57A00A7C5EC /* MainVC.swift in Sources */, CF6F111C241E96F400B70805 /* Booter.swift in Sources */, CF6F1122241E971E00B70805 /* Misc.swift in Sources */, + D5B5BBF824A7B6CC004E5D7C /* HyperlinkTextField.swift in Sources */, CF6F1124241E972600B70805 /* NVRAM.swift in Sources */, CF59E728241DA2D500A7C5EC /* AppDelegate.swift in Sources */, CF6F1128241E973E00B70805 /* UEFI.swift in Sources */, diff --git a/OC Gen-X/Base.lproj/Main.storyboard b/OC Gen-X/Base.lproj/Main.storyboard index f05e0d3..6da68c0 100644 --- a/OC Gen-X/Base.lproj/Main.storyboard +++ b/OC Gen-X/Base.lproj/Main.storyboard @@ -729,7 +729,7 @@ - + @@ -1594,17 +1594,17 @@ Add watchdog=0 to disable WatchDog timer (if you get accidental reboots). - - - + + + - - - + + + @@ -1614,26 +1614,29 @@ Add watchdog=0 to disable WatchDog timer (if you get accidental reboots). - + - + + + + + - + - diff --git a/OC Gen-X/MainVC.swift b/OC Gen-X/MainVC.swift index 37b59d4..09dc351 100644 --- a/OC Gen-X/MainVC.swift +++ b/OC Gen-X/MainVC.swift @@ -31,7 +31,7 @@ class MainVC: NSViewController { @IBOutlet weak var openUSBChecked: NSButton! @IBOutlet weak var nvmExpressChecked: NSButton! @IBOutlet weak var xhciChecked: NSButton! - @IBOutlet weak var textfield: NSTextField! + @IBOutlet weak var textfield: HyperlinkTextField! @IBOutlet weak var hfsPlusChecked: NSButton! @IBOutlet weak var snInput: NSTextField! @IBOutlet weak var mlbInput: NSTextField! @@ -56,6 +56,17 @@ class MainVC: NSViewController { override func viewDidLoad() { super.viewDidLoad() generateButton.isEnabled = false + applyDesktopGuideHyperlink() + } + + private func applyDesktopGuideHyperlink() { + // Keep it centered + let paragraphStyle = NSMutableParagraphStyle() + paragraphStyle.alignment = .center + let attributes: [NSAttributedString.Key: Any] = [.paragraphStyle : paragraphStyle, .font: textfield.font ?? NSFont.systemFontSize] + + guard let url = NSURL(string: "https://dortania.github.io/OpenCore-Desktop-Guide/") else { return } + textfield.setHyperlinkWithTitle(title: "https://dortania.github.io/OpenCore-Desktop-Guide/", URL: url, additionalAttributes: attributes) } @IBAction func systemTypeChecked(_ sender: NSButton) { diff --git a/OC Gen-X/Views/HyperlinkTextField.swift b/OC Gen-X/Views/HyperlinkTextField.swift new file mode 100644 index 0000000..0499491 --- /dev/null +++ b/OC Gen-X/Views/HyperlinkTextField.swift @@ -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 + /// + /// - 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) + } +} diff --git a/README.md b/README.md index 9b8bc4e..29fa22d 100644 --- a/README.md +++ b/README.md @@ -26,5 +26,6 @@ i.e: Haswell, Skylake, Coffeelake etc.. * *Acidanthera Development Team* for Opencore (This app is not endorsed or promoted by Acidanthera) * *Dortania Team* for the Opencore Guide. * *Hackintosh x86* for testing and logo's +* Minor contributions from *@StephenHeaps*