iOS: swipe to delete agenda entries; delete files from Folders !214
6 files changed, +60 −6
Layout: unified · split
Sources/OrgstarMobile/AgendaScreen.swift +4
| @@ -491,6 +491,10 @@ struct AgendaScreen: View, Equatable { | |||
| 491 | Button("Done", systemImage: "checkmark") { markDone(item) }.tint(.green) | 491 | Button("Done", systemImage: "checkmark") { markDone(item) }.tint(.green) |
| 492 | Button("Next State", systemImage: "arrow.right.circle") { run("org.todo.next", on: item) }.tint(.blue) | 492 | Button("Next State", systemImage: "arrow.right.circle") { run("org.todo.next", on: item) }.tint(.blue) |
| 493 | } | 493 | } |
| 494 | // Last, so a full swipe doesn't reach it; it asks first. | ||
| 495 | if let item = row.item, item.path != nil, item.headingLine != nil { | ||
| 496 | Button("Delete", systemImage: "trash") { deleting = item }.tint(.red) | ||
| 497 | } | ||
| 494 | } | 498 | } |
| 495 | .swipeActions(edge: .leading) { | 499 | .swipeActions(edge: .leading) { |
| 496 | if canReschedule(row), let item = row.item { | 500 | if canReschedule(row), let item = row.item { |
Sources/OrgstarMobile/FoldersScreen.swift +47 −3
| @@ -6,13 +6,16 @@ import UniformTypeIdentifiers | |||
| 6 | /// The folders of org files the agenda reads, and their files. | 6 | /// The folders of org files the agenda reads, and their files. |
| 7 | struct FoldersScreen: View { | 7 | struct FoldersScreen: View { |
| 8 | let workspace: WorkspaceModel | 8 | let workspace: WorkspaceModel |
| 9 | let session: DocumentSession | ||
| 9 | @State private var importing = false | 10 | @State private var importing = false |
| 11 | /// The file whose deletion is being confirmed. | ||
| 12 | @State private var deleting: String? | ||
| 10 | 13 | ||
| 11 | var body: some View { | 14 | var body: some View { |
| 12 | List { | 15 | List { |
| 13 | ForEach(workspace.rootPaths, id: \.self) { root in | 16 | ForEach(workspace.rootPaths, id: \.self) { root in |
| 14 | Section((root as NSString).lastPathComponent) { | 17 | Section((root as NSString).lastPathComponent) { |
| 15 | FolderContents(workspace: workspace, root: root, folder: "") | 18 | FolderContents(workspace: workspace, root: root, folder: "", deleting: $deleting) |
| 16 | Button("Remove Folder", role: .destructive) { try? workspace.removeRoot(path: root) } | 19 | Button("Remove Folder", role: .destructive) { try? workspace.removeRoot(path: root) } |
| 17 | } | 20 | } |
| 18 | } | 21 | } |
| @@ -22,9 +25,9 @@ struct FoldersScreen: View { | |||
| 22 | } | 25 | } |
| 23 | .navigationTitle("Folders") | 26 | .navigationTitle("Folders") |
| 24 | .navigationDestination(for: FolderRoute.self) { route in | 27 | .navigationDestination(for: FolderRoute.self) { route in |
| 25 | List { FolderContents(workspace: workspace, root: route.root, folder: route.folder) } | 28 | FolderPage(workspace: workspace, session: session, route: route) |
| 26 | .navigationTitle((route.folder as NSString).lastPathComponent) | ||
| 27 | } | 29 | } |
| 30 | .confirmDeletion($deleting, workspace: workspace, session: session) | ||
| 28 | .overlay { | 31 | .overlay { |
| 29 | if workspace.rootPaths.isEmpty { | 32 | if workspace.rootPaths.isEmpty { |
| 30 | ContentUnavailableView { | 33 | ContentUnavailableView { |
| @@ -55,6 +58,40 @@ struct FoldersScreen: View { | |||
| 55 | } | 58 | } |
| 56 | } | 59 | } |
| 57 | } | 60 | } |
| 61 | /// A subfolder's own list, asking about its own deletions. | ||
| 62 | private struct FolderPage: View { | ||
| 63 | let workspace: WorkspaceModel | ||
| 64 | let session: DocumentSession | ||
| 65 | let route: FolderRoute | ||
| 66 | @State private var deleting: String? | ||
| 67 | |||
| 68 | var body: some View { | ||
| 69 | List { FolderContents(workspace: workspace, root: route.root, folder: route.folder, deleting: $deleting) } | ||
| 70 | .navigationTitle((route.folder as NSString).lastPathComponent) | ||
| 71 | .confirmDeletion($deleting, workspace: workspace, session: session) | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | private extension View { | ||
| 76 | /// Asks before deleting the file in `deleting`, closing it first. | ||
| 77 | func confirmDeletion(_ deleting: Binding<String?>, workspace: WorkspaceModel, session: DocumentSession) -> some View { | ||
| 78 | let name = deleting.wrappedValue.map { ($0 as NSString).lastPathComponent } ?? "" | ||
| 79 | return confirmationDialog("Delete “\(name)”?", isPresented: Binding { deleting.wrappedValue != nil } set: { if !$0 { deleting.wrappedValue = nil } }, | ||
| 80 | titleVisibility: .visible) { | ||
| 81 | Button("Delete", role: .destructive) { | ||
| 82 | guard let path = deleting.wrappedValue else { return } | ||
| 83 | deleting.wrappedValue = nil | ||
| 84 | session.kill(path) | ||
| 85 | Task { | ||
| 86 | do { try await workspace.trash(path) } catch { workspace.lastError = "Can't delete \(name): \(error.localizedDescription)" } | ||
| 87 | } | ||
| 88 | } | ||
| 89 | } message: { | ||
| 90 | Text("The whole file is removed. Files in iCloud Drive go to Recently Deleted in the Files app.") | ||
| 91 | } | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 58 | /// A subfolder to show, relative to its root. | 95 | /// A subfolder to show, relative to its root. |
| 59 | struct FolderRoute: Hashable { | 96 | struct FolderRoute: Hashable { |
| 60 | let root: String | 97 | let root: String |
| @@ -67,6 +104,7 @@ private struct FolderContents: View { | |||
| 67 | let workspace: WorkspaceModel | 104 | let workspace: WorkspaceModel |
| 68 | let root: String | 105 | let root: String |
| 69 | let folder: String | 106 | let folder: String |
| 107 | @Binding var deleting: String? | ||
| 70 | 108 | ||
| 71 | private var prefix: String { folder.isEmpty ? "" : folder + "/" } | 109 | private var prefix: String { folder.isEmpty ? "" : folder + "/" } |
| 72 | 110 | ||
| @@ -91,6 +129,12 @@ private struct FolderContents: View { | |||
| 91 | NavigationLink(value: ReaderRoute.file(file.path)) { | 129 | NavigationLink(value: ReaderRoute.file(file.path)) { |
| 92 | Label(file.name, systemImage: "doc.text") | 130 | Label(file.name, systemImage: "doc.text") |
| 93 | } | 131 | } |
| 132 | .swipeActions(edge: .trailing) { | ||
| 133 | Button("Delete", systemImage: "trash") { deleting = file.path }.tint(.red) | ||
| 134 | } | ||
| 135 | .contextMenu { | ||
| 136 | Button("Delete…", systemImage: "trash", role: .destructive) { deleting = file.path } | ||
| 137 | } | ||
| 94 | } | 138 | } |
| 95 | ForEach(pending.filter { !$0.contains("/") }, id: \.self) { name in | 139 | ForEach(pending.filter { !$0.contains("/") }, id: \.self) { name in |
| 96 | Label(name, systemImage: "icloud.and.arrow.down").foregroundStyle(.secondary) | 140 | Label(name, systemImage: "icloud.and.arrow.down").foregroundStyle(.secondary) |
Sources/OrgstarMobile/MobileModel.swift +4
| @@ -65,6 +65,10 @@ final class MobileModel { | |||
| 65 | let settings = OrgPreferences.orgSettings() | 65 | let settings = OrgPreferences.orgSettings() |
| 66 | do { | 66 | do { |
| 67 | let workspace = try WorkspaceModel(directory: WorkspaceModel.defaultDirectory, settings: .with(todoKeywords: settings)) | 67 | let workspace = try WorkspaceModel(directory: WorkspaceModel.defaultDirectory, settings: .with(todoKeywords: settings)) |
| 68 | // Recently Deleted where the folder's provider keeps one (iCloud Drive); otherwise gone. | ||
| 69 | workspace.trasher = { url in | ||
| 70 | do { try FileManager.default.trashItem(at: url, resultingItemURL: nil) } catch { try FileManager.default.removeItem(at: url) } | ||
| 71 | } | ||
| 68 | self.workspace = workspace | 72 | self.workspace = workspace |
| 69 | agenda = AgendaModel(workspace: workspace) | 73 | agenda = AgendaModel(workspace: workspace) |
| 70 | failure = nil | 74 | failure = nil |
Sources/OrgstarMobile/OrgstarMobileApp.swift +1 −1
| @@ -162,7 +162,7 @@ struct RootView: View { | |||
| 162 | } | 162 | } |
| 163 | Tab("Folders", systemImage: "folder", value: .folders) { | 163 | Tab("Folders", systemImage: "folder", value: .folders) { |
| 164 | NavigationStack { | 164 | NavigationStack { |
| 165 | FoldersScreen(workspace: workspace) | 165 | FoldersScreen(workspace: workspace, session: session) |
| 166 | .toolbar { captureButton } | 166 | .toolbar { captureButton } |
| 167 | .readerDestination(workspace: workspace, session: session) | 167 | .readerDestination(workspace: workspace, session: session) |
| 168 | } | 168 | } |
docs/manual/guide/07-agenda.org +1 −1
| @@ -567,7 +567,7 @@ The Agenda tab shows the same views from the same files, using the settings in t | |||
| 567 | - Pull down to refresh. | 567 | - Pull down to refresh. |
| 568 | - The Filter button opens a sheet: type a filter as for =/=, or tap a tag or category to cycle between Keep, Leave out and no filter. | 568 | - The Filter button opens a sheet: type a filter as for =/=, or tap a tag or category to cycle between Keep, Leave out and no filter. |
| 569 | - 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. | 569 | - 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. |
| 570 | - 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. 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. | 570 | - 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. |
| 571 | - 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. | 571 | - 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. |
| 572 | - 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. | 572 | - 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. |
| 573 | - Marking an entry done and rescheduling one give haptic feedback. | 573 | - Marking an entry done and rescheduling one give haptic feedback. |
docs/manual/guide/14-ios.org +3 −1
| @@ -22,6 +22,8 @@ orgstar on iOS works on folders you choose, in iCloud Drive or in another app's | |||
| 22 | 22 | ||
| 23 | orgstar keeps access to the folder across launches. Each folder appears as a section listing its =.org= files by their path inside the folder. Remove Folder at the end of a section removes it from orgstar; the files stay where they are. | 23 | orgstar keeps access to the folder across launches. Each folder appears as a section listing its =.org= files by their path inside the folder. Remove Folder at the end of a section removes it from orgstar; the files stay where they are. |
| 24 | 24 | ||
| 25 | Swipe left on a file, or touch and hold it, to delete it. orgstar asks first. A file in iCloud Drive goes to Recently Deleted in the Files app; elsewhere it is removed. | ||
| 26 | |||
| 25 | Files that iCloud hasn't downloaded to the device yet appear in grey with a cloud icon. orgstar asks iCloud to download them and lists them as files once they arrive. | 27 | Files that iCloud hasn't downloaded to the device yet appear in grey with a cloud icon. orgstar asks iCloud to download them and lists them as files once they arrive. |
| 26 | 28 | ||
| 27 | orgstar sees changes made by iCloud and by apps that use the system's file coordination, and reads every folder again each time you return to the app, since not every sync app reports its changes. An open file takes in changes from disk as described in [[file:15-alongside-emacs.org][Working alongside Emacs and other tools]]. | 29 | orgstar sees changes made by iCloud and by apps that use the system's file coordination, and reads every folder again each time you return to the app, since not every sync app reports its changes. An open file takes in changes from disk as described in [[file:15-alongside-emacs.org][Working alongside Emacs and other tools]]. |
| @@ -159,7 +161,7 @@ The Agenda tab shows the agenda over all your folders, with the span and start d | |||
| 159 | - Filter :: keep or leave out tags and categories of the entries shown, or type a filter as Org's =/= takes it: =+keep= and =-drop= tags or categories, =<0:30= for effort, =/regexp/=. The filter in use shows above the bar. | 161 | - Filter :: keep or leave out tags and categories of the entries shown, or type a filter as Org's =/= takes it: =+keep= and =-drop= tags or categories, =<0:30= for effort, =/regexp/=. The filter in use shows above the bar. |
| 160 | - + on a day's header :: captures an entry scheduled on that day (see [[file:08-capture.org][Capture]]). | 162 | - + on a day's header :: captures an entry scheduled on that day (see [[file:08-capture.org][Capture]]). |
| 161 | - Tap :: an entry to read it, at its heading. | 163 | - Tap :: an entry to read it, at its heading. |
| 162 | - Swipe left :: on a TODO entry for Done, which sets the first done keyword of its sequence, or Next State. | 164 | - 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. |
| 163 | - 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. | 165 | - 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. |
| 164 | - 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 files; the entry goes to the end of the one you choose. Refiling under a heading is Mac only. | 166 | - 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 files; the entry goes to the end of the one you choose. Refiling under a heading is Mac only. |
| 165 | 167 | ||