Skip to content

Commit

Permalink
Add noLinks label
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkfalcon committed May 22, 2018
1 parent fc8341e commit 1cf1da7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Peregrine/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
</customSpacing>
</stackView>
<scrollView focusRingType="none" horizontalHuggingPriority="249" verticalHuggingPriority="249" horizontalCompressionResistancePriority="749" verticalCompressionResistancePriority="749" placeholderIntrinsicWidth="320" placeholderIntrinsicHeight="180" verifyAmbiguity="off" borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" usesPredominantAxisScrolling="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ome-rW-50L">
<rect key="frame" x="0.0" y="80" width="320" height="180"/>
<rect key="frame" x="0.0" y="76" width="320" height="180"/>
<clipView key="contentView" focusRingType="none" copiesOnScroll="NO" id="qSO-ba-55L">
<rect key="frame" x="0.0" y="0.0" width="320" height="180"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down
3 changes: 2 additions & 1 deletion Peregrine/Data/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ struct Labels {
static let panel = "Choose a file"
static let notLoggedIn = "Please Log In First 😊"
static let gist = "Create Gist"
static let noText = "Write Anything 🖋"
static let noText = "Start Writing Above 🖋"
static let noLinks = "Gists will appear here 👻"
}

struct Errors {
Expand Down
1 change: 1 addition & 0 deletions Peregrine/ViewController/GistViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class GistViewController: NSViewController {

self.usernameButton.title = Labels.logIn
self.gistButton.title = Labels.notLoggedIn
// This is correct, it loads from default first
if self.loggedIn {
login()
}
Expand Down
12 changes: 12 additions & 0 deletions Peregrine/ViewController/TableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class TableViewController: NSViewController, NSTableViewDelegate, NSTableViewDat
@IBOutlet weak var scrollView: NSScrollView!

var links: [Link] = []
var noLinks: NSTextField!

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -22,6 +23,13 @@ class TableViewController: NSViewController, NSTableViewDelegate, NSTableViewDat
self.links = UserDefaults.standard.getList(key: UserDefaults.Key.links)
tableView.reloadData()

if self.links.count == 0 {
if #available(OSX 10.12, *) {
noLinks = NSTextField(labelWithAttributedString: NSAttributedString.create(color: .white, size: 20, title: Labels.noLinks, alignment: .center))
self.view.addSubview(noLinks)
}
}

NotificationCenter.default.addObserver(self, selector: #selector(self.addTableViewItem(_:)), name: .AddItem, object: nil)
}

Expand Down Expand Up @@ -65,6 +73,10 @@ class TableViewController: NSViewController, NSTableViewDelegate, NSTableViewDat
self.links = UserDefaults.standard.getList(key: UserDefaults.Key.links)
tableView.reloadData()
tableView.scrollRowToVisible(0)
if self.links.count > 0 && noLinks != nil {
self.noLinks.removeFromSuperview()
self.noLinks = nil
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
self.tableView.rowView(atRow: 0, makeIfNecessary: false)?.isSelected = true
}
Expand Down

0 comments on commit 1cf1da7

Please sign in to comment.