Commit 0e0e407283
Verified · cmc
Layout: unified · split
Sources/OrgApp/CalendarEvents.swift +105
| @@ -84,3 +84,108 @@ public final class CalendarEvents: @unchecked Sendable { | |||
| 84 | return RGBA(red: Double(c[0]), green: Double(c[1]), blue: Double(c[2]), alpha: Double(converted.alpha)) | 84 | return RGBA(red: Double(c[0]), green: Double(c[1]), blue: Double(c[2]), alpha: Double(converted.alpha)) |
| 85 | } | 85 | } |
| 86 | } | 86 | } |
| 87 | |||
| 88 | /// An event's fields while it is edited or made. | ||
| 89 | public struct EventDraft: Sendable, Equatable { | ||
| 90 | public var title: String | ||
| 91 | public var start: Date | ||
| 92 | public var end: Date | ||
| 93 | public var isAllDay: Bool | ||
| 94 | public var location: String | ||
| 95 | /// The calendar it goes in; empty for the default calendar for new events. | ||
| 96 | public var calendarID: String | ||
| 97 | |||
| 98 | public init(title: String, start: Date, end: Date, isAllDay: Bool, location: String = "", calendarID: String = "") { | ||
| 99 | self.title = title | ||
| 100 | self.start = start | ||
| 101 | self.end = end | ||
| 102 | self.isAllDay = isAllDay | ||
| 103 | self.location = location | ||
| 104 | self.calendarID = calendarID | ||
| 105 | } | ||
| 106 | |||
| 107 | public init(_ event: AgendaEvent) { | ||
| 108 | self.init(title: event.title, start: event.start, end: event.end, isAllDay: event.isAllDay, | ||
| 109 | location: event.location ?? "", calendarID: event.calendarID) | ||
| 110 | } | ||
| 111 | |||
| 112 | /// An agenda entry on `day` as an event: at its time (`start` and `end` as `hhmm`), an | ||
| 113 | /// hour long when it has no end, or all day without a time. An all-day event's dates are | ||
| 114 | /// its first and last day. | ||
| 115 | public static func entry(_ title: String, day: Int, start: Int?, end: Int?, calendar: Calendar = .current) -> EventDraft { | ||
| 116 | let d = Days.date(day) | ||
| 117 | let midnight = calendar.date(from: DateComponents(year: d.year, month: d.month, day: d.day)) ?? Date() | ||
| 118 | guard let start else { | ||
| 119 | return EventDraft(title: title, start: midnight, end: midnight, isAllDay: true) | ||
| 120 | } | ||
| 121 | func at(_ hhmm: Int) -> Date { calendar.date(bySettingHour: hhmm / 100, minute: hhmm % 100, second: 0, of: midnight) ?? midnight } | ||
| 122 | let from = at(start) | ||
| 123 | var to = end.map(at) ?? from.addingTimeInterval(3600) | ||
| 124 | if to <= from { to = from.addingTimeInterval(3600) } | ||
| 125 | return EventDraft(title: title, start: from, end: to, isAllDay: false) | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 129 | extension CalendarEvents { | ||
| 130 | /// The calendars events can be added to or changed in. | ||
| 131 | public func writableCalendars() -> [(id: String, title: String, color: RGBA?)] { | ||
| 132 | guard Self.isAuthorized else { return [] } | ||
| 133 | return store.calendars(for: .event).filter(\.allowsContentModifications) | ||
| 134 | .map { ($0.calendarIdentifier, $0.title, $0.cgColor.flatMap(Self.rgba)) } | ||
| 135 | } | ||
| 136 | |||
| 137 | /// The calendar new events go in. | ||
| 138 | public var defaultCalendarID: String { store.defaultCalendarForNewEvents?.calendarIdentifier ?? "" } | ||
| 139 | |||
| 140 | public enum SaveError: Error, CustomStringConvertible { | ||
| 141 | case noAccess, gone, noCalendar, failed(String) | ||
| 142 | |||
| 143 | public var description: String { | ||
| 144 | switch self { | ||
| 145 | case .noAccess: "orgstar may not change your calendars." | ||
| 146 | case .gone: "The event is no longer in Calendar." | ||
| 147 | case .noCalendar: "Choose a calendar." | ||
| 148 | case .failed(let message): message | ||
| 149 | } | ||
| 150 | } | ||
| 151 | } | ||
| 152 | |||
| 153 | /// Writes `draft` into the event `replacing` (only that occurrence of a repeating event), or | ||
| 154 | /// as a new event. Returns the event's agenda identifier. | ||
| 155 | @discardableResult | ||
| 156 | public func save(_ draft: EventDraft, replacing event: AgendaEvent? = nil) throws -> String { | ||
| 157 | guard Self.isAuthorized else { throw SaveError.noAccess } | ||
| 158 | let target: EKEvent | ||
| 159 | if let event { | ||
| 160 | let predicate = store.predicateForEvents(withStart: event.start.addingTimeInterval(-1), end: event.end.addingTimeInterval(1), calendars: nil) | ||
| 161 | guard let found = store.events(matching: predicate).first(where: { $0.recordID == event.id }) else { throw SaveError.gone } | ||
| 162 | target = found | ||
| 163 | } else { | ||
| 164 | target = EKEvent(eventStore: store) | ||
| 165 | } | ||
| 166 | let calendarID = draft.calendarID.isEmpty ? defaultCalendarID : draft.calendarID | ||
| 167 | guard let calendar = store.calendar(withIdentifier: calendarID) else { throw SaveError.noCalendar } | ||
| 168 | target.calendar = calendar | ||
| 169 | target.title = draft.title | ||
| 170 | target.isAllDay = draft.isAllDay | ||
| 171 | // EventKit takes an all-day event's days from the dates. | ||
| 172 | target.startDate = draft.isAllDay ? Calendar.current.startOfDay(for: draft.start) : draft.start | ||
| 173 | target.endDate = max(draft.isAllDay ? Calendar.current.startOfDay(for: draft.end) : draft.end, target.startDate) | ||
| 174 | target.location = draft.location.isEmpty ? nil : draft.location | ||
| 175 | do { | ||
| 176 | try store.save(target, span: .thisEvent, commit: true) | ||
| 177 | } catch { | ||
| 178 | throw SaveError.failed(error.localizedDescription) | ||
| 179 | } | ||
| 180 | return target.recordID | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | extension CalendarEvents { | ||
| 185 | /// Whether the event repeats, so that a change applies to one occurrence. | ||
| 186 | public func isRepeating(_ event: AgendaEvent) -> Bool { | ||
| 187 | guard Self.isAuthorized else { return false } | ||
| 188 | let predicate = store.predicateForEvents(withStart: event.start.addingTimeInterval(-1), end: event.end.addingTimeInterval(1), calendars: nil) | ||
| 189 | return store.events(matching: predicate).first { $0.recordID == event.id }?.hasRecurrenceRules ?? false | ||
| 190 | } | ||
| 191 | } | ||
Sources/OrgApp/EventSheet.swift added +92
| @@ -0,0 +1,92 @@ | |||
| 1 | import Foundation | ||
| 2 | import OrgPresentation | ||
| 3 | import SwiftUI | ||
| 4 | |||
| 5 | /// What the event sheet does: change an event from the agenda, or add an entry to a calendar. | ||
| 6 | public struct EventRequest: Identifiable { | ||
| 7 | public let id = UUID() | ||
| 8 | public let draft: EventDraft | ||
| 9 | /// The event changed; nil adds a new one. | ||
| 10 | public let event: AgendaEvent? | ||
| 11 | |||
| 12 | public init(draft: EventDraft, event: AgendaEvent? = nil) { | ||
| 13 | self.draft = draft | ||
| 14 | self.event = event | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | /// An event's title, times, location and calendar, saved to Calendar. `done` closes the sheet | ||
| 19 | /// with a message, nil when cancelled. | ||
| 20 | public struct EventSheet: View { | ||
| 21 | let request: EventRequest | ||
| 22 | let events: CalendarEvents | ||
| 23 | let done: (String?) -> Void | ||
| 24 | @State private var draft: EventDraft | ||
| 25 | @State private var calendars: [(id: String, title: String, color: RGBA?)] = [] | ||
| 26 | @State private var problem: String? | ||
| 27 | |||
| 28 | public init(request: EventRequest, events: CalendarEvents, done: @escaping (String?) -> Void) { | ||
| 29 | self.request = request | ||
| 30 | self.events = events | ||
| 31 | self.done = done | ||
| 32 | _draft = State(initialValue: request.draft) | ||
| 33 | } | ||
| 34 | |||
| 35 | public var body: some View { | ||
| 36 | VStack(alignment: .leading, spacing: 0) { | ||
| 37 | Form { | ||
| 38 | TextField("Title", text: $draft.title) | ||
| 39 | Toggle("All day", isOn: $draft.isAllDay) | ||
| 40 | DatePicker("Starts", selection: $draft.start, displayedComponents: draft.isAllDay ? [.date] : [.date, .hourAndMinute]) | ||
| 41 | DatePicker("Ends", selection: $draft.end, in: draft.start..., displayedComponents: draft.isAllDay ? [.date] : [.date, .hourAndMinute]) | ||
| 42 | TextField("Location", text: $draft.location) | ||
| 43 | Picker("Calendar", selection: $draft.calendarID) { | ||
| 44 | ForEach(calendars, id: \.id) { calendar in Text(calendar.title).tag(calendar.id) } | ||
| 45 | } | ||
| 46 | if request.event != nil, events.isRepeating(request.event!) { | ||
| 47 | Text("Changes apply to this occurrence only.").font(.caption).foregroundStyle(.secondary) | ||
| 48 | } | ||
| 49 | if let problem { Text(problem).foregroundStyle(.red) } | ||
| 50 | } | ||
| 51 | .formStyle(.grouped) | ||
| 52 | #if os(macOS) | ||
| 53 | HStack { | ||
| 54 | Spacer() | ||
| 55 | Button("Cancel", role: .cancel) { done(nil) }.keyboardShortcut(.cancelAction) | ||
| 56 | Button(request.event == nil ? "Add" : "Save") { save() } | ||
| 57 | .keyboardShortcut(.defaultAction) | ||
| 58 | .disabled(!canSave) | ||
| 59 | } | ||
| 60 | .padding(12) | ||
| 61 | #endif | ||
| 62 | } | ||
| 63 | #if os(macOS) | ||
| 64 | .frame(minWidth: 420) | ||
| 65 | #else | ||
| 66 | .toolbar { | ||
| 67 | ToolbarItem(placement: .cancellationAction) { Button("Cancel", role: .cancel) { done(nil) } } | ||
| 68 | ToolbarItem(placement: .confirmationAction) { Button(request.event == nil ? "Add" : "Save") { save() }.disabled(!canSave) } | ||
| 69 | } | ||
| 70 | #endif | ||
| 71 | .task { | ||
| 72 | _ = await events.requestAccess() | ||
| 73 | calendars = events.writableCalendars() | ||
| 74 | if !calendars.contains(where: { $0.id == draft.calendarID }) { | ||
| 75 | draft.calendarID = calendars.first { $0.id == events.defaultCalendarID }?.id ?? calendars.first?.id ?? "" | ||
| 76 | } | ||
| 77 | if calendars.isEmpty { problem = CalendarEvents.isAuthorized ? "No calendar can be changed." : CalendarEvents.SaveError.noAccess.description } | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | private var canSave: Bool { !draft.title.trimmingCharacters(in: .whitespaces).isEmpty && !draft.calendarID.isEmpty } | ||
| 82 | |||
| 83 | private func save() { | ||
| 84 | do { | ||
| 85 | try events.save(draft, replacing: request.event) | ||
| 86 | let name = calendars.first { $0.id == draft.calendarID }?.title ?? "Calendar" | ||
| 87 | done(request.event == nil ? "Added to \(name)." : "Saved.") | ||
| 88 | } catch { | ||
| 89 | problem = "\(error)" | ||
| 90 | } | ||
| 91 | } | ||
| 92 | } | ||
Sources/OrgApp/UserConfig.swift +1 −1
| @@ -315,7 +315,7 @@ public enum UserConfig { | |||
| 315 | Setting(section: "orgstar", key: "reminders", defaultsKey: "reminders", kind: .bool, fallback: .bool(true), | 315 | Setting(section: "orgstar", key: "reminders", defaultsKey: "reminders", kind: .bool, fallback: .bool(true), |
| 316 | comment: "notify before timed entries", legacy: "agenda.reminders"), | 316 | comment: "notify before timed entries", legacy: "agenda.reminders"), |
| 317 | Setting(section: "orgstar", key: "calendar-events", defaultsKey: "calendarEvents", kind: .bool, fallback: .bool(false), | 317 | Setting(section: "orgstar", key: "calendar-events", defaultsKey: "calendarEvents", kind: .bool, fallback: .bool(false), |
| 318 | comment: "show events from Calendar in the agenda, read-only", legacy: ""), | 318 | comment: "show events from Calendar in the agenda", legacy: ""), |
| 319 | Setting(section: "orgstar", key: "calendar-event-calendars", defaultsKey: "calendarEventCalendars", kind: .string, fallback: .string(""), | 319 | Setting(section: "orgstar", key: "calendar-event-calendars", defaultsKey: "calendarEventCalendars", kind: .string, fallback: .string(""), |
| 320 | comment: "the calendars whose events show, by title or identifier, separated by commas; \"\" for all", legacy: ""), | 320 | comment: "the calendars whose events show, by title or identifier, separated by commas; \"\" for all", legacy: ""), |
| 321 | Setting(section: "orgstar", key: "agenda-reminders", defaultsKey: "agendaReminders", kind: .bool, fallback: .bool(false), | 321 | Setting(section: "orgstar", key: "agenda-reminders", defaultsKey: "agendaReminders", kind: .bool, fallback: .bool(false), |
Sources/Orgstar/AgendaView.swift +18
| @@ -45,6 +45,8 @@ struct AgendaView: View { | |||
| 45 | @State var keepRequestedDays = false | 45 | @State var keepRequestedDays = false |
| 46 | @State var message: String? | 46 | @State var message: String? |
| 47 | @State var prompt: PendingPrompt? | 47 | @State var prompt: PendingPrompt? |
| 48 | /// An event being changed, or an entry being added to a calendar. | ||
| 49 | @State private var eventRequest: EventRequest? | ||
| 48 | @State var promptText = "" | 50 | @State var promptText = "" |
| 49 | @State var prefix: String? | 51 | @State var prefix: String? |
| 50 | /// Entries marked for a bulk action. | 52 | /// Entries marked for a bulk action. |
| @@ -337,6 +339,15 @@ struct AgendaView: View { | |||
| 337 | ContentUnavailableView("No agenda files", systemImage: "calendar", description: Text("The agenda reads the org files at the top of each folder you add.")) | 339 | ContentUnavailableView("No agenda files", systemImage: "calendar", description: Text("The agenda reads the org files at the top of each folder you add.")) |
| 338 | } | 340 | } |
| 339 | } | 341 | } |
| 342 | .sheet(item: $eventRequest) { request in | ||
| 343 | EventSheet(request: request, events: CalendarAccess.events) { result in | ||
| 344 | eventRequest = nil | ||
| 345 | if let result { | ||
| 346 | message = result | ||
| 347 | tick += 1 | ||
| 348 | } | ||
| 349 | } | ||
| 350 | } | ||
| 340 | .sheet(item: Binding(get: { prompt?.prompt.fast == nil ? nil : prompt }, set: { if $0 == nil { prompt = nil } })) { pending in | 351 | .sheet(item: Binding(get: { prompt?.prompt.fast == nil ? nil : prompt }, set: { if $0 == nil { prompt = nil } })) { pending in |
| 341 | if let fast = pending.prompt.fast { | 352 | if let fast = pending.prompt.fast { |
| 342 | FastSelectionView(selection: fast, message: pending.prompt.message) { answer in | 353 | FastSelectionView(selection: fast, message: pending.prompt.message) { answer in |
| @@ -546,6 +557,9 @@ struct AgendaView: View { | |||
| 546 | private func menu(_ line: Line) -> some View { | 557 | private func menu(_ line: Line) -> some View { |
| 547 | if let event = line.row.event { | 558 | if let event = line.row.event { |
| 548 | Button(event.isReminder ? "Show in Reminders" : "Show in Calendar") { openEvent(event) } | 559 | Button(event.isReminder ? "Show in Reminders" : "Show in Calendar") { openEvent(event) } |
| 560 | if !event.isReminder { | ||
| 561 | Button("Edit Event…") { eventRequest = EventRequest(draft: EventDraft(event), event: event) } | ||
| 562 | } | ||
| 549 | } else if line.row.item != nil { | 563 | } else if line.row.item != nil { |
| 550 | Button("Open") { selection = line.id; jump(line.id) } | 564 | Button("Open") { selection = line.id; jump(line.id) } |
| 551 | Divider() | 565 | Divider() |
| @@ -555,6 +569,10 @@ struct AgendaView: View { | |||
| 555 | Button("Schedule…") { selection = line.id; run(SetPlanning(deadline: false)) } | 569 | Button("Schedule…") { selection = line.id; run(SetPlanning(deadline: false)) } |
| 556 | Button("Set Deadline…") { selection = line.id; run(SetPlanning(deadline: true)) } | 570 | Button("Set Deadline…") { selection = line.id; run(SetPlanning(deadline: true)) } |
| 557 | Divider() | 571 | Divider() |
| 572 | Button("Add to Calendar…") { | ||
| 573 | eventRequest = EventRequest(draft: .entry(line.row.title, day: line.day, start: line.row.start, end: line.row.end)) | ||
| 574 | } | ||
| 575 | Divider() | ||
| 558 | Button("Clock In") { selection = line.id; clockIn() } | 576 | Button("Clock In") { selection = line.id; clockIn() } |
| 559 | Button(EntryRef(line.row.item!).map(marked.contains) == true ? "Unmark" : "Mark") { | 577 | Button(EntryRef(line.row.item!).map(marked.contains) == true ? "Unmark" : "Mark") { |
| 560 | selection = line.id | 578 | selection = line.id |
Sources/Orgstar/OrgstarApp.swift +1 −1
| @@ -779,7 +779,7 @@ struct SettingsView: View { | |||
| 779 | } | 779 | } |
| 780 | } | 780 | } |
| 781 | } footer: { | 781 | } footer: { |
| 782 | Text("Events show in the agenda read-only; double-click one to open it in Calendar. New calendars show while every calendar is checked.") | 782 | Text("Events show in the agenda; double-click one to open it in Calendar, or choose Edit Event… in its context menu. New calendars show while every calendar is checked.") |
| 783 | .settingsFooter() | 783 | .settingsFooter() |
| 784 | } | 784 | } |
| 785 | .task(id: calendarEvents) { | 785 | .task(id: calendarEvents) { |
Sources/OrgstarMobile/AgendaScreen.swift +31 −3
| @@ -28,6 +28,8 @@ struct AgendaScreen: View, Equatable { | |||
| 28 | @State private var asking: Asking? | 28 | @State private var asking: Asking? |
| 29 | @State private var prompt: EditorScreen.PromptRequest? | 29 | @State private var prompt: EditorScreen.PromptRequest? |
| 30 | @State private var refiling: AgendaItem? | 30 | @State private var refiling: AgendaItem? |
| 31 | /// An event being changed, or an entry being added to a calendar. | ||
| 32 | @State private var eventRequest: EventRequest? | ||
| 31 | @State private var archiving: AgendaItem? | 33 | @State private var archiving: AgendaItem? |
| 32 | @State private var deleting: AgendaItem? | 34 | @State private var deleting: AgendaItem? |
| 33 | /// The day, week or month shown; nil for `org-agenda-span` and `org-agenda-start-day`. | 35 | /// The day, week or month shown; nil for `org-agenda-span` and `org-agenda-start-day`. |
| @@ -252,6 +254,19 @@ struct AgendaScreen: View, Equatable { | |||
| 252 | request.reply(answer) | 254 | request.reply(answer) |
| 253 | } | 255 | } |
| 254 | } | 256 | } |
| 257 | .sheet(item: $eventRequest) { request in | ||
| 258 | NavigationStack { | ||
| 259 | EventSheet(request: request, events: model.calendarEvents) { result in | ||
| 260 | eventRequest = nil | ||
| 261 | if let result { | ||
| 262 | message = result | ||
| 263 | tick += 1 | ||
| 264 | } | ||
| 265 | } | ||
| 266 | .navigationTitle(request.event == nil ? "Add to Calendar" : "Edit Event") | ||
| 267 | .navigationBarTitleDisplayMode(.inline) | ||
| 268 | } | ||
| 269 | } | ||
| 255 | .sheet(item: $refiling) { item in | 270 | .sheet(item: $refiling) { item in |
| 256 | RefileSheet(targets: workspace.refileTargets(openPath: session.path, document: session.document)) { target in | 271 | RefileSheet(targets: workspace.refileTargets(openPath: session.path, document: session.document)) { target in |
| 257 | refiling = nil | 272 | refiling = nil |
| @@ -610,10 +625,13 @@ struct AgendaScreen: View, Equatable { | |||
| 610 | } else if let item = row.item, let path = item.path, let offset = item.headingOffset ?? item.markerOffset { | 625 | } else if let item = row.item, let path = item.path, let offset = item.headingOffset ?? item.markerOffset { |
| 611 | NavigationLink(value: ReaderRoute.offset(path, offset)) { AgendaRowView(row: row, day: day, theme: theme, dark: isDark) } | 626 | NavigationLink(value: ReaderRoute.offset(path, offset)) { AgendaRowView(row: row, day: day, theme: theme, dark: isDark) } |
| 612 | } else if let event = row.event { | 627 | } else if let event = row.event { |
| 613 | // Calendar can't be asked for one event by URL; it opens on the event's day. | 628 | // An event opens for editing; a reminder opens in Reminders. |
| 614 | Button { | 629 | Button { |
| 615 | let link = event.isReminder ? "x-apple-reminderkit://REMCDReminder/\(event.id)" : "calshow:\(event.start.timeIntervalSinceReferenceDate)" | 630 | if event.isReminder { |
| 616 | if let url = URL(string: link) { openURL(url) } | 631 | if let url = URL(string: "x-apple-reminderkit://REMCDReminder/\(event.id)") { openURL(url) } |
| 632 | } else { | ||
| 633 | eventRequest = EventRequest(draft: EventDraft(event), event: event) | ||
| 634 | } | ||
| 617 | } label: { | 635 | } label: { |
| 618 | AgendaRowView(row: row, day: day, theme: theme, dark: isDark) | 636 | AgendaRowView(row: row, day: day, theme: theme, dark: isDark) |
| 619 | } | 637 | } |
| @@ -640,6 +658,13 @@ struct AgendaScreen: View, Equatable { | |||
| 640 | } | 658 | } |
| 641 | } | 659 | } |
| 642 | .contextMenu { | 660 | .contextMenu { |
| 661 | if let event = row.event, !event.isReminder { | ||
| 662 | Button("Edit Event…", systemImage: "pencil") { eventRequest = EventRequest(draft: EventDraft(event), event: event) } | ||
| 663 | // Calendar can't be asked for one event by URL; it opens on the event's day. | ||
| 664 | Button("Show in Calendar", systemImage: "calendar") { | ||
| 665 | if let url = URL(string: "calshow:\(event.start.timeIntervalSinceReferenceDate)") { openURL(url) } | ||
| 666 | } | ||
| 667 | } | ||
| 643 | if let item = row.item, item.path != nil { | 668 | if let item = row.item, item.path != nil { |
| 644 | if let mark = Mark(item) { | 669 | if let mark = Mark(item) { |
| 645 | Button("Select", systemImage: "checkmark.circle") { | 670 | Button("Select", systemImage: "checkmark.circle") { |
| @@ -662,6 +687,9 @@ struct AgendaScreen: View, Equatable { | |||
| 662 | Button("Clock In", systemImage: "stopwatch") { | 687 | Button("Clock In", systemImage: "stopwatch") { |
| 663 | if let (path, offset) = locate(item) { clockIn(path, offset) } | 688 | if let (path, offset) = locate(item) { clockIn(path, offset) } |
| 664 | } | 689 | } |
| 690 | Button("Add to Calendar…", systemImage: "calendar.badge.plus") { | ||
| 691 | eventRequest = EventRequest(draft: .entry(row.title, day: day, start: row.start, end: row.end)) | ||
| 692 | } | ||
| 665 | Divider() | 693 | Divider() |
| 666 | Button("Refile…", systemImage: "arrow.turn.down.right") { refiling = item } | 694 | Button("Refile…", systemImage: "arrow.turn.down.right") { refiling = item } |
| 667 | Button("Archive…", systemImage: "archivebox") { archiving = item } | 695 | Button("Archive…", systemImage: "archivebox") { archiving = item } |
Sources/OrgstarMobile/SettingsScreen.swift +1 −1
| @@ -140,7 +140,7 @@ struct SettingsScreen: View { | |||
| 140 | } header: { | 140 | } header: { |
| 141 | Text("Calendar") | 141 | Text("Calendar") |
| 142 | } footer: { | 142 | } footer: { |
| 143 | Text(on ? "Events from the checked calendars show in the agenda, read-only." : "Show events from Calendar in the agenda, read-only.") | 143 | Text(on ? "Events from the checked calendars show in the agenda. Tap one to edit it." : "Show events from Calendar in the agenda.") |
| 144 | } | 144 | } |
| 145 | .task(id: on) { loadCalendars() } | 145 | .task(id: on) { loadCalendars() } |
| 146 | } | 146 | } |
Tests/OrgAppTests/CalendarEventsTests.swift +18
| @@ -63,6 +63,24 @@ struct CalendarEventsTests { | |||
| 63 | #expect(AgendaRow(event: CalendarEvents.event(allDay), day: day, calendar: utc).gutter == "All day") | 63 | #expect(AgendaRow(event: CalendarEvents.event(allDay), day: day, calendar: utc).gutter == "All day") |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | @Test func entriesBecomeEventDrafts() { | ||
| 67 | var utc = Calendar(identifier: .gregorian) | ||
| 68 | utc.timeZone = TimeZone(identifier: "UTC")! | ||
| 69 | let day = Days.absolute(year: 2026, month: 10, day: 12) | ||
| 70 | let midnight = utc.date(from: DateComponents(year: 2026, month: 10, day: 12))! | ||
| 71 | let timed = EventDraft.entry("Standup", day: day, start: 930, end: 1015, calendar: utc) | ||
| 72 | #expect(!timed.isAllDay && timed.title == "Standup") | ||
| 73 | #expect(timed.start == midnight.addingTimeInterval(9.5 * 3600) && timed.end == midnight.addingTimeInterval(10.25 * 3600)) | ||
| 74 | let open = EventDraft.entry("Call", day: day, start: 1400, end: nil, calendar: utc) | ||
| 75 | #expect(open.end.timeIntervalSince(open.start) == 3600) | ||
| 76 | let backwards = EventDraft.entry("Odd", day: day, start: 1400, end: 1300, calendar: utc) | ||
| 77 | #expect(backwards.end.timeIntervalSince(backwards.start) == 3600) | ||
| 78 | let allDay = EventDraft.entry("Holiday", day: day, start: nil, end: nil, calendar: utc) | ||
| 79 | #expect(allDay.isAllDay && allDay.start == midnight && allDay.end == midnight && allDay.calendarID.isEmpty) | ||
| 80 | let event = CalendarEvents.event(Record()) | ||
| 81 | #expect(EventDraft(event) == EventDraft(title: "Standup", start: event.start, end: event.end, isAllDay: false, location: "Room 4", calendarID: "cal-1")) | ||
| 82 | } | ||
| 83 | |||
| 66 | @Test func calendarsChosenByTitleOrIdentifier() { | 84 | @Test func calendarsChosenByTitleOrIdentifier() { |
| 67 | #expect(CalendarEvents.chooses(id: "x", title: "Work", chosen: [])) | 85 | #expect(CalendarEvents.chooses(id: "x", title: "Work", chosen: [])) |
| 68 | #expect(CalendarEvents.chooses(id: "x", title: "Work", chosen: ["Work"])) | 86 | #expect(CalendarEvents.chooses(id: "x", title: "Work", chosen: ["Work"])) |
docs/manual/guide/07-agenda.org +10 −3
| @@ -191,7 +191,7 @@ With =org-enforce-todo-dependencies= or =org-enforce-todo-checkbox-dependencies= | |||
| 191 | 191 | ||
| 192 | * Calendar events | 192 | * Calendar events |
| 193 | 193 | ||
| 194 | The agenda can show events from the system Calendar app (EventKit) among your entries. They are read-only: orgstar never changes your calendars. It is off by default. To turn it on: | 194 | The agenda can show events from the system Calendar app (EventKit) among your entries. orgstar changes your calendars only when you edit an event or add an entry, as below. It is off by default. To turn it on: |
| 195 | 195 | ||
| 196 | - On the Mac, turn on Settings ▸ Agenda ▸ Show events from Calendar, and check the calendars to show. | 196 | - On the Mac, turn on Settings ▸ Agenda ▸ Show events from Calendar, and check the calendars to show. |
| 197 | - On iOS, turn on Settings ▸ Calendar ▸ Show Calendar Events, and tap the calendars to show. | 197 | - On iOS, turn on Settings ▸ Calendar ▸ Show Calendar Events, and tap the calendars to show. |
| @@ -217,6 +217,13 @@ Events appear only in the day, week and month view: | |||
| 217 | 217 | ||
| 218 | On the Mac, double-click an event, or select it and press =RET=, to open it in Calendar; its context menu has Show in Calendar. Entry commands such as =t= don't apply to events. | 218 | On the Mac, double-click an event, or select it and press =RET=, to open it in Calendar; its context menu has Show in Calendar. Entry commands such as =t= don't apply to events. |
| 219 | 219 | ||
| 220 | ** Editing events and adding entries | ||
| 221 | |||
| 222 | - Edit Event… :: in an event's context menu on the Mac, or by tapping the event on iOS (touch and hold for Edit Event… and Show in Calendar). The sheet changes the title, All day, the start and end, the location and the calendar. For a repeating event, the change applies to that occurrence only. | ||
| 223 | - Add to Calendar… :: in an entry's context menu on the Mac and iOS. The sheet starts with the entry's title and its time on the day it shows: an entry at =10:00-11:30= becomes an event from 10:00 to 11:30, one at =10:00= an hour-long event, and one without a time an all-day event. The calendar starts as Calendar's default calendar for new events; only calendars that can be changed are offered. The entry itself doesn't change. | ||
| 224 | |||
| 225 | Both use the access granted for showing events. Read-only calendars, such as subscriptions and holidays, can't be chosen. | ||
| 226 | |||
| 220 | * Reminders | 227 | * Reminders |
| 221 | 228 | ||
| 222 | The agenda can also show reminders from the Reminders app (EventKit), read-only. It is off by default. To turn it on: | 229 | The agenda can also show reminders from the Reminders app (EventKit), read-only. It is off by default. To turn it on: |
| @@ -616,7 +623,7 @@ Select a line with the mouse, or move the selection with =n= and =p=, =C-n= and | |||
| 616 | 623 | ||
| 617 | Without a selected line, =k= captures onto today when today is shown, else onto the first day shown. The + at the right of each day's header captures onto that day; see [[file:08-capture.org][Capture]]. | 624 | Without a selected line, =k= captures onto today when today is shown, else onto the first day shown. The + at the right of each day's header captures onto that day; see [[file:08-capture.org][Capture]]. |
| 618 | 625 | ||
| 619 | Right-click a line for Open, Cycle TODO State, Set Priority…, Set Tags…, Schedule…, Set Deadline…, Clock In, Mark or Unmark, and Archive. A calendar event's menu has Show in Calendar. | 626 | Right-click a line for Open, Cycle TODO State, Set Priority…, Set Tags…, Schedule…, Set Deadline…, Add to Calendar…, Clock In, Mark or Unmark, and Archive. A calendar event's menu has Show in Calendar and Edit Event…; a reminder's has Show in Reminders. |
| 620 | 627 | ||
| 621 | =t= follows =org-todo=: with fast-selection keys in your TODO keywords it asks for the state, otherwise it cycles (see [[file:05-todos-and-tags.org][TODOs and tags]]). Questions an action needs, such as a date for =C-c C-s= or a note on a state change, appear in the agenda window. Dates take the same input as in the editor (see [[file:06-dates-and-clocking.org][Dates, scheduling and clocking]]). =S-<right>= and =S-<left>= work only on deadline, scheduled and timestamp lines; they change the timestamp the line comes from. | 628 | =t= follows =org-todo=: with fast-selection keys in your TODO keywords it asks for the state, otherwise it cycles (see [[file:05-todos-and-tags.org][TODOs and tags]]). Questions an action needs, such as a date for =C-c C-s= or a note on a state change, appear in the agenda window. Dates take the same input as in the editor (see [[file:06-dates-and-clocking.org][Dates, scheduling and clocking]]). =S-<right>= and =S-<left>= work only on deadline, scheduled and timestamp lines; they change the timestamp the line comes from. |
| 622 | 629 | ||
| @@ -696,7 +703,7 @@ The Agenda tab shows the same views from the same files, using the settings in t | |||
| 696 | - Tap an entry to open it. Tap a calendar event to open Calendar on the event's day; iOS can't open Calendar at one event. | 703 | - Tap an entry to open it. Tap a calendar event to open Calendar on the event's day; iOS can't open Calendar at one event. |
| 697 | - Swipe left on an open TODO entry for Done, which sets the first done keyword of its sequence, and Next State, which moves to the next keyword; and on any entry with a heading, for Delete, which asks first, as Delete… in the menu does. The sequence is the one the file defines: the default keywords from =config.toml=, the file's own =#+TODO= lines, and those of its setup files, with unsaved edits in an open buffer included. | 704 | - Swipe left on an open TODO entry for Done, which sets the first done keyword of its sequence, and Next State, which moves to the next keyword; and on any entry with a heading, for Delete, which asks first, as Delete… in the menu does. The sequence is the one the file defines: the default keywords from =config.toml=, the file's own =#+TODO= lines, and those of its setup files, with unsaved edits in an open buffer included. |
| 698 | - Swipe right on a scheduled entry, a deadline, a habit or a TODO entry, when it isn't done, for Tomorrow, Next Week and Pick Date. Tomorrow is the day after today and Next Week is next Monday. On a deadline row these move the deadline; on other rows they set the scheduled date. A timed row keeps its times. | 705 | - Swipe right on a scheduled entry, a deadline, a habit or a TODO entry, when it isn't done, for Tomorrow, Next Week and Pick Date. Tomorrow is the day after today and Next Week is next Monday. On a deadline row these move the deadline; on other rows they set the scheduled date. A timed row keeps its times. |
| 699 | - Touch and hold an entry for TODO State…, Reschedule (Tomorrow, Next Week, Pick Date…), Schedule…, Deadline…, Tags…, Priority…, Clock In, Refile…, Archive… and Delete…, which removes the heading and everything under it. | 706 | - Touch and hold an entry for TODO State…, Reschedule (Tomorrow, Next Week, Pick Date…), Schedule…, Deadline…, Tags…, Priority…, Clock In, Add to Calendar…, Refile…, Archive… and Delete…, which removes the heading and everything under it. |
| 700 | - Marking an entry done and rescheduling one give haptic feedback. | 707 | - Marking an entry done and rescheduling one give haptic feedback. |
| 701 | - Log Mode, in the span menu, turns log mode on and off. The widgets never show log mode's entries. | 708 | - Log Mode, in the span menu, turns log mode on and off. The widgets never show log mode's entries. |
| 702 | - There are no keyboard commands; bulk actions use Select instead of marks (see [[*Bulk actions][Bulk actions]]). | 709 | - There are no keyboard commands; bulk actions use Select instead of marks (see [[*Bulk actions][Bulk actions]]). |
docs/manual/guide/13-configuration.org +1 −1
| @@ -365,7 +365,7 @@ Any other key in =[theme]= is a color; see Themes below. | |||
| 365 | | =ignored-folders= | string | see below | Folder names never listed or searched, separated by spaces. | | 365 | | =ignored-folders= | string | see below | Folder names never listed or searched, separated by spaces. | |
| 366 | | =agenda-include-subfolders= | boolean | =false= | The agenda reads org files in subfolders too. | | 366 | | =agenda-include-subfolders= | boolean | =false= | The agenda reads org files in subfolders too. | |
| 367 | | =reminders= | boolean | =true= | Notify before timed entries. | | 367 | | =reminders= | boolean | =true= | Notify before timed entries. | |
| 368 | | =calendar-events= | boolean | =false= | Show events from Calendar in the agenda, read-only. | | 368 | | =calendar-events= | boolean | =false= | Show events from Calendar in the agenda. | |
| 369 | | =calendar-event-calendars= | string | =""= | The calendars whose events show, by title or identifier, separated by commas; =""= for all. | | 369 | | =calendar-event-calendars= | string | =""= | The calendars whose events show, by title or identifier, separated by commas; =""= for all. | |
| 370 | | =agenda-reminders= | boolean | =false= | Show incomplete reminders with a due date from Reminders in the agenda, read-only. | | 370 | | =agenda-reminders= | boolean | =false= | Show incomplete reminders with a due date from Reminders in the agenda, read-only. | |
| 371 | | =agenda-reminder-lists= | string | =""= | The Reminders lists shown, by title or identifier, separated by commas; =""= for all. | | 371 | | =agenda-reminder-lists= | string | =""= | The Reminders lists shown, by title or identifier, separated by commas; =""= for all. | |
docs/manual/guide/14-ios.org +3 −3
| @@ -175,11 +175,11 @@ The Agenda tab shows the agenda over all your folders, with the span and start d | |||
| 175 | - Tap :: an entry to read it, at its heading. | 175 | - Tap :: an entry to read it, at its heading. |
| 176 | - Swipe left :: on a TODO entry for Done, which sets the first done keyword of its sequence, or Next State; on any entry with a heading for Delete, which asks first. | 176 | - Swipe left :: on a TODO entry for Done, which sets the first done keyword of its sequence, or Next State; on any entry with a heading for Delete, which asks first. |
| 177 | - Swipe right :: for Tomorrow, Next Week (next Monday) or Pick Date, which move the entry's scheduled date, or its deadline on a deadline row. | 177 | - Swipe right :: for Tomorrow, Next Week (next Monday) or Pick Date, which move the entry's scheduled date, or its deadline on a deadline row. |
| 178 | - Touch and hold :: an entry for TODO State…, Reschedule, Schedule…, Deadline…, Tags…, Priority…, Clock In, Refile…, Archive…, and Delete…. Delete… removes the heading and every line under it, after asking. Refile… lists each file and the headings in it down to level 3, as the Mac's prompt does; the entry goes to the end of the file, or under the heading, you choose. Search narrows the list by file and heading path. | 178 | - Touch and hold :: an entry for TODO State…, Reschedule, Schedule…, Deadline…, Tags…, Priority…, Clock In, Add to Calendar…, Refile…, Archive…, and Delete…. Delete… removes the heading and every line under it, after asking. Refile… lists each file and the headings in it down to level 3, as the Mac's prompt does; the entry goes to the end of the file, or under the heading, you choose. Search narrows the list by file and heading path. |
| 179 | 179 | ||
| 180 | Commands from the agenda change the file directly when it isn't open, and through the editor when it is. If the heading changed since the agenda was built, nothing runs. | 180 | Commands from the agenda change the file directly when it isn't open, and through the editor when it is. If the heading changed since the agenda was built, nothing runs. |
| 181 | 181 | ||
| 182 | With =calendar-events= on, the agenda also shows events from the Calendar app, and with =agenda-reminders= on, reminders from the Reminders app; see Settings below. | 182 | With =calendar-events= on, the agenda also shows events from the Calendar app, and with =agenda-reminders= on, reminders from the Reminders app; see Settings below. Tap an event to edit it; an entry's Add to Calendar… adds it to a calendar. See [[file:07-agenda.org][The agenda]]. |
| 183 | 183 | ||
| 184 | See [[file:07-agenda.org][The agenda]] for the rows, the views and matches, and the differences from the Mac. | 184 | See [[file:07-agenda.org][The agenda]] for the rows, the views and matches, and the differences from the Mac. |
| 185 | 185 | ||
| @@ -351,7 +351,7 @@ The Agenda, TODO Dependencies, Calendar and Reminders sections are the only plac | |||
| 351 | - Show days without entries :: turns =org-agenda-show-all-dates= on or off. | 351 | - Show days without entries :: turns =org-agenda-show-all-dates= on or off. |
| 352 | - Blocked entries :: Dimmed, Hidden or Shown as usual (=org-agenda-dim-blocked-tasks=). | 352 | - Blocked entries :: Dimmed, Hidden or Shown as usual (=org-agenda-dim-blocked-tasks=). |
| 353 | - TODO Dependencies :: Not done before TODO children (=org-enforce-todo-dependencies=) and Not done with unchecked boxes (=org-enforce-todo-checkbox-dependencies=). | 353 | - TODO Dependencies :: Not done before TODO children (=org-enforce-todo-dependencies=) and Not done with unchecked boxes (=org-enforce-todo-checkbox-dependencies=). |
| 354 | - Show Calendar Events :: turns on =calendar-events=, and asks for access to your calendars. iOS asks for full access, as Calendar has no read-only level; orgstar only reads. While access is missing the section shows Allow Access to Calendars…; if you declined, allow it in the Settings app under Privacy & Security ▸ Calendars. | 354 | - Show Calendar Events :: turns on =calendar-events=, and asks for access to your calendars. iOS asks for full access, as Calendar has no read-only level; orgstar changes a calendar only when you edit an event or add an entry. While access is missing the section shows Allow Access to Calendars…; if you declined, allow it in the Settings app under Privacy & Security ▸ Calendars. |
| 355 | - The calendars :: tap one to show or hide its events (=calendar-event-calendars=). With every calendar checked the setting is empty, so calendars added later show too. | 355 | - The calendars :: tap one to show or hide its events (=calendar-event-calendars=). With every calendar checked the setting is empty, so calendars added later show too. |
| 356 | - Show Reminders :: turns on =agenda-reminders= and asks for access to your reminders; Allow Access to Reminders… shows while it is missing. Tap a list to show or hide its reminders (=agenda-reminder-lists=). | 356 | - Show Reminders :: turns on =agenda-reminders= and asks for access to your reminders; Allow Access to Reminders… shows while it is missing. Tap a list to show or hide its reminders (=agenda-reminder-lists=). |
| 357 | 357 | ||
ios/Orgstar/Info.plist +1 −1
| @@ -40,7 +40,7 @@ | |||
| 40 | <key>NSFaceIDUsageDescription</key> | 40 | <key>NSFaceIDUsageDescription</key> |
| 41 | <string>Face ID unlocks the passphrase of encrypted entries you asked orgstar to remember.</string> | 41 | <string>Face ID unlocks the passphrase of encrypted entries you asked orgstar to remember.</string> |
| 42 | <key>NSCalendarsFullAccessUsageDescription</key> | 42 | <key>NSCalendarsFullAccessUsageDescription</key> |
| 43 | <string>The agenda shows your calendar events alongside your Org entries. orgstar only reads them.</string> | 43 | <string>The agenda shows your calendar events alongside your Org entries. orgstar changes your calendars only when you edit an event or add an entry to one.</string> |
| 44 | <key>NSRemindersFullAccessUsageDescription</key> | 44 | <key>NSRemindersFullAccessUsageDescription</key> |
| 45 | <string>The agenda shows your reminders alongside your Org entries. orgstar only reads them.</string> | 45 | <string>The agenda shows your reminders alongside your Org entries. orgstar only reads them.</string> |
| 46 | <key>NSSupportsLiveActivities</key> | 46 | <key>NSSupportsLiveActivities</key> |
scripts/build-app.sh +1 −1
| @@ -132,7 +132,7 @@ ${feed_keys} | |||
| 132 | <key>LSApplicationCategoryType</key> | 132 | <key>LSApplicationCategoryType</key> |
| 133 | <string>public.app-category.productivity</string> | 133 | <string>public.app-category.productivity</string> |
| 134 | <key>NSCalendarsFullAccessUsageDescription</key> | 134 | <key>NSCalendarsFullAccessUsageDescription</key> |
| 135 | <string>The agenda shows your calendar events alongside your Org entries. orgstar only reads them.</string> | 135 | <string>The agenda shows your calendar events alongside your Org entries. orgstar changes your calendars only when you edit an event or add an entry to one.</string> |
| 136 | <key>NSRemindersFullAccessUsageDescription</key> | 136 | <key>NSRemindersFullAccessUsageDescription</key> |
| 137 | <string>The agenda shows your reminders alongside your Org entries. orgstar only reads them.</string> | 137 | <string>The agenda shows your reminders alongside your Org entries. orgstar only reads them.</string> |
| 138 | <key>NSHighResolutionCapable</key> | 138 | <key>NSHighResolutionCapable</key> |
scripts/build-ios-app.sh +1 −1
| @@ -52,7 +52,7 @@ cat > "$app/Info.plist" <<PLIST | |||
| 52 | <key>NSFaceIDUsageDescription</key> | 52 | <key>NSFaceIDUsageDescription</key> |
| 53 | <string>Face ID unlocks the passphrase of encrypted entries you asked orgstar to remember.</string> | 53 | <string>Face ID unlocks the passphrase of encrypted entries you asked orgstar to remember.</string> |
| 54 | <key>NSCalendarsFullAccessUsageDescription</key> | 54 | <key>NSCalendarsFullAccessUsageDescription</key> |
| 55 | <string>The agenda shows your calendar events alongside your Org entries. orgstar only reads them.</string> | 55 | <string>The agenda shows your calendar events alongside your Org entries. orgstar changes your calendars only when you edit an event or add an entry to one.</string> |
| 56 | <key>NSRemindersFullAccessUsageDescription</key> | 56 | <key>NSRemindersFullAccessUsageDescription</key> |
| 57 | <string>The agenda shows your reminders alongside your Org entries. orgstar only reads them.</string> | 57 | <string>The agenda shows your reminders alongside your Org entries. orgstar only reads them.</string> |
| 58 | <key>UIDeviceFamily</key> | 58 | <key>UIDeviceFamily</key> |