Skip to content

Commit

Permalink
Add opening urls
Browse files Browse the repository at this point in the history
  • Loading branch information
goranmoomin committed Aug 25, 2020
1 parent be2bedf commit b077ab1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions HackerNews/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,9 @@ Gw
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="cellTitle"/>
</buttonCell>
<connections>
<action selector="openURL:" target="0A2-e5-fyj" id="GsW-Zy-yPi"/>
</connections>
</button>
</subviews>
<visibilityPriorities>
Expand Down Expand Up @@ -1590,6 +1593,9 @@ Gw
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
<font key="font" metaFont="cellTitle"/>
</buttonCell>
<connections>
<action selector="openURL:" target="bvi-xf-WO0" id="Ttq-gc-Nh4"/>
</connections>
</button>
</subviews>
<visibilityPriorities>
Expand Down
18 changes: 18 additions & 0 deletions HackerNews/ItemList/ItemListCellView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,22 @@ class ItemListCellView: NSTableCellView {
}
}
}

@IBAction func openURL(_ sender: NSButton) {
guard objectValue != nil else {
return
}
let item = objectValue as! TopLevelItem

let url: URL
switch item {
case .story(let story):
guard story.content.url != nil else { return }
url = story.content.url!
case .job(let job):
guard job.content.url != nil else { return }
url = job.content.url!
}
NSWorkspace.shared.open(url)
}
}
14 changes: 14 additions & 0 deletions HackerNews/Page/ItemViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ class ItemViewController: NSViewController {
}
}

@IBAction func openURL(_ sender: NSButton) {
let url: URL
switch item {
case .story(let story):
guard story.content.url != nil else { return }
url = story.content.url!
case .job(let job):
guard job.content.url != nil else { return }
url = job.content.url!
default: return
}
NSWorkspace.shared.open(url)
}

override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
Expand Down

0 comments on commit b077ab1

Please sign in to comment.