Skip to content

Commit

Permalink
+ Setting for swipe actions ~ Purge button adjustm
Browse files Browse the repository at this point in the history
  • Loading branch information
buresdv committed Nov 4, 2024
1 parent 258e99b commit 95dedca
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 25 deletions.
10 changes: 10 additions & 0 deletions Cork/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -36469,6 +36469,16 @@
}
}
},
"settings.general.package-details.enable-swipe-actions.toggle" : {
"localizations" : {
"en" : {
"stringUnit" : {
"state" : "translated",
"value" : "Enable swipe actions"
}
}
}
},
"settings.general.package-details.reveal-in-finder.toggle" : {
"localizations" : {
"cs" : {
Expand Down
20 changes: 14 additions & 6 deletions Cork/Views/Reusables/Uninstallation/Remove Packages Buttons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import SwiftUI
import CorkShared

/// Button for uninstalling packages
struct UninstallPackageButton: View
{
let package: BrewPackage
Expand All @@ -20,15 +21,22 @@ struct UninstallPackageButton: View
}
}

/// Button for purging packages
/// Will not display when purging is disabled
struct PurgePackageButton: View
{
@AppStorage("allowMoreCompleteUninstallations") var allowMoreCompleteUninstallations: Bool = false

let package: BrewPackage

let isCalledFromSidebar: Bool

var body: some View
{
RemovePackageButton(package: package, shouldPurge: true, isCalledFromSidebar: isCalledFromSidebar)
if allowMoreCompleteUninstallations
{
RemovePackageButton(package: package, shouldPurge: true, isCalledFromSidebar: isCalledFromSidebar)
}
}
}

Expand Down Expand Up @@ -73,17 +81,17 @@ private struct RemovePackageButton: View
}
} label: {
if shouldPurge
{
Label("action.purge-\(package.name)", systemImage: "trash")
}
else
{
Label {
Text("action.uninstall-\(package.name)")
Text("action.purge-\(package.name)")
} icon: {
Image("custom.trash.triangle.fill")
}
}
else
{
Label("action.uninstall-\(package.name)", systemImage: "trash")
}
}
}
}
6 changes: 6 additions & 0 deletions Cork/Views/Settings/Panes/General Pane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct GeneralPane: View
@AppStorage("showOldVersionsInOutdatedPackageList") var showOldVersionsInOutdatedPackageList: Bool = true

@AppStorage("enableRevealInFinder") var enableRevealInFinder: Bool = false
@AppStorage("enableSwipeActions") var enableSwipeActions: Bool = false

@AppStorage("showSearchFieldForDependenciesInPackageDetails") var showSearchFieldForDependenciesInPackageDetails: Bool = false

Expand Down Expand Up @@ -149,6 +150,11 @@ struct GeneralPane: View
{
Text("settings.general.package-details.reveal-in-finder.toggle")
}

Toggle(isOn: $enableSwipeActions)
{
Text("settings.general.package-details.enable-swipe-actions.toggle")
}
}
} label: {
Text("settings.general.package-details")
Expand Down
45 changes: 26 additions & 19 deletions Cork/Views/Sidebar/Components/Sidebar Package Row.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ struct SidebarPackageRow: View
{
let package: BrewPackage

@AppStorage("allowMoreCompleteUninstallations") var allowMoreCompleteUninstallations: Bool = false

@AppStorage("enableRevealInFinder") var enableRevealInFinder: Bool = false
@AppStorage("enableSwipeActions") var enableSwipeActions: Bool = false

@EnvironmentObject var appState: AppState
@EnvironmentObject var brewData: BrewDataStorage
Expand All @@ -29,17 +28,28 @@ struct SidebarPackageRow: View
{
contextMenuContent
}
.swipeActions(edge: .leading, allowsFullSwipe: false)
{
tagUntagButton
}
.swipeActions(edge: .trailing, allowsFullSwipe: false)
{
UninstallPackageButton(package: package, isCalledFromSidebar: true)
.tint(.orange)

PurgePackageButton(package: package, isCalledFromSidebar: true)
.tint(.red)
.modify
{ viewProxy in
if enableSwipeActions
{
viewProxy
.swipeActions(edge: .leading, allowsFullSwipe: false)
{
tagUntagButton
}
.swipeActions(edge: .trailing, allowsFullSwipe: false)
{
PurgePackageButton(package: package, isCalledFromSidebar: true)
.tint(.red)

UninstallPackageButton(package: package, isCalledFromSidebar: true)
.tint(.orange)
}
}
else
{
viewProxy
}
}
}

Expand All @@ -60,20 +70,17 @@ struct SidebarPackageRow: View
Label(package.isTagged ? "sidebar.section.all.contextmenu.untag-\(package.name)" : "sidebar.section.all.contextmenu.tag-\(package.name)", systemImage: package.isTagged ? "tag.slash" : "tag")
}
}

@ViewBuilder
var contextMenuContent: some View
{
tagUntagButton

Divider()

UninstallPackageButton(package: package, isCalledFromSidebar: true)

if allowMoreCompleteUninstallations
{
PurgePackageButton(package: package, isCalledFromSidebar: true)
}
PurgePackageButton(package: package, isCalledFromSidebar: true)

if enableRevealInFinder
{
Expand Down

0 comments on commit 95dedca

Please sign in to comment.