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.

Offer to move the rest when open apps keep part of a selection

Țugui Dragoș09d53483cad9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d2241cc2..5769ec73 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -56,7 +56,7 @@ its changes the way [Keep a Changelog](https://keepachangelog.com/) suggests.
#### Moving to the Trash from several pages
- When open apps keep part of what is selected, the alert names them all and offers Deselect Them, which deselects
- only the parts they keep.
+ only the parts they keep, and Move the Rest, which moves the other parts after the usual question.
### Changed
diff --git a/Localization/Peel/Localizable.xcstrings b/Localization/Peel/Localizable.xcstrings
index 5177c640..e2c5e0f1 100644
--- a/Localization/Peel/Localizable.xcstrings
+++ b/Localization/Peel/Localizable.xcstrings
@@ -88214,6 +88214,113 @@
}
}
},
+ "Move the Rest" : {
+ "comment" : "A button of the alert that names the open apps keeping part of a selection made on several pages. It asks before moving the parts no open app keeps, and leaves the others selected.",
+ "localizations" : {
+ "cs" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Přesunout ostatní"
+ }
+ },
+ "de" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Rest verschieben"
+ }
+ },
+ "es" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Trasladar el resto"
+ }
+ },
+ "fr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Déplacer le reste"
+ }
+ },
+ "it" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Sposta il resto"
+ }
+ },
+ "ja" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "残りをゴミ箱に入れる"
+ }
+ },
+ "ko" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "나머지 이동"
+ }
+ },
+ "nl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Verplaats de rest"
+ }
+ },
+ "pl" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Przenieś resztę"
+ }
+ },
+ "pt" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Mover o Restante"
+ }
+ },
+ "ro" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Mutați restul"
+ }
+ },
+ "ru" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Переместить остальное"
+ }
+ },
+ "sv" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Flytta resten"
+ }
+ },
+ "tr" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Geri Kalanını Taşı"
+ }
+ },
+ "uk" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "Перемістити решту"
+ }
+ },
+ "zh-Hans" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "移走其余项目"
+ }
+ },
+ "zh-Hant" : {
+ "stringUnit" : {
+ "state" : "translated",
+ "value" : "移動其餘項目"
+ }
+ }
+ }
+ },
"Move the settings saved for %@ on %@ to the Trash?" : {
"localizations" : {
"cs" : {
diff --git a/Peel/Model/SelectionCarrier.swift b/Peel/Model/SelectionCarrier.swift
index a578bf74..d7974064 100644
--- a/Peel/Model/SelectionCarrier.swift
+++ b/Peel/Model/SelectionCarrier.swift
@@ -80,6 +80,12 @@ final class SelectionCarrier {
parts.compactMap { part in self.tool(of: part)?.appToQuit(for: part).map { (part, $0) } }
}
+ /// The parts no open app keeps, which can move while the others wait for their apps to quit.
+ func free(among parts: [CarriedSelection.Part]) -> [CarriedSelection.Part] {
+ let kept = Set(kept(among: parts).map(\.part))
+ return parts.filter { !kept.contains($0) }
+ }
+
func deselect(_ part: CarriedSelection.Part) {
tool(of: part)?.deselect(part)
}
diff --git a/Peel/Views/RemovalBar.swift b/Peel/Views/RemovalBar.swift
index 950e15b3..1e678bfa 100644
--- a/Peel/Views/RemovalBar.swift
+++ b/Peel/Views/RemovalBar.swift
@@ -12,6 +12,7 @@ struct RemovalBar: View {
@State private var isAsking = false
/// The open apps that keep part of the selection from moving, and those parts.
@State private var kept: (apps: [String], parts: [CarriedSelection.Part]) = ([], [])
+ @State private var rest: [CarriedSelection.Part] = []
@State private var isAskingToQuit = false
@State private var isShowingPages = false
/// The page's own words under the question, worked out when Move to Trash was pressed.
@@ -266,6 +267,10 @@ struct RemovalBar: View {
Button("Deselect Them") {
for part in kept.parts { carrier.deselect(part) }
}
+ if !rest.isEmpty {
+ // The question opens once the alert has closed: one window shows one of them at a time.
+ Button("Move the Rest") { Task { askToMove(rest) } }
+ }
Button("OK", role: .cancel) {}
}
}
@@ -284,21 +289,26 @@ struct RemovalBar: View {
return Text("Quit \(RemovalFailureAlert.listed(kept.apps)) before removing their files.")
}
- /// Asks before moving anything, unless open apps keep some of the parts: then nothing moves until they quit or
- /// their parts are deselected, which the alert offers.
+ /// Asks before moving anything, unless open apps keep some of the parts: then they wait until the apps quit or
+ /// their parts are deselected, and the alert offers to move the rest meanwhile.
private func ask(about parts: [CarriedSelection.Part]) {
let keptNow = carrier.kept(among: parts)
if !keptNow.isEmpty {
var named: Set<String> = []
kept = (keptNow.map(\.app).filter { named.insert($0).inserted }, keptNow.map(\.part))
+ rest = carrier.free(among: parts)
isAskingToQuit = true
} else {
- question = parts
- if case .carried(_, let message) = purpose {
- pageMessage = message?()
- }
- isAsking = true
+ askToMove(parts)
+ }
+ }
+
+ private func askToMove(_ parts: [CarriedSelection.Part]) {
+ question = parts
+ if case .carried(_, let message) = purpose {
+ pageMessage = message?()
}
+ isAsking = true
}
/// Under the question: the page's own words when only its selection moves, and otherwise a line for each of the
diff --git a/PeelTests/SelectionCarrierTests.swift b/PeelTests/SelectionCarrierTests.swift
index 04d55b02..eb7d6952 100644
--- a/PeelTests/SelectionCarrierTests.swift
+++ b/PeelTests/SelectionCarrierTests.swift
@@ -44,5 +44,6 @@ struct SelectionCarrierTests {
#expect(kept.map(\.app) == ["Google Chrome", "Slack"])
#expect(kept.map(\.part.page.scope) == ["chrome", "slack"])
+ #expect(carrier.free(among: [part("chrome"), part("npm"), part("slack")]).map(\.page.scope) == ["npm"])
}
}