krz/orgstar

A native macOS editor for org-mode files. editor org-mode swift

Sources/Orgstar/LinkOpener.swift

c1295824f55c7bba681fca8338bf08167e110105
orgstar/Sources/Orgstar/LinkOpener.swift history · blame · raw

18 lines · 605 bytes

 1import AppKit
 2import OrgApp
 3import OrgCore
 4
 5/// Follows a link, handing addresses and files Orgstar doesn't edit to macOS.
 6@MainActor
 7enum LinkOpener {
 8    /// Returns a message when the link can't be followed.
 9    static func open(_ link: OrgLink, session: DocumentSession, workspace: WorkspaceModel) -> String? {
10        switch session.follow(link, workspace: workspace, isText: FileTypes.isText) {
11        case .shown: return nil
12        case .openExternally(let url):
13            NSWorkspace.shared.open(url)
14            return nil
15        case .message(let message): return message
16        }
17    }
18}