mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2024-12-20 22:34:10 +01:00
Add pref for timeline sorting direction.
This commit is contained in:
parent
19a46e9b20
commit
c2afd03d8c
@ -6,7 +6,7 @@
|
||||
// Copyright © 2017 Ranchero Software. All rights reserved.
|
||||
//
|
||||
|
||||
import Cocoa
|
||||
import AppKit
|
||||
|
||||
enum FontSize: Int {
|
||||
|
||||
@ -24,6 +24,7 @@ final class AppDefaults {
|
||||
static let firstRunDate = "firstRunDate"
|
||||
static let sidebarFontSize = "sidebarFontSize"
|
||||
static let timelineFontSize = "timelineFontSize"
|
||||
static let timelineSortDirection = "timelineSortDirection"
|
||||
static let detailFontSize = "detailFontSize"
|
||||
static let openInBrowserInBackground = "openInBrowserInBackground"
|
||||
|
||||
@ -76,6 +77,15 @@ final class AppDefaults {
|
||||
return bool(for: Key.showTitleOnMainWindow)
|
||||
}
|
||||
|
||||
var timelineSortDirection: ComparisonResult {
|
||||
get {
|
||||
return sortDirection(for: Key.timelineSortDirection)
|
||||
}
|
||||
set {
|
||||
setSortDirection(for: Key.timelineSortDirection, newValue)
|
||||
}
|
||||
}
|
||||
|
||||
private init() {
|
||||
|
||||
AppDefaults.registerDefaults()
|
||||
@ -118,7 +128,7 @@ private extension AppDefaults {
|
||||
|
||||
static func registerDefaults() {
|
||||
|
||||
let defaults = [Key.sidebarFontSize: FontSize.medium.rawValue, Key.timelineFontSize: FontSize.medium.rawValue, Key.detailFontSize: FontSize.medium.rawValue]
|
||||
let defaults = [Key.sidebarFontSize: FontSize.medium.rawValue, Key.timelineFontSize: FontSize.medium.rawValue, Key.detailFontSize: FontSize.medium.rawValue, Key.timelineSortDirection: ComparisonResult.orderedDescending.rawValue]
|
||||
|
||||
UserDefaults.standard.register(defaults: defaults)
|
||||
}
|
||||
@ -162,6 +172,25 @@ private extension AppDefaults {
|
||||
func setDate(for key: String, _ date: Date?) {
|
||||
UserDefaults.standard.set(date, forKey: key)
|
||||
}
|
||||
|
||||
func sortDirection(for key:String) -> ComparisonResult {
|
||||
|
||||
let rawInt = int(for: key)
|
||||
if rawInt == ComparisonResult.orderedAscending.rawValue {
|
||||
return .orderedAscending
|
||||
}
|
||||
return .orderedDescending
|
||||
}
|
||||
|
||||
func setSortDirection(for key: String, _ value: ComparisonResult) {
|
||||
|
||||
if value == .orderedAscending {
|
||||
setInt(for: key, ComparisonResult.orderedAscending.rawValue)
|
||||
}
|
||||
else {
|
||||
setInt(for: key, ComparisonResult.orderedDescending.rawValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user