Sources/Orgstar/RoamGraphWindow.swift

30 lines · 1148 bytes

1 symbol in this file
 1import OrgApp
 2import OrgCore
 3import OrgIndex
 4import SwiftUI
 5
 6/// Window ▸ Graph: the workspace's nodes and links; a click on a node shows it in the main window.
 7struct RoamGraphWindow: View {
 8    let workspace: WorkspaceModel
 9    let session: DocumentSession
10    let commands: AppCommands
11    @Environment(\.openWindow) private var openWindow
12
13    private var current: String? {
14        guard let path = session.path, let tree = session.document?.tree else { return nil }
15        return RoamGraph.current(tree: tree, at: commands.selection.location, path: path, denote: OrgPreferences.usesDenote())
16    }
17
18    var body: some View {
19        RoamGraphView(
20            load: { workspace.roamGraph(overlay: workspace.overlay(session.openDocuments)) },
21            current: current,
22            version: session.editVersion &+ workspace.files.count &+ (workspace.changedFile?.version ?? 0)
23        ) { location in
24            if !commands.mainWindowOpen { openWindow(id: "main") }
25            commands.jump(path: location.path, offset: location.start)
26        }
27        .frame(minWidth: 420, minHeight: 320)
28        .navigationTitle("Graph")
29    }
30}