From 3d4000a493992d7c2aaf36122325ccb1bcd2f3c0 Mon Sep 17 00:00:00 2001 From: phlpsong Date: Wed, 20 Mar 2024 22:49:32 +0800 Subject: [PATCH] fix: show alert when no discard files --- .../SourceControlNavigatorToolbarBottom.swift | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/CodeEdit/Features/NavigatorArea/SourceControlNavigator/Views/SourceControlNavigatorToolbarBottom.swift b/CodeEdit/Features/NavigatorArea/SourceControlNavigator/Views/SourceControlNavigatorToolbarBottom.swift index ffa8feb0b6..0135cd2385 100644 --- a/CodeEdit/Features/NavigatorArea/SourceControlNavigator/Views/SourceControlNavigatorToolbarBottom.swift +++ b/CodeEdit/Features/NavigatorArea/SourceControlNavigator/Views/SourceControlNavigatorToolbarBottom.swift @@ -12,8 +12,9 @@ struct SourceControlNavigatorToolbarBottom: View { @EnvironmentObject var sourceControlManager: SourceControlManager @State private var text = "" - @State private var stashChangesIsPresented: Bool = false - @State private var noChangesToStashIsPresented: Bool = false + @State private var stashChangesIsPresented = false + @State private var noChangesToStashIsPresented = false + @State private var noDiscardChangesIsPresented = false var body: some View { HStack(spacing: 5) { @@ -49,6 +50,11 @@ struct SourceControlNavigatorToolbarBottom: View { private var sourceControlMenu: some View { Menu { Button("Discard All Changes...") { + guard let sourceControlManager = workspace.sourceControlManager else { return } + if sourceControlManager.changedFiles.isEmpty { + noDiscardChangesIsPresented = true + return + } if discardChangesDialog() { workspace.sourceControlManager?.discardAllChanges() } @@ -75,6 +81,11 @@ struct SourceControlNavigatorToolbarBottom: View { } message: { Text("There are no uncommitted changes in the local repository for this project.") } + .alert("Cannot Discard Changes", isPresented: $noDiscardChangesIsPresented) { + Button("OK", role: .cancel) {} + } message: { + Text("There are no uncommitted changes in the local repository for this project.") + } } /// Renders a Discard Changes Dialog