Skip to content

Commit

Permalink
✨ add custom about window
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardodino committed Jul 13, 2022
1 parent 36e17a7 commit c406989
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
4 changes: 4 additions & 0 deletions SilkScreen.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
961CD236287F733400E4110B /* AboutWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 961CD235287F733400E4110B /* AboutWindow.swift */; };
964B527D2847DAF9005FB0CF /* BaseImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 964B527C2847DAF9005FB0CF /* BaseImageView.swift */; };
964B527F2847DB84005FB0CF /* BaseDragDropView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 964B527E2847DB84005FB0CF /* BaseDragDropView.swift */; };
964B52812847DBFC005FB0CF /* GPWelcomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 964B52802847DBFC005FB0CF /* GPWelcomeView.swift */; };
Expand All @@ -22,6 +23,7 @@
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
961CD235287F733400E4110B /* AboutWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutWindow.swift; sourceTree = "<group>"; };
964B527C2847DAF9005FB0CF /* BaseImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseImageView.swift; sourceTree = "<group>"; };
964B527E2847DB84005FB0CF /* BaseDragDropView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseDragDropView.swift; sourceTree = "<group>"; };
964B52802847DBFC005FB0CF /* GPWelcomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GPWelcomeView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -93,6 +95,7 @@
96B72438283D978E00F149DF /* WindowController.swift */,
96B4DAB9282F2C80005C0792 /* Document.swift */,
96B72436283D976600F149DF /* Window.swift */,
961CD235287F733400E4110B /* AboutWindow.swift */,
965B9EAF2841687B006FBA63 /* Extensions.swift */,
96B4DABD282F2C81005C0792 /* Main.storyboard */,
);
Expand Down Expand Up @@ -203,6 +206,7 @@
96B72439283D978E00F149DF /* WindowController.swift in Sources */,
96B4DAB6282F2C80005C0792 /* AppDelegate.swift in Sources */,
96B4DABA282F2C80005C0792 /* Document.swift in Sources */,
961CD236287F733400E4110B /* AboutWindow.swift in Sources */,
964B52832847DC26005FB0CF /* GPImageView.swift in Sources */,
965B9EB02841687B006FBA63 /* Extensions.swift in Sources */,
964B527F2847DB84005FB0CF /* BaseDragDropView.swift in Sources */,
Expand Down
53 changes: 53 additions & 0 deletions Sources/AboutWindow.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import Cocoa

fileprivate func BasicLink(
text: String,
href: String,
font: NSFont
) -> NSAttributedString {
return NSAttributedString(
string: text,
attributes: [
.font: font,
.link: NSURL(string: href) ?? "",
.toolTip: href,
.underlineColor: NSColor.clear,
]
)
}

fileprivate func join(_ parts: [NSAttributedString]) -> NSMutableAttributedString {
let joinedString = NSMutableAttributedString(string: "")
parts.forEach{ joinedString.append($0) }
return joinedString
}

extension NSApplication.AboutPanelOptionKey {
static let copyright = NSApplication.AboutPanelOptionKey(rawValue: "Copyright")
}

class AboutWindow {
static let shared = AboutWindow()
@objc func show() {
NSApp.orderFrontStandardAboutPanel(options: [
.copyright: "",
.credits: join([
BasicLink(
text: "Source Code",
href: "https://github.com/leonardodino/SilkScreen",
font: NSFont.systemFont(ofSize: 12, weight: .medium)
),
NSAttributedString(
string: "\n\n",
attributes: [.font: NSFont.systemFont(ofSize: 6)]
),
BasicLink(
text: "Leonardo Dino",
href: "https://leonardodino.com/",
font: NSFont.systemFont(ofSize: 10)
),
]),
])
NSApp.activate(ignoringOtherApps: true)
}
}
3 changes: 3 additions & 0 deletions Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ final class AppDelegate: NSObject, NSApplicationDelegate {
return true
}

@IBAction func showAbout(_ sender: Any?) {
AboutWindow.shared.show()
}
@IBAction func showHelp(_ sender: Any?) {
if let url = URL(string: "https://github.com/leonardodino/SilkScreen") {
NSWorkspace.shared.open(url)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<menuItem title="About SilkScreen" id="5kV-Vb-QxS">
<modifierMask key="keyEquivalentModifierMask"/>
<connections>
<action selector="orderFrontStandardAboutPanel:" target="Ady-hI-5gd" id="Exp-CZ-Vem"/>
<action selector="showAbout:" target="Voe-Tx-rLC" id="9Ex-pP-za5"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
Expand Down

0 comments on commit c406989

Please sign in to comment.