Uninstall Mac apps with every file they leave behind, and see why each belongs. Free up space, fine-tune macOS, and set up Terminal.
Swift cache-cleanercleanerclideveloper-toolsdisk-cleanupdisk-spaceduplicate-finderhomebrewliquid-glassmac-cleanermacosmacos-appmacos-golden-gatemacos-tahoemacos-tweaksswiftswiftuiterminal-themesuninstalluninstaller
Deselect All clears a row selected by hand
Țugui Dragoș6a00c0e437cb
diff --git a/Packages/PeelCore/Sources/PeelCore/Removal/SelectAll.swift b/Packages/PeelCore/Sources/PeelCore/Removal/SelectAll.swiftnew file mode 100644index 00000000..5d639f7f--- /dev/null+++ b/Packages/PeelCore/Sources/PeelCore/Removal/SelectAll.swift@@ -0,0 +1,12 @@+/// What a section's Select All and Deselect All do to the selection.+public enum SelectAll {+ public static func isAllSelected<ID: Hashable>(_ selectable: [ID], in selection: Set<ID>) -> Bool {+ selectable.allSatisfy(selection.contains)+ }++ /// Select All adds the rows that can be selected. Deselect All takes out every row of the section, a row+ /// selected by hand that Select All leaves alone included.+ public static func toggled<ID: Hashable>(_ selection: Set<ID>, selectable: [ID], rows: [ID]) -> Set<ID> {+ isAllSelected(selectable, in: selection) ? selection.subtracting(rows) : selection.union(selectable)+ }+}diff --git a/Packages/PeelCore/Tests/PeelCoreTests/SelectAllTests.swift b/Packages/PeelCore/Tests/PeelCoreTests/SelectAllTests.swiftnew file mode 100644index 00000000..9547b476--- /dev/null+++ b/Packages/PeelCore/Tests/PeelCoreTests/SelectAllTests.swift@@ -0,0 +1,28 @@+import Foundation+@testable import PeelCore+import Testing++struct SelectAllTests {+ private let repository = URL(filePath: "/tmp/org.example.Work")+ private let cache = URL(filePath: "/tmp/org.example.Cache")+ private let log = URL(filePath: "/tmp/org.example.Log")+ private let elsewhere = URL(filePath: "/tmp/org.example.Elsewhere")++ /// A row held back from Select All can still be selected by hand, and Deselect All takes it out with the rest:+ /// otherwise it would stay selected unseen and move with the next small file.+ @Test func deselectAllTakesOutARowSelectedByHand() {+ let rows = [repository, cache, log]+ let selectable = [cache, log]+ let selection: Set = [repository, cache, log, elsewhere]+ #expect(SelectAll.isAllSelected(selectable, in: selection))+ #expect(SelectAll.toggled(selection, selectable: selectable, rows: rows) == [elsewhere])+ }++ @Test func selectAllAddsOnlyWhatCanBeSelected() {+ let rows = [repository, cache, log]+ let selectable = [cache, log]+ let selection: Set = [cache]+ #expect(!SelectAll.isAllSelected(selectable, in: selection))+ #expect(SelectAll.toggled(selection, selectable: selectable, rows: rows) == [cache, log])+ }+}diff --git a/Peel/Views/AppDetailView.swift b/Peel/Views/AppDetailView.swiftindex b47dd0d5..7bcd176d 100644--- a/Peel/Views/AppDetailView.swift+++ b/Peel/Views/AppDetailView.swift@@ -278,7 +278,8 @@ struct AppDetailView: View {"Everything selected here goes to the Trash together when you click Move to Trash. Nothing is deleted outright: History can put it back while it’s in the Trash."),movable: plan.recommendedMovable,- selectable: recommendedSelectable+ selectable: recommendedSelectable,+ rows: recommendedRows)}}@@ -286,7 +287,11 @@ struct AppDetailView: View {/// The Recommended rows a checkbox can select, for its Select All. Review Before Removing has no Select All,/// because nothing there should be selected without being read.private var recommendedSelectable: [URL] {- ([plan.app.url] + plan.recommended.map(\.url)).filter(plan.selectable.contains)+ recommendedRows.filter(plan.selectable.contains)+ }++ private var recommendedRows: [URL] {+ [plan.app.url] + plan.recommended.map(\.url)}@ViewBuilder@@ -325,7 +330,9 @@ struct AppDetailView: View {/// A section heading with, at its other end, how many of its items can move and their total size, so the/// user sees how much is about to move without adding up the rows.- private func sectionHeader(_ title: some View, movable: (count: Int, size: SizeTotal), selectable: [URL] = []) -> some View {+ private func sectionHeader(+ _ title: some View, movable: (count: Int, size: SizeTotal), selectable: [URL] = [], rows: [URL] = []+ ) -> some View {SectionHeaderLine {title} count: {@@ -334,7 +341,7 @@ struct AppDetailView: View {.foregroundStyle(.secondary).monospacedDigit()} actions: {- SelectAllButton(selectable: selectable, selection: $plan.selectedURLs)+ SelectAllButton(selectable: selectable, rows: rows, selection: $plan.selectedURLs)}}diff --git a/Peel/Views/Cloud/CloudView.swift b/Peel/Views/Cloud/CloudView.swiftindex 782a9d1d..f22360b5 100644--- a/Peel/Views/Cloud/CloudView.swift+++ b/Peel/Views/Cloud/CloudView.swift@@ -61,7 +61,11 @@ struct CloudView: View {"Once their downloads are removed, Finder still lists these files, with a cloud beside each name. Deleting a file is different: that removes it from iCloud and from your other devices, and Peel never does it here.")} actions: {- SelectAllButton(selectable: listed.map(\.url), selection: Bindable(cloud).selectedURLs)+ SelectAllButton(+ selectable: listed.map(\.url),+ rows: listed.map(\.url),+ selection: Bindable(cloud).selectedURLs+ )}} footer: {if cloud.wasCutShort {diff --git a/Peel/Views/FileSearch/FileSearchList.swift b/Peel/Views/FileSearch/FileSearchList.swiftindex be486529..65cda2dc 100644--- a/Peel/Views/FileSearch/FileSearchList.swift+++ b/Peel/Views/FileSearch/FileSearchList.swift@@ -45,7 +45,11 @@ struct FileSearchList: View {SectionHeaderLine {Text("Files")} actions: {- SelectAllButton(selectable: Array(search.selectableURLs), selection: Bindable(search).selectedURLs)+ SelectAllButton(+ selectable: Array(search.selectableURLs),+ rows: results.files.map(\.url),+ selection: Bindable(search).selectedURLs+ )}}// Disables the section, not the list, so the list still scrolls and the user can review the selection.diff --git a/Peel/Views/History/HistoryDetailView.swift b/Peel/Views/History/HistoryDetailView.swiftindex 9505afff..b8903094 100644--- a/Peel/Views/History/HistoryDetailView.swift+++ b/Peel/Views/History/HistoryDetailView.swift@@ -178,7 +178,11 @@ struct HistoryDetailView: View {SectionHeaderLine {Text("Items")} actions: {- SelectAllButton(selectable: restorable.map(\.id), selection: Bindable(history).selectedIDs)+ SelectAllButton(+ selectable: restorable.map(\.id),+ rows: batch.records.map(\.id),+ selection: Bindable(history).selectedIDs+ )}}.disabled(history.isRestoring)diff --git a/Peel/Views/Installers/InstallerDetailView.swift b/Peel/Views/Installers/InstallerDetailView.swiftindex 634f4a82..6b5b75b9 100644--- a/Peel/Views/Installers/InstallerDetailView.swift+++ b/Peel/Views/Installers/InstallerDetailView.swift@@ -47,6 +47,7 @@ struct InstallerDetailView: View {} actions: {SelectAllButton(selectable: rows.filter { !$0.isReadOnly && $0.heldBack == nil && !($0.requiresPrivileges && !helper.canAct) }.map(\.url),+ rows: rows.map(\.url),selection: Bindable(installers).selectedURLs)}diff --git a/Peel/Views/Orphans/OrphanDetailView.swift b/Peel/Views/Orphans/OrphanDetailView.swiftindex cbe29bf7..1f3d1cda 100644--- a/Peel/Views/Orphans/OrphanDetailView.swift+++ b/Peel/Views/Orphans/OrphanDetailView.swift@@ -42,7 +42,11 @@ struct OrphanDetailView: View {SectionHeaderLine {Text("Files")} actions: {- SelectAllButton(selectable: selectableURLs, selection: Bindable(orphans).selectedURLs)+ SelectAllButton(+ selectable: selectableURLs,+ rows: group.items.map(\.url),+ selection: Bindable(orphans).selectedURLs+ )}}}diff --git a/Peel/Views/Packages/PackageDetailView.swift b/Peel/Views/Packages/PackageDetailView.swiftindex fafd3f5c..4ec43785 100644--- a/Peel/Views/Packages/PackageDetailView.swift+++ b/Peel/Views/Packages/PackageDetailView.swift@@ -45,7 +45,11 @@ struct PackageDetailView: View {SectionHeaderLine {Text("Installed Items")} actions: {- SelectAllButton(selectable: selectableURLs, selection: Bindable(packages).selectedURLs)+ SelectAllButton(+ selectable: selectableURLs,+ rows: receipt.items.map(\.url),+ selection: Bindable(packages).selectedURLs+ )}}diff --git a/Peel/Views/SelectAllButton.swift b/Peel/Views/SelectAllButton.swiftindex 2de82394..ef0eae91 100644--- a/Peel/Views/SelectAllButton.swift+++ b/Peel/Views/SelectAllButton.swift@@ -1,20 +1,19 @@+import PeelCoreimport SwiftUI-/// Selects every row of a section that can be selected, or clears them. With nothing to select it draws nothing: a-/// Select All that changes nothing reads as broken.+/// Selects every row of a section that can be selected, or clears them all. With nothing to select it draws nothing:+/// a Select All that changes nothing reads as broken.struct SelectAllButton<ID: Hashable>: View {let selectable: [ID]+ /// Every row of the section, which Deselect All clears, a row selected by hand included.+ let rows: [ID]@Binding var selection: Set<ID>var body: some View {if !selectable.isEmpty {- let isAllSelected = selectable.allSatisfy(selection.contains)+ let isAllSelected = SelectAll.isAllSelected(selectable, in: selection)Button {- if isAllSelected {- selection.subtract(selectable)- } else {- selection.formUnion(selectable)- }+ selection = SelectAll.toggled(selection, selectable: selectable, rows: rows)} label: {Text(isAllSelected ? "Deselect All" : "Select All").minimumTarget()diff --git a/Peel/Views/Space/SpaceDetailView.swift b/Peel/Views/Space/SpaceDetailView.swiftindex e6864247..9991f0fb 100644--- a/Peel/Views/Space/SpaceDetailView.swift+++ b/Peel/Views/Space/SpaceDetailView.swift@@ -122,6 +122,7 @@ struct SpaceDetailView: View {} actions: {SelectAllButton(selectable: rows.filter { plan.heldBack[$0] == nil && !isLocked($0, in: plan) },+ rows: rows,selection: Bindable(space).selectedURLs)}