Commit d85099bc95
Verified · cmc
Layout: unified · split
Sources/OrgstarMobile/ColumnViewScreen.swift added +136
| @@ -0,0 +1,136 @@ | |||
| 1 | #if os(iOS) | ||
| 2 | import OrgApp | ||
| 3 | import OrgCore | ||
| 4 | import SwiftUI | ||
| 5 | |||
| 6 | /// `org-columns` on iOS: the entries and their columns, with summaries, as on the Mac. Tap a | ||
| 7 | /// cell to select it; the bar edits it (`e`), moves to the previous or next allowed value | ||
| 8 | /// (`p`, `n`), or goes to the entry. | ||
| 9 | struct ColumnViewScreen: View { | ||
| 10 | @State var view: ColumnView.View | ||
| 11 | let session: DocumentSession | ||
| 12 | let path: String | ||
| 13 | let jump: (Int) -> Void | ||
| 14 | @Environment(\.dismiss) private var dismiss | ||
| 15 | @State private var selected: (row: Int, column: Int)? | ||
| 16 | @State private var message: String? | ||
| 17 | @State private var prompt: EditorScreen.PromptRequest? | ||
| 18 | |||
| 19 | var body: some View { | ||
| 20 | NavigationStack { | ||
| 21 | ScrollView([.horizontal, .vertical]) { | ||
| 22 | Grid(alignment: .leading, horizontalSpacing: 14, verticalSpacing: 6) { | ||
| 23 | GridRow { | ||
| 24 | ForEach(view.specs.indices, id: \.self) { i in | ||
| 25 | Text(view.specs[i].title).bold().foregroundStyle(.secondary) | ||
| 26 | } | ||
| 27 | } | ||
| 28 | Divider() | ||
| 29 | ForEach(view.rows.indices, id: \.self) { r in | ||
| 30 | GridRow { | ||
| 31 | ForEach(view.specs.indices, id: \.self) { c in cellView(r, c) } | ||
| 32 | } | ||
| 33 | } | ||
| 34 | } | ||
| 35 | .font(.system(.callout, design: .monospaced)) | ||
| 36 | .padding(12) | ||
| 37 | } | ||
| 38 | .defaultScrollAnchor(.topLeading) | ||
| 39 | .navigationTitle("Column View") | ||
| 40 | .navigationBarTitleDisplayMode(.inline) | ||
| 41 | .toolbar { | ||
| 42 | ToolbarItem(placement: .confirmationAction) { Button("Done") { dismiss() } } | ||
| 43 | ToolbarItemGroup(placement: .bottomBar) { | ||
| 44 | Button("Edit", systemImage: "pencil") { edit() }.disabled(selected == nil) | ||
| 45 | Button("Previous Value", systemImage: "chevron.up") { cycle(previous: true) }.disabled(selected == nil) | ||
| 46 | Button("Next Value", systemImage: "chevron.down") { cycle(previous: false) }.disabled(selected == nil) | ||
| 47 | Spacer() | ||
| 48 | Button("Go to Entry", systemImage: "arrow.right.doc.on.clipboard") { | ||
| 49 | guard let selected else { return } | ||
| 50 | jump(view.rows[selected.row].start) | ||
| 51 | dismiss() | ||
| 52 | } | ||
| 53 | .disabled(selected == nil) | ||
| 54 | } | ||
| 55 | } | ||
| 56 | .safeAreaInset(edge: .top) { | ||
| 57 | if let message { | ||
| 58 | Text(message).font(.footnote).padding(.horizontal, 12).padding(.vertical, 6) | ||
| 59 | .glassEffect(.regular, in: Capsule()) | ||
| 60 | .onTapGesture { self.message = nil } | ||
| 61 | } | ||
| 62 | } | ||
| 63 | .sheet(item: $prompt) { request in | ||
| 64 | PromptSheet(prompt: request.prompt) { answer in | ||
| 65 | prompt = nil | ||
| 66 | request.reply(answer) | ||
| 67 | } | ||
| 68 | } | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | private func cellView(_ r: Int, _ c: Int) -> some View { | ||
| 73 | let row = view.rows[r] | ||
| 74 | let isSelected = selected.map { $0 == (r, c) } ?? false | ||
| 75 | let text = view.specs[c].property == "ITEM" ? String(repeating: "*", count: row.level) + " " + row.values[c] : row.values[c] | ||
| 76 | return Text(text.isEmpty ? " " : text) | ||
| 77 | .lineLimit(1) | ||
| 78 | .frame(maxWidth: view.specs[c].width.map { CGFloat($0) * 8.5 }, alignment: .leading) | ||
| 79 | .padding(.horizontal, 3) | ||
| 80 | .padding(.vertical, 2) | ||
| 81 | .background(isSelected ? Color.accentColor.opacity(0.25) : .clear, in: RoundedRectangle(cornerRadius: 4)) | ||
| 82 | .contentShape(Rectangle()) | ||
| 83 | .onTapGesture { selected = (r, c) } | ||
| 84 | .accessibilityAddTraits(isSelected ? [.isButton, .isSelected] : .isButton) | ||
| 85 | .accessibilityAction(named: "Edit") { | ||
| 86 | selected = (r, c) | ||
| 87 | edit() | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | /// `org-columns-edit-value`: asks for the value, offering the allowed ones. | ||
| 92 | private func edit() { | ||
| 93 | guard let (r, c) = selected else { return } | ||
| 94 | let spec = view.specs[c] | ||
| 95 | let row = view.rows[r] | ||
| 96 | if ["CLOCKSUM", "CLOCKSUM_T", "ALLTAGS", "BLOCKED", "CLOSED", "FILE", "TIMESTAMP", "TIMESTAMP_IA"].contains(spec.property) { | ||
| 97 | message = "This special column cannot be edited" | ||
| 98 | return | ||
| 99 | } | ||
| 100 | let allowed = session.document.flatMap { PropertyValues.allowed(spec.property, at: row.start, text: $0.text, tree: $0.tree)?.values } ?? [] | ||
| 101 | let initial = row.raw.indices.contains(c) ? row.raw[c] : row.values[c] | ||
| 102 | // With allowed values the field starts empty, so that they all show. | ||
| 103 | let message = allowed.isEmpty || initial.isEmpty ? spec.title : "\(spec.title) (now \(initial))" | ||
| 104 | prompt = EditorScreen.PromptRequest(prompt: Prompt(key: "value", message: message, initial: allowed.isEmpty ? initial : "", choices: allowed)) { answer in | ||
| 105 | guard let answer else { return } | ||
| 106 | perform(SetColumnValue(property: spec.property, value: answer), at: row.start) | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | private func cycle(previous: Bool) { | ||
| 111 | guard let (r, c) = selected else { return } | ||
| 112 | let spec = view.specs[c] | ||
| 113 | perform(NextColumnValue(property: spec.property, summary: spec.summary, previous: previous), at: view.rows[r].start) | ||
| 114 | } | ||
| 115 | |||
| 116 | private func perform(_ command: any OrgCommand, at start: Int, answers: [String: String] = [:]) { | ||
| 117 | switch session.perform(command, path: path, at: start, expect: nil, answers: answers) { | ||
| 118 | case .commit: | ||
| 119 | message = nil | ||
| 120 | guard let document = session.document, let new = try? ColumnView.refresh(view, text: document.text, tree: document.tree) else { return } | ||
| 121 | view = new | ||
| 122 | if let selected, selected.row >= new.rows.count { self.selected = nil } | ||
| 123 | case .failed(let text): | ||
| 124 | message = text | ||
| 125 | case .prompt(let request): | ||
| 126 | // A state note, or what else the change asks. | ||
| 127 | prompt = EditorScreen.PromptRequest(prompt: request) { answer in | ||
| 128 | guard let answer else { return } | ||
| 129 | perform(command, at: start, answers: answers.merging([request.key: answer]) { $1 }) | ||
| 130 | } | ||
| 131 | case .external(let request): | ||
| 132 | message = MobileEditor.unavailable(request, title: command.title) | ||
| 133 | } | ||
| 134 | } | ||
| 135 | } | ||
| 136 | #endif | ||
Sources/OrgstarMobile/EditorScreen.swift +7
| @@ -44,6 +44,7 @@ struct EditorScreen: View { | |||
| 44 | /// `app.refile`, `app.refile.copy` or `app.refile.goto`. | 44 | /// `app.refile`, `app.refile.copy` or `app.refile.goto`. |
| 45 | case refile(String) | 45 | case refile(String) |
| 46 | case block(BlockEdit) | 46 | case block(BlockEdit) |
| 47 | case columns(ColumnView.View) | ||
| 47 | 48 | ||
| 48 | var id: String { | 49 | var id: String { |
| 49 | switch self { | 50 | switch self { |
| @@ -53,6 +54,7 @@ struct EditorScreen: View { | |||
| 53 | case .syncCopies: "syncCopies" | 54 | case .syncCopies: "syncCopies" |
| 54 | case .recovery: "recovery" | 55 | case .recovery: "recovery" |
| 55 | case .block(let edit): "block \(edit.range)" | 56 | case .block(let edit): "block \(edit.range)" |
| 57 | case .columns: "columns" | ||
| 56 | } | 58 | } |
| 57 | } | 59 | } |
| 58 | } | 60 | } |
| @@ -78,6 +80,8 @@ struct EditorScreen: View { | |||
| 78 | Menu("More", systemImage: "ellipsis.circle") { | 80 | Menu("More", systemImage: "ellipsis.circle") { |
| 79 | Button("Commands", systemImage: "command") { sheet = .palette } | 81 | Button("Commands", systemImage: "command") { sheet = .palette } |
| 80 | Button("Clock In", systemImage: "stopwatch") { editor?.run("app.clock.in") } | 82 | Button("Clock In", systemImage: "stopwatch") { editor?.run("app.clock.in") } |
| 83 | Button("Column View", systemImage: "tablecells") { editor?.run("org.columns") } | ||
| 84 | Button("Column View of File", systemImage: "tablecells.badge.ellipsis") { editor?.run("org.columns.global") } | ||
| 81 | Toggle(isOn: Binding(get: { model.showMarkup }, set: { model.showMarkup = $0 })) { | 85 | Toggle(isOn: Binding(get: { model.showMarkup }, set: { model.showMarkup = $0 })) { |
| 82 | Label("Show Markup", systemImage: "chevron.left.forwardslash.chevron.right") | 86 | Label("Show Markup", systemImage: "chevron.left.forwardslash.chevron.right") |
| 83 | } | 87 | } |
| @@ -140,6 +144,8 @@ struct EditorScreen: View { | |||
| 140 | self.sheet = nil | 144 | self.sheet = nil |
| 141 | if let content, let editor { _ = editor.perform(ReplaceBlockLines(edit: edit, content: content)) } | 145 | if let content, let editor { _ = editor.perform(ReplaceBlockLines(edit: edit, content: content)) } |
| 142 | } | 146 | } |
| 147 | case .columns(let view): | ||
| 148 | ColumnViewScreen(view: view, session: session, path: path) { offset in editor?.reveal(offset) } | ||
| 143 | } | 149 | } |
| 144 | } | 150 | } |
| 145 | .onChange(of: session.conflict) { _, conflict in | 151 | .onChange(of: session.conflict) { _, conflict in |
| @@ -219,6 +225,7 @@ struct EditorScreen: View { | |||
| 219 | } | 225 | } |
| 220 | } | 226 | } |
| 221 | editor.onEditBlock = { edit in sheet = .block(edit) } | 227 | editor.onEditBlock = { edit in sheet = .block(edit) } |
| 228 | editor.onColumnView = { view in sheet = .columns(view) } | ||
| 222 | editor.onTangle = { scope in message = session.tangle(scope) } | 229 | editor.onTangle = { scope in message = session.tangle(scope) } |
| 223 | editor.onBabel = { job in run(job) } | 230 | editor.onBabel = { job in run(job) } |
| 224 | editor.onRefreshSetup = { session.refreshSetup() } | 231 | editor.onRefreshSetup = { session.refreshSetup() } |
Sources/OrgstarMobile/MobileEditor.swift +4
| @@ -82,6 +82,8 @@ final class MobileEditor: NSObject, DocumentBuffer { | |||
| 82 | var onEditBlock: ((BlockEdit) -> Void)? | 82 | var onEditBlock: ((BlockEdit) -> Void)? |
| 83 | /// A followed timestamp's agenda days: the first (a `Days` number) and how many. | 83 | /// A followed timestamp's agenda days: the first (a `Days` number) and how many. |
| 84 | var onAgenda: ((Int, Int) -> Void)? | 84 | var onAgenda: ((Int, Int) -> Void)? |
| 85 | /// Shows a column view. | ||
| 86 | var onColumnView: ((ColumnView.View) -> Void)? | ||
| 85 | /// Commands the app runs, as `app.clock.in`. | 87 | /// Commands the app runs, as `app.clock.in`. |
| 86 | var onAppCommand: ((String) -> Void)? | 88 | var onAppCommand: ((String) -> Void)? |
| 87 | /// Tags used across the workspace, for completion. | 89 | /// Tags used across the workspace, for completion. |
| @@ -233,6 +235,8 @@ final class MobileEditor: NSObject, DocumentBuffer { | |||
| 233 | onTangle?(scope) | 235 | onTangle?(scope) |
| 234 | case .external(.agenda(let start, let count)) where onAgenda != nil: | 236 | case .external(.agenda(let start, let count)) where onAgenda != nil: |
| 235 | onAgenda?(start, count) | 237 | onAgenda?(start, count) |
| 238 | case .external(.columnView(let view)) where onColumnView != nil: | ||
| 239 | onColumnView?(view) | ||
| 236 | case .external(let request): | 240 | case .external(let request): |
| 237 | onMessage?(Self.unavailable(request, title: command.title)) | 241 | onMessage?(Self.unavailable(request, title: command.title)) |
| 238 | } | 242 | } |
docs/manual/guide/04-outlines.org +5
| @@ -678,6 +678,11 @@ The allowed values are the property's =_ALL= values from the entry, an ancestor | |||
| 678 | earlier; Org 9.8.7 signals an error there instead. After each change the sheet captures | 678 | earlier; Org 9.8.7 signals an error there instead. After each change the sheet captures |
| 679 | the view again, so summaries follow. Parent summaries are not written into the file. | 679 | the view again, so summaries follow. Parent summaries are not written into the file. |
| 680 | 680 | ||
| 681 | On iOS, choose Column View or Column View of File from the editor's More menu. The view | ||
| 682 | scrolls both ways; tap a cell to select it. The bar at the bottom has Edit, which asks | ||
| 683 | for the value with the allowed values listed, Previous Value and Next Value (=p= and | ||
| 684 | =n=), and Go to Entry. Done closes it. | ||
| 685 | |||
| 681 | ** The Columns inspector | 686 | ** The Columns inspector |
| 682 | 687 | ||
| 683 | View ▸ Show or Hide Columns and Clock opens an inspector beside the editor. Its Columns | 688 | View ▸ Show or Hide Columns and Clock opens an inspector beside the editor. Its Columns |
docs/manual/guide/14-ios.org +1 −1
| @@ -371,7 +371,7 @@ Quick Look in the Files app shows org files as the HTML export renders them. | |||
| 371 | - Word, ODT, LaTeX, ASCII and LaTeX-made PDF export. | 371 | - Word, ODT, LaTeX, ASCII and LaTeX-made PDF export. |
| 372 | - Idle detection while a clock runs. | 372 | - Idle detection while a clock runs. |
| 373 | - Import from Emacs. | 373 | - Import from Emacs. |
| 374 | - The board, column view, the backlinks pane, and the buffer list and tab bar. | 374 | - The Columns inspector, the backlinks pane, and the buffer list and tab bar. The board and column view are there (see [[file:07-agenda.org][The agenda]] and [[file:04-outlines.org][Outlines]]). |
| 375 | - The global capture hotkey and the Settings window. | 375 | - The global capture hotkey and the Settings window. |
| 376 | - Explicit saving. | 376 | - Explicit saving. |
| 377 | 377 | ||