Sources/Orgstar/Preferences.swift
61 lines · 2932 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 #if APPSTORE
10 /// The folder chosen with Choose Configuration Folder…, used before anything reads the
11 /// configuration.
12 private static let chosenConfigFolder: Void = { UserConfig.directoryOverride = ConfigFolder.resolve() }()
13 #endif
14
15 /// TODO keywords for files without `#+TODO`, read at launch.
16 @MainActor
17 static var orgSettings: OrgSettings {
18 #if APPSTORE
19 _ = chosenConfigFolder
20 #endif
21 // config.toml applies before anything reads settings.
22 ConfigSync.shared.start()
23 return OrgPreferences.orgSettings()
24 }
25
26 static func options(
27 tagsColumn: Int, headingAfterSubtree: Bool, splitLine: Bool, alphabeticalLists: Bool, fillColumn: Int,
28 hiddenMarkers: Bool, prettyEntities: Bool, logDone: String, logIntoDrawer: String,
29 hideDrawerStartup: Bool, hideBlockStartup: Bool, logReschedule: String, logRedeadline: String, useSpeedCommands: Bool, startupWithInlineImages: Bool,
30 startupIndented: Bool, hideLeadingStars: Bool, startupAlignAllTables: Bool, startupTruncated: Bool, spellCheck: Bool, electricPair: Bool,
31 enforceTodoDependencies: Bool, enforceTodoCheckboxDependencies: Bool
32 ) -> EditingOptions {
33 // The settings only config.toml has, under those the Settings window binds.
34 var options = OrgPreferences.options()
35 options.tagsColumn = tagsColumn
36 options.insertHeadingRespectContent = headingAfterSubtree
37 options.metaReturnMaySplitLine = splitLine
38 options.listAllowAlphabetical = alphabeticalLists
39 options.fillColumn = fillColumn
40 options.hideEmphasisMarkers = hiddenMarkers
41 options.prettyEntities = prettyEntities
42 options.subSuperscriptsNeedBraces = true
43 options.logDone = LogHow(rawValue: logDone)
44 options.logIntoDrawer = logIntoDrawer.isEmpty ? nil : logIntoDrawer
45 options.hideDrawerStartup = hideDrawerStartup
46 options.hideBlockStartup = hideBlockStartup
47 options.logReschedule = LogHow(rawValue: logReschedule)
48 options.logRedeadline = LogHow(rawValue: logRedeadline)
49 options.useSpeedCommands = useSpeedCommands
50 options.startupWithInlineImages = startupWithInlineImages
51 options.startupIndented = startupIndented
52 options.hideLeadingStars = hideLeadingStars
53 options.startupAlignAllTables = startupAlignAllTables
54 options.startupTruncated = startupTruncated
55 options.spellCheck = spellCheck
56 options.electricPair = electricPair
57 options.enforceTodoDependencies = enforceTodoDependencies
58 options.enforceTodoCheckboxDependencies = enforceTodoCheckboxDependencies
59 return options
60 }
61}