Skip to content

Commit aecf3d4

Browse files
authored
Show an alert if not file changes when Discard All Changes (#1642)
fix: show alert when no discard files
1 parent 8f26014 commit aecf3d4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

CodeEdit/Features/NavigatorArea/SourceControlNavigator/Views/SourceControlNavigatorToolbarBottom.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ struct SourceControlNavigatorToolbarBottom: View {
1212
@EnvironmentObject var sourceControlManager: SourceControlManager
1313

1414
@State private var text = ""
15-
@State private var stashChangesIsPresented: Bool = false
16-
@State private var noChangesToStashIsPresented: Bool = false
15+
@State private var stashChangesIsPresented = false
16+
@State private var noChangesToStashIsPresented = false
17+
@State private var noDiscardChangesIsPresented = false
1718

1819
var body: some View {
1920
HStack(spacing: 5) {
@@ -49,6 +50,11 @@ struct SourceControlNavigatorToolbarBottom: View {
4950
private var sourceControlMenu: some View {
5051
Menu {
5152
Button("Discard All Changes...") {
53+
guard let sourceControlManager = workspace.sourceControlManager else { return }
54+
if sourceControlManager.changedFiles.isEmpty {
55+
noDiscardChangesIsPresented = true
56+
return
57+
}
5258
if discardChangesDialog() {
5359
workspace.sourceControlManager?.discardAllChanges()
5460
}
@@ -75,6 +81,11 @@ struct SourceControlNavigatorToolbarBottom: View {
7581
} message: {
7682
Text("There are no uncommitted changes in the local repository for this project.")
7783
}
84+
.alert("Cannot Discard Changes", isPresented: $noDiscardChangesIsPresented) {
85+
Button("OK", role: .cancel) {}
86+
} message: {
87+
Text("There are no uncommitted changes in the local repository for this project.")
88+
}
7889
}
7990

8091
/// Renders a Discard Changes Dialog

0 commit comments

Comments
 (0)