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.

Send every change of a selection through one method

Țugui Dragoș3cfcd49b9df4
diff --git a/Peel/Model/BulkRemovalPlan.swift b/Peel/Model/BulkRemovalPlan.swift
index b6286e25..dc51c7c3 100644
--- a/Peel/Model/BulkRemovalPlan.swift
+++ b/Peel/Model/BulkRemovalPlan.swift
@@ -105,16 +105,10 @@ final class BulkRemovalPlan {
selectedURLs = choices.update(selectedURLs, in: bulk, canUseHelper: canUseHelper)
}
- /// Selects or deselects one row. Deselecting an app's bundle keeps the app, so its files leave the selection
- /// with it (`UninstallSelection.personChanged(from:to:in:)`).
- func setSelected(_ isSelected: Bool, for url: URL) {
- var selected = selectedURLs
- if isSelected {
- selected.insert(url)
- } else {
- selected.remove(url)
- }
- selectedURLs = bulk.map { choices.personChanged(from: selectedURLs, to: selected, in: $0) } ?? selected
+ /// Deselecting an app's bundle keeps the app, so its files leave the selection with it
+ /// (`UninstallSelection.personChanged(from:to:in:)`).
+ func select(_ selection: Set<URL>) {
+ selectedURLs = bulk.map { choices.personChanged(from: selectedURLs, to: selection, in: $0) } ?? selection
}
/// Moves what `request` asked about, whatever has been selected since.
diff --git a/Peel/Model/RowSelection.swift b/Peel/Model/RowSelection.swift
index f72b50ec..c6bf9112 100644
--- a/Peel/Model/RowSelection.swift
+++ b/Peel/Model/RowSelection.swift
@@ -6,7 +6,8 @@ import Foundation
/// SwiftUI treats every row as changed and rebuilds all of them on every change.
protocol RowSelection: AnyObject {
var selectedURLs: Set<URL> { get set }
- func setSelected(_ isSelected: Bool, for url: URL)
+ /// Makes `selection` what is selected, as the person chose it: a click and a Select menu both come here.
+ func select(_ selection: Set<URL>)
}
extension RowSelection {
@@ -14,12 +15,18 @@ extension RowSelection {
selectedURLs.contains(url)
}
+ func select(_ selection: Set<URL>) {
+ selectedURLs = selection
+ }
+
func setSelected(_ isSelected: Bool, for url: URL) {
+ var selection = selectedURLs
if isSelected {
- selectedURLs.insert(url)
+ selection.insert(url)
} else {
- selectedURLs.remove(url)
+ selection.remove(url)
}
+ select(selection)
}
}