Skip to content

Commit

Permalink
Added preferences to show editor on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
lukakerr committed Sep 30, 2019
1 parent 7822b80 commit 5170b42
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[Unreleased]
### New Features
- Added preference to show editor on startup

### Fixes

Expand Down
19 changes: 15 additions & 4 deletions Pine/Controllers/MarkdownViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ class MarkdownViewController: NSViewController, NSTextViewDelegate, HighlightDel
return parent as? NSSplitViewController
}

/// The split view controllers editor item
private var editorSplitViewItem: NSSplitViewItem? {
return splitViewController?.splitViewItems.first
}

/// The split view controllers preview item
private var previewSplitViewItem: NSSplitViewItem? {
return splitViewController?.splitViewItems.last
}

/// The preview view controller for this markdown view controller
private var previewViewController: PreviewViewController? {
return splitViewController?.splitViewItems.last?.viewController as? PreviewViewController
Expand Down Expand Up @@ -74,10 +84,6 @@ class MarkdownViewController: NSViewController, NSTextViewDelegate, HighlightDel
self.generatePreview()
}

if let preview = splitViewController?.splitViewItems.last {
preview.isCollapsed = !preferences[.showPreviewOnStartup]
}

self.setupTextStorage()
self.setupScrollView()
self.setupLayoutManager()
Expand All @@ -92,6 +98,11 @@ class MarkdownViewController: NSViewController, NSTextViewDelegate, HighlightDel
view.addSubview(scrollView)
}

override func viewWillAppear() {
previewSplitViewItem?.isCollapsed = !preferences[.showPreviewOnStartup]
editorSplitViewItem?.isCollapsed = !preferences[.showEditorOnStartup]
}

// MARK: - Private functions for updating and setting view components

private func setupTextStorage() {
Expand Down
3 changes: 2 additions & 1 deletion Pine/Models/Preferences/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import Cocoa
import cmark_gfm_swift

extension PreferenceKeys {
static let showPreviewOnStartup = PreferenceKey<Bool>("showPreviewOnStartup", defaultValue: true)
static let autosaveDocument = PreferenceKey<Bool>("autosaveDocument", defaultValue: true)
static let verticalSplitView = PreferenceKey<Bool>("verticalSplitView", defaultValue: true)
static let modernTitlebar = PreferenceKey<Bool>("modernTitlebar", defaultValue: true)
static let useSystemAppearance = PreferenceKey<Bool>("useSystemAppearance", defaultValue: false)
static let showSidebar = PreferenceKey<Bool>("showSidebar", defaultValue: true)
static let showEditorOnStartup = PreferenceKey<Bool>("showEditorOnStartup", defaultValue: true)
static let showPreviewOnStartup = PreferenceKey<Bool>("showPreviewOnStartup", defaultValue: true)
static let spellcheckEnabled = PreferenceKey<Bool>("spellcheckEnabled", defaultValue: false)
static let autoPairSyntax = PreferenceKey<Bool>("autoPairSyntax", defaultValue: true)
static let useThemeColorForSidebar = PreferenceKey<Bool>("useThemeColorForSidebar", defaultValue: true)
Expand Down
1 change: 1 addition & 0 deletions Pine/Views/Preferences/GeneralStackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Cocoa
class GeneralStackView: NSStackView, PreferenceStackView {

private let behaviorMap: BoolPreferenceMap = [
"Show editor on startup": .showEditorOnStartup,
"Show preview on startup": .showPreviewOnStartup,
"Open new document on startup": .openNewDocumentOnStartup,
"Terminate after last window closed": .terminateAfterLastWindowClosed
Expand Down

0 comments on commit 5170b42

Please sign in to comment.