Skip to content

Commit b077ab1

Browse files
committed
Add opening urls
1 parent be2bedf commit b077ab1

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

HackerNews/Base.lproj/Main.storyboard

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,9 @@ Gw
13151315
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
13161316
<font key="font" metaFont="cellTitle"/>
13171317
</buttonCell>
1318+
<connections>
1319+
<action selector="openURL:" target="0A2-e5-fyj" id="GsW-Zy-yPi"/>
1320+
</connections>
13181321
</button>
13191322
</subviews>
13201323
<visibilityPriorities>
@@ -1590,6 +1593,9 @@ Gw
15901593
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
15911594
<font key="font" metaFont="cellTitle"/>
15921595
</buttonCell>
1596+
<connections>
1597+
<action selector="openURL:" target="bvi-xf-WO0" id="Ttq-gc-Nh4"/>
1598+
</connections>
15931599
</button>
15941600
</subviews>
15951601
<visibilityPriorities>

HackerNews/ItemList/ItemListCellView.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,22 @@ class ItemListCellView: NSTableCellView {
5353
}
5454
}
5555
}
56+
57+
@IBAction func openURL(_ sender: NSButton) {
58+
guard objectValue != nil else {
59+
return
60+
}
61+
let item = objectValue as! TopLevelItem
62+
63+
let url: URL
64+
switch item {
65+
case .story(let story):
66+
guard story.content.url != nil else { return }
67+
url = story.content.url!
68+
case .job(let job):
69+
guard job.content.url != nil else { return }
70+
url = job.content.url!
71+
}
72+
NSWorkspace.shared.open(url)
73+
}
5674
}

HackerNews/Page/ItemViewController.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,20 @@ class ItemViewController: NSViewController {
5454
}
5555
}
5656

57+
@IBAction func openURL(_ sender: NSButton) {
58+
let url: URL
59+
switch item {
60+
case .story(let story):
61+
guard story.content.url != nil else { return }
62+
url = story.content.url!
63+
case .job(let job):
64+
guard job.content.url != nil else { return }
65+
url = job.content.url!
66+
default: return
67+
}
68+
NSWorkspace.shared.open(url)
69+
}
70+
5771
override func viewDidLoad() {
5872
super.viewDidLoad()
5973
// Do view setup here.

0 commit comments

Comments
 (0)