Sources/Orgstar/Preferences.swift

d85099bc95bf1766aee990d94671dacda0c0686e
orgstar/Sources/Orgstar/Preferences.swift history · blame · raw

52 lines · 2609 bytes

 1import Foundation
 2import OrgApp
 3import OrgCore
 4
 5/// Org preferences, stored in user defaults by the Settings window.
 6enum Preferences {
 7    static let defaultTodoKeywords = OrgPreferences.defaultTodoKeywords
 8
 9    /// TODO keywords for files without `#+TODO`, read at launch.
10    @MainActor
11    static var orgSettings: OrgSettings {
12        // config.toml applies before anything reads settings.
13        ConfigSync.shared.start()
14        return OrgPreferences.orgSettings()
15    }
16
17    static func options(
18        tagsColumn: Int, headingAfterSubtree: Bool, splitLine: Bool, alphabeticalLists: Bool, fillColumn: Int,
19        hiddenMarkers: Bool, prettyEntities: Bool, logDone: String, logIntoDrawer: String,
20        hideDrawerStartup: Bool, hideBlockStartup: Bool, logReschedule: String, logRedeadline: String, useSpeedCommands: Bool, startupWithInlineImages: Bool,
21        startupIndented: Bool, hideLeadingStars: Bool, startupAlignAllTables: Bool, startupTruncated: Bool, spellCheck: Bool, electricPair: Bool,
22        enforceTodoDependencies: Bool, enforceTodoCheckboxDependencies: Bool
23    ) -> EditingOptions {
24        // The settings only config.toml has, under those the Settings window binds.
25        var options = OrgPreferences.options()
26        options.tagsColumn = tagsColumn
27        options.insertHeadingRespectContent = headingAfterSubtree
28        options.metaReturnMaySplitLine = splitLine
29        options.listAllowAlphabetical = alphabeticalLists
30        options.fillColumn = fillColumn
31        options.hideEmphasisMarkers = hiddenMarkers
32        options.prettyEntities = prettyEntities
33        options.subSuperscriptsNeedBraces = true
34        options.logDone = LogHow(rawValue: logDone)
35        options.logIntoDrawer = logIntoDrawer.isEmpty ? nil : logIntoDrawer
36        options.hideDrawerStartup = hideDrawerStartup
37        options.hideBlockStartup = hideBlockStartup
38        options.logReschedule = LogHow(rawValue: logReschedule)
39        options.logRedeadline = LogHow(rawValue: logRedeadline)
40        options.useSpeedCommands = useSpeedCommands
41        options.startupWithInlineImages = startupWithInlineImages
42        options.startupIndented = startupIndented
43        options.hideLeadingStars = hideLeadingStars
44        options.startupAlignAllTables = startupAlignAllTables
45        options.startupTruncated = startupTruncated
46        options.spellCheck = spellCheck
47        options.electricPair = electricPair
48        options.enforceTodoDependencies = enforceTodoDependencies
49        options.enforceTodoCheckboxDependencies = enforceTodoCheckboxDependencies
50        return options
51    }
52}