Skip to content

armgit / peel

Public Imported from GitHub
0

Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.

Keep the Move to Trash question on screen however many pages are selected

Țugui Dragoș2a2bb47c91f9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 761fd56f..2a47a501 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -180,6 +180,11 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.
- Lists what an app with a tool's identifier left while another such app is installed.
+#### Orphaned Files and Storage
+
+- With many pages selected, the Move to Trash question no longer runs past the bottom of the screen and takes its
+ buttons with it: it names the first few pages and counts the items of the others, which "Selected on N pages" lists.
+
#### Duplicates and File Search
- What they move goes as one removal, so a run that was interrupted shows in History as one interrupted removal.
diff --git a/GUIDE.md b/GUIDE.md
index 1de0db8d..377a09ca 100644
--- a/GUIDE.md
+++ b/GUIDE.md
@@ -201,7 +201,7 @@ Search stays selected while you look at the others, and Move to Trash on any of
entry in History. These pages select nothing for you, but for the copies Duplicates selects after a scan you start. A
page counts once you have opened it, or once the Select menu in a tool's toolbar, which selects on every page the
tool lists, has selected something there. The bar at the foot of the page says how many pages that is, and lists
-them.
+them. Move to Trash asks first, naming the first few pages and how many items the others hold.
## Look after your Mac
diff --git a/Peel/Views/RemovalBar.swift b/Peel/Views/RemovalBar.swift
index e565a75a..4b943914 100644
--- a/Peel/Views/RemovalBar.swift
+++ b/Peel/Views/RemovalBar.swift
@@ -278,17 +278,28 @@ struct RemovalBar: View {
}
}
- /// Under the question: the page's own words when only its selection moves, and otherwise a line for each page.
+ /// Under the question: the page's own words when only its selection moves, and otherwise a line for each of the
+ /// first pages, as many as an alert lists, and how many items the others hold. "Selected on N pages" lists all.
@ViewBuilder
private var questionMessage: some View {
if case .carried(let page, _) = purpose, question.map(\.page) == [page] {
pageMessage
} else {
- Text(verbatim: question.map(line).joined(separator: "\n"))
+ Text(verbatim: Self.lines(for: question).joined(separator: "\n"))
}
}
- private func line(_ part: CarriedSelection.Part) -> String {
+ static func lines(for parts: [CarriedSelection.Part]) -> [String] {
+ let listed = parts.prefix(RemovalFailureAlert.mostListed)
+ var lines = listed.map(line)
+ let rest = parts.dropFirst(listed.count).reduce(0) { $0 + $1.count }
+ if rest > 0 {
+ lines.append(String(inflecting: "And ^[\(rest) more item](inflect: true)."))
+ }
+ return lines
+ }
+
+ private static func line(_ part: CarriedSelection.Part) -> String {
switch part.total.reading {
case .exactly(0):
String(inflecting: "\(part.title): ^[\(part.count) item](inflect: true)")
diff --git a/PeelTests/RemovalBarTests.swift b/PeelTests/RemovalBarTests.swift
new file mode 100644
index 00000000..96510827
--- /dev/null
+++ b/PeelTests/RemovalBarTests.swift
@@ -0,0 +1,28 @@
+import Foundation
+@testable import Peel
+import PeelCore
+import Testing
+
+@MainActor
+struct RemovalBarTests {
+ private func parts(_ count: Int) -> [CarriedSelection.Part] {
+ (1...count).map { index in
+ CarriedSelection.Part(
+ page: CarriedSelection.Page(tool: "orphans", scope: "org.example.gone\(index)"),
+ title: "org.example.gone\(index)", source: "org.example.gone\(index)", sourceKey: nil,
+ sizes: [URL(filePath: "/Users/me/Library/Caches/org.example.gone\(index)"): 4_096]
+ )
+ }
+ }
+
+ @Test func listsTheFirstPagesOfALongSelectionAndCountsTheItemsOfTheRest() {
+ let lines = RemovalBar.lines(for: parts(80))
+ let most = RemovalFailureAlert.mostListed
+ #expect(lines.count == most + 1)
+ for (index, line) in lines.prefix(most).enumerated() {
+ #expect(line.hasPrefix("org.example.gone\(index + 1):"), "\(line)")
+ }
+ #expect(lines.last?.contains("76") == true, "\(lines.last ?? "")")
+ #expect(RemovalBar.lines(for: parts(most)).count == most)
+ }
+}