Skip to content
This repository has been archived by the owner on Nov 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #177 from wrutkowski/font-size
Browse files Browse the repository at this point in the history
Added font increase and decrease options into Editor menu
  • Loading branch information
orta committed Jan 13, 2016
2 parents 3fbddf8 + bffa25b commit 7522e91
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
11 changes: 11 additions & 0 deletions app/CocoaPods/Base.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,17 @@
<action selector="outdentSelection:" target="-1" id="Cdl-5c-U2X"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="dpD-lu-qYJ"/>
<menuItem title="Increase Font Size" keyEquivalent="+" id="kFl-4W-TiK">
<connections>
<action selector="increaseFontSize:" target="-1" id="aYI-IG-T1I"/>
</connections>
</menuItem>
<menuItem title="Decrease Font Size" keyEquivalent="-" id="MPg-RF-OWf">
<connections>
<action selector="decreaseFontSize:" target="-1" id="s2L-it-X5V"/>
</connections>
</menuItem>
</items>
</menu>
</menuItem>
Expand Down
36 changes: 34 additions & 2 deletions app/CocoaPods/CPFontAndColourGateKeeper.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import Cocoa

class CPFontAndColourGateKeeper: NSObject {
let defaultFont = NSFont(name: "Menlo", size: 16)


// MARK: - Colors

let cpBlack = NSColor(calibratedRed:0.180, green:0.000, blue:0.008, alpha:1.00)
let cpRed = NSColor(calibratedRed:0.682, green:0.000, blue:0.000, alpha:1.00)
let cpGreen = NSColor(calibratedRed:0.161, green:0.608, blue:0.086, alpha:1.00)
Expand All @@ -21,4 +22,35 @@ class CPFontAndColourGateKeeper: NSObject {
let cpBrightWhite = NSColor(calibratedRed:0.773, green:0.773, blue:0.773, alpha:1.00)
let cpBrightLightBrown = NSColor(calibratedRed: 232/255, green:226/255 , blue: 224/255, alpha: 1)
let cpBrightBrown = NSColor(calibratedRed: 209/255, green:196/255 , blue: 192/255, alpha: 1)

//MARK: - Font

private let kDefaultsDefaultFontSize = "defaultFontSize"
var defaultFont: NSFont? {
return NSFont(name: "Menlo", size: defaultFontSize)
}
private var defaultFontSize: CGFloat {
let defaults = NSUserDefaults.standardUserDefaults()
if let fontSize = defaults.objectForKey(kDefaultsDefaultFontSize) as? Float {
return CGFloat(fontSize)
}
return 16
}

func increaseDefaultFontSize() -> NSFont? {
let newSize = defaultFontSize + 1
return changeDefaultFontSize(newSize)
}

func decreaseDefaultFontSize() -> NSFont? {
let newSize = max(1, defaultFontSize - 1)
return changeDefaultFontSize(newSize)
}

private func changeDefaultFontSize(size: CGFloat) -> NSFont? {
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setFloat(Float(size), forKey: kDefaultsDefaultFontSize)
return defaultFont
}

}
12 changes: 12 additions & 0 deletions app/CocoaPods/CPPodfileEditorViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ class CPPodfileEditorViewController: NSViewController, NSTextViewDelegate {
let range = applyTextChange(outdentedSelection, toSelection: selectedLines(editor.textView))
editor.textView.setSelectedRange(range)
}

@IBAction func increaseFontSize(sender: NSMenuItem) {
let settings = CPFontAndColourGateKeeper()
settings.increaseDefaultFontSize()
editor.textFont = settings.defaultFont
}

@IBAction func decreaseFontSize(sender: NSMenuItem) {
let settings = CPFontAndColourGateKeeper()
settings.decreaseDefaultFontSize()
editor.textFont = settings.defaultFont
}

/// Apply a text transformation to a selection
///
Expand Down

0 comments on commit 7522e91

Please sign in to comment.