Support increasing / decreasing text size

This commit is contained in:
Matt Baer 2017-07-29 15:15:22 -04:00
parent 48358f5a13
commit fd6b44ec73
4 changed files with 50 additions and 3 deletions

View File

@ -7,6 +7,7 @@
objects = { objects = {
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
33071D332D5799D36FBC1DDD /* Preferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3307150C0D2CA1C8A71C5E26 /* Preferences.swift */; };
C98EE9AC1F29532F002F646E /* writeas in Resources */ = {isa = PBXBuildFile; fileRef = C98EE9AB1F29532F002F646E /* writeas */; }; C98EE9AC1F29532F002F646E /* writeas in Resources */ = {isa = PBXBuildFile; fileRef = C98EE9AB1F29532F002F646E /* writeas */; };
C9953E7D1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf in Resources */ = {isa = PBXBuildFile; fileRef = C9953E791F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf */; }; C9953E7D1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf in Resources */ = {isa = PBXBuildFile; fileRef = C9953E791F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf */; };
C9953E7E1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = C9953E7A1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf */; }; C9953E7E1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = C9953E7A1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf */; };
@ -23,6 +24,7 @@
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
3307150C0D2CA1C8A71C5E26 /* Preferences.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Preferences.swift; path = writeas/Preferences.swift; sourceTree = "<group>"; };
C98EE9AB1F29532F002F646E /* writeas */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = writeas; sourceTree = "<group>"; }; C98EE9AB1F29532F002F646E /* writeas */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.executable"; path = writeas; sourceTree = "<group>"; };
C9953E791F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf"; sourceTree = "<group>"; }; C9953E791F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600.ttf"; sourceTree = "<group>"; };
C9953E7A1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf"; sourceTree = "<group>"; }; C9953E7A1F2D07A7008ED235 /* open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "open-sans-v14-cyrillic-ext_vietnamese_cyrillic_latin-ext_latin_greek-ext_greek-600italic.ttf"; sourceTree = "<group>"; };
@ -71,6 +73,7 @@
children = ( children = (
C99B910B1C33841E00A91990 /* writeas */, C99B910B1C33841E00A91990 /* writeas */,
C99B910A1C33841E00A91990 /* Products */, C99B910A1C33841E00A91990 /* Products */,
3307150C0D2CA1C8A71C5E26 /* Preferences.swift */,
); );
sourceTree = "<group>"; sourceTree = "<group>";
}; };
@ -180,6 +183,7 @@
files = ( files = (
C99B910F1C33841E00A91990 /* ViewController.swift in Sources */, C99B910F1C33841E00A91990 /* ViewController.swift in Sources */,
C99B910D1C33841E00A91990 /* AppDelegate.swift in Sources */, C99B910D1C33841E00A91990 /* AppDelegate.swift in Sources */,
33071D332D5799D36FBC1DDD /* Preferences.swift in Sources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View File

@ -244,6 +244,18 @@ DQ
<action selector="toggleNightMode:" target="Voe-Tx-rLC" id="Nmq-eG-y3w"/> <action selector="toggleNightMode:" target="Voe-Tx-rLC" id="Nmq-eG-y3w"/>
</connections> </connections>
</menuItem> </menuItem>
<menuItem isSeparatorItem="YES" id="ue7-Hl-EOO"/>
<menuItem title="Increase Text Size" keyEquivalent="+" id="BWd-kX-bJP">
<connections>
<action selector="viewIncTextSize:" target="Voe-Tx-rLC" id="Z3T-tc-ixm"/>
</connections>
</menuItem>
<menuItem title="Decrease Text Size" keyEquivalent="-" id="fGL-5w-dMs">
<connections>
<action selector="viewDecTextSize:" target="Voe-Tx-rLC" id="6K9-kj-cui"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="wad-VP-ov7"/>
</items> </items>
</menu> </menu>
</menuItem> </menuItem>

15
writeas/Preferences.swift Normal file
View File

@ -0,0 +1,15 @@
//
// Created by Matt Baer on 7/29/17.
// Copyright (c) 2017 A Bunch Tell. All rights reserved.
//
import Foundation
class Preferences {
class func getFontSize() -> CGFloat {
let size = Int(UserDefaults.standard.string(forKey: "editor_text_size") ?? "16") ?? 16
return CGFloat(size)
}
}

View File

@ -19,7 +19,7 @@ class ViewController: NSViewController, NSTextViewDelegate, NSUserNotificationCe
loadDocument() loadDocument()
writerText.font = NSFont(name: "Lora", size: 16) writerText.font = NSFont(name: "Lora", size: Preferences.getFontSize())
writerText.isHorizontallyResizable = false writerText.isHorizontallyResizable = false
writerText.textContainerInset = NSSize(width: 16, height: 16) writerText.textContainerInset = NSSize(width: 16, height: 16)
writerText.isAutomaticQuoteSubstitutionEnabled = false writerText.isAutomaticQuoteSubstitutionEnabled = false
@ -34,8 +34,7 @@ class ViewController: NSViewController, NSTextViewDelegate, NSUserNotificationCe
override func viewDidAppear() { override func viewDidAppear() {
super.viewDidAppear() super.viewDidAppear()
// Fit textview to window size configureWindow()
writerText.setFrameSize(NSSize(width: self.view.window!.frame.width, height: self.view.window!.frame.height))
// Style the window // Style the window
self.view.window!.title = "Write.as" self.view.window!.title = "Write.as"
@ -45,6 +44,11 @@ class ViewController: NSViewController, NSTextViewDelegate, NSUserNotificationCe
self.view.window!.backgroundColor = NSColor.white self.view.window!.backgroundColor = NSColor.white
} }
func configureWindow() {
// Fit textview to window size
writerText.setFrameSize(NSSize(width: self.view.window!.frame.width, height: self.view.window!.frame.height))
}
override var representedObject: Any? { override var representedObject: Any? {
didSet { didSet {
// Update the view, if already loaded. // Update the view, if already loaded.
@ -132,5 +136,17 @@ class ViewController: NSViewController, NSTextViewDelegate, NSUserNotificationCe
self.writerText.textColor = NSColor.black self.writerText.textColor = NSColor.black
} }
} }
func adjustTextSize(increment: Bool) {
var size = Preferences.getFontSize()
if increment {
size += 2
} else {
size -= 1
}
self.writerText.font = NSFont(name: "Lora", size: size)
UserDefaults.standard.set(String(Int(size)), forKey: "editor_text_size")
configureWindow()
}
} }