SPB Git

Repository Public

Welcome.swift 5.4 KB 93 lines swift

1import AppKit2import SwiftUI3import SheetCore4import SheetUI56/// Template chooser shown at launch and from File ▸ New from Template (see TemplateChooser.swift).7@MainActor8enum Welcome {9    /// Set by `Features.registerAll()`.10    static var provider: WelcomeProvider?11    static var isAvailable: Bool { provider != nil }1213    static func show(delegate: AppDelegate) {14        guard let provider else { NSDocumentController.shared.newDocument(nil); return }15        if delegate.welcomeWindow == nil {16            let w = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 940, height: 640), styleMask: [.titled, .closable, .fullSizeContentView], backing: .buffered, defer: false)17            w.titlebarAppearsTransparent = true18            w.title = NSLocalizedString("New Workbook", comment: "")19            w.isReleasedWhenClosed = false20            w.contentView = NSHostingView(rootView: provider.view({ workbook, name in21                delegate.welcomeWindow?.close()22                if let workbook { delegate.openWorkbook(workbook, name: name) } else { NSDocumentController.shared.newDocument(nil) }23            }, { delegate.welcomeWindow?.close(); NSDocumentController.shared.openDocument(nil) }))24            w.center()25            delegate.welcomeWindow = w26        }27        delegate.welcomeWindow?.makeKeyAndOrderFront(nil)28    }2930    static func buildTemplate(id: String) -> (Workbook, String)? { provider?.build(id) }31}3233struct WelcomeProvider {34    /// (onChoose(workbook or nil for blank, name), onOpenExisting) → chooser view35    var view: (@escaping (Workbook?, String?) -> Void, @escaping () -> Void) -> AnyView36    var build: (String) -> (Workbook, String)?37}3839/// Minimal in-app help: keyboard shortcuts and where things are. Full documentation lives in the repository.40@MainActor41enum HelpWindow {42    private static var window: NSWindow?43    static func show() {44        if window == nil {45            let w = NSWindow(contentRect: NSRect(x: 0, y: 0, width: 560, height: 620), styleMask: [.titled, .closable, .resizable], backing: .buffered, defer: false)46            w.title = NSLocalizedString("ORIX Sheet Help", comment: "")47            w.isReleasedWhenClosed = false48            w.contentView = NSHostingView(rootView: HelpView())49            w.center()50            window = w51        }52        window?.makeKeyAndOrderFront(nil)53    }54}5556struct HelpView: View {57    /// Section titles, key names and descriptions are catalog keys (`LK`); pure key symbols are shown as is.58    static let shortcuts: [(String, [(String, String)])] = [59        (LK("Navigation"), [(LK("Arrow keys"), LK("Move")), (LK("⇧ + arrows"), LK("Extend the selection")), (LK("⌘ + arrows"), LK("Jump to the edge of the data")), ("⌃G", LK("Go to a cell, range or name")),60                        ("⌘A", LK("Select the data region, then the sheet")), (LK("⇧Space / ⌃Space"), LK("Select row / column")), ("⌥⌘← / ⌥⌘→", LK("Previous / next sheet")), ("⌥⌘R", LK("Rename the sheet"))]),61        (LK("Editing"), [(LK("Type"), LK("Replace the cell")), (LK("F2 or double-click"), LK("Edit in the cell")), ("↩ / ⇥", LK("Commit and move down / right")), ("⌃↩", LK("Fill the selection with the entry")),62                     ("⌥↩", LK("New line in the cell")), (LK("Esc"), LK("Cancel")), ("⌘D / ⌘R", LK("Fill down / right")), ("⌘;", LK("Insert today's date")), ("⌫", LK("Clear contents"))]),63        (LK("Clipboard"), [("⌘C ⌘X ⌘V", LK("Copy, cut, paste")), ("⇧⌘V", LK("Paste values")), ("⌥⌘V", LK("Paste formatting"))]),64        (LK("Format"), [("⌘B ⌘I ⌘U", LK("Bold, italic, underline")), ("⇧⌘X", LK("Strikethrough")), ("⌥⌘M", LK("Merge or unmerge"))]),65        (LK("View"), [("⌘`", LK("Show formulas")), ("⌘+ ⌘− ⌘0", LK("Zoom")), ("⌥⌘I", LK("Inspector")), ("⌃⌘S", LK("Navigator")), ("⌘=", LK("Recalculate everything"))]),66    ]67    var body: some View {68        ScrollView {69            VStack(alignment: .leading, spacing: ORIX.Space.md) {70                Text("ORIX Sheet").font(ORIX.Typeface.title).accessibilityAddTraits(.isHeader)71                Text(NSLocalizedString("Everything runs on this Mac: no account, no network. Other formats are imported into an ORIX workbook; use File ▸ Export To to write Excel, CSV, OpenDocument, JSON or PDF, with a report of anything the format cannot hold.", comment: ""))72                    .font(ORIX.Typeface.body).foregroundStyle(ORIX.Palette.textSecondary)73                ForEach(Self.shortcuts, id: \.0) { group in74                    VStack(alignment: .leading, spacing: 6) {75                        SectionHeader(localized: NSLocalizedString(group.0, comment: ""))76                        ForEach(group.1, id: \.0) { row in77                            HStack(alignment: .firstTextBaseline) {78                                Text(NSLocalizedString(row.0, comment: "")).font(.system(size: 12, weight: .medium, design: .monospaced)).frame(width: 170, alignment: .leading)79                                Text(NSLocalizedString(row.1, comment: "")).font(.system(size: 12.5)).foregroundStyle(ORIX.Palette.textSecondary)80                                    .fixedSize(horizontal: false, vertical: true)81                            }82                            .accessibilityElement(children: .combine)83                        }84                    }85                }86            }87            .padding(ORIX.Space.lg)88            .frame(maxWidth: .infinity, alignment: .leading)89        }90        .background(ORIX.Palette.surface)91    }92}93
Files main
Menu

Theme