Skip to content

Commit a5620eb

Browse files
authored
Always show the "Discard unchanged changes" menu item (#3683)
Always show the "Discard unchanged changes" menu item in the Discard menu, just strike it through if not applicable. This will hopefully help with confusion about the meaning of "all" in the "Discard all changes" entry; some people misunderstand this to mean all changes in the working copy. Seeing the "Discard unstaged changes" item next to it hopefully makes it clearer that "all" is meant in contrast to that.
2 parents a08c86c + 1b245ef commit a5620eb

File tree

2 files changed

+49
-42
lines changed

2 files changed

+49
-42
lines changed

pkg/gui/controllers/files_controller.go

Lines changed: 47 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,60 +1062,65 @@ func (self *FilesController) remove(selectedNodes []*filetree.FileNode) error {
10621062

10631063
selectedNodes = normalisedSelectedNodes(selectedNodes)
10641064

1065-
menuItems := []*types.MenuItem{
1066-
{
1067-
Label: self.c.Tr.DiscardAllChanges,
1068-
OnPress: func() error {
1069-
self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInFile)
1065+
discardAllChangesItem := types.MenuItem{
1066+
Label: self.c.Tr.DiscardAllChanges,
1067+
OnPress: func() error {
1068+
self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInFile)
10701069

1071-
if self.context().IsSelectingRange() {
1072-
defer self.context().CancelRangeSelect()
1073-
}
1070+
if self.context().IsSelectingRange() {
1071+
defer self.context().CancelRangeSelect()
1072+
}
10741073

1075-
for _, node := range selectedNodes {
1076-
if err := self.c.Git().WorkingTree.DiscardAllDirChanges(node); err != nil {
1077-
return err
1078-
}
1074+
for _, node := range selectedNodes {
1075+
if err := self.c.Git().WorkingTree.DiscardAllDirChanges(node); err != nil {
1076+
return err
10791077
}
1078+
}
10801079

1081-
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
1082-
},
1083-
Key: self.c.KeybindingsOpts().GetKey(self.c.UserConfig.Keybinding.Files.ConfirmDiscard),
1084-
Tooltip: utils.ResolvePlaceholderString(
1085-
self.c.Tr.DiscardAllTooltip,
1086-
map[string]string{
1087-
"path": self.formattedPaths(selectedNodes),
1088-
},
1089-
),
1080+
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
10901081
},
1082+
Key: self.c.KeybindingsOpts().GetKey(self.c.UserConfig.Keybinding.Files.ConfirmDiscard),
1083+
Tooltip: utils.ResolvePlaceholderString(
1084+
self.c.Tr.DiscardAllTooltip,
1085+
map[string]string{
1086+
"path": self.formattedPaths(selectedNodes),
1087+
},
1088+
),
10911089
}
10921090

1093-
if someNodesHaveStagedChanges(selectedNodes) && someNodesHaveUnstagedChanges(selectedNodes) {
1094-
menuItems = append(menuItems, &types.MenuItem{
1095-
Label: self.c.Tr.DiscardUnstagedChanges,
1096-
OnPress: func() error {
1097-
self.c.LogAction(self.c.Tr.Actions.DiscardAllUnstagedChangesInFile)
1091+
discardUnstagedChangesItem := types.MenuItem{
1092+
Label: self.c.Tr.DiscardUnstagedChanges,
1093+
OnPress: func() error {
1094+
self.c.LogAction(self.c.Tr.Actions.DiscardAllUnstagedChangesInFile)
10981095

1099-
if self.context().IsSelectingRange() {
1100-
defer self.context().CancelRangeSelect()
1101-
}
1096+
if self.context().IsSelectingRange() {
1097+
defer self.context().CancelRangeSelect()
1098+
}
11021099

1103-
for _, node := range selectedNodes {
1104-
if err := self.c.Git().WorkingTree.DiscardUnstagedDirChanges(node); err != nil {
1105-
return err
1106-
}
1100+
for _, node := range selectedNodes {
1101+
if err := self.c.Git().WorkingTree.DiscardUnstagedDirChanges(node); err != nil {
1102+
return err
11071103
}
1104+
}
11081105

1109-
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
1106+
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
1107+
},
1108+
Key: 'u',
1109+
Tooltip: utils.ResolvePlaceholderString(
1110+
self.c.Tr.DiscardUnstagedTooltip,
1111+
map[string]string{
1112+
"path": self.formattedPaths(selectedNodes),
11101113
},
1111-
Key: 'u',
1112-
Tooltip: utils.ResolvePlaceholderString(
1113-
self.c.Tr.DiscardUnstagedTooltip,
1114-
map[string]string{
1115-
"path": self.formattedPaths(selectedNodes),
1116-
},
1117-
),
1118-
})
1114+
),
1115+
}
1116+
1117+
if !someNodesHaveStagedChanges(selectedNodes) || !someNodesHaveUnstagedChanges(selectedNodes) {
1118+
discardUnstagedChangesItem.DisabledReason = &types.DisabledReason{Text: self.c.Tr.DiscardUnstagedDisabled}
1119+
}
1120+
1121+
menuItems := []*types.MenuItem{
1122+
&discardAllChangesItem,
1123+
&discardUnstagedChangesItem,
11191124
}
11201125

11211126
return self.c.Menu(types.CreateMenuOptions{Title: self.c.Tr.DiscardChangesTitle, Items: menuItems})

pkg/i18n/english.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ type TranslationSet struct {
175175
UndoMergeResolveTooltip string
176176
DiscardAllTooltip string
177177
DiscardUnstagedTooltip string
178+
DiscardUnstagedDisabled string
178179
Pop string
179180
StashPopTooltip string
180181
Drop string
@@ -1143,6 +1144,7 @@ func EnglishTranslationSet() TranslationSet {
11431144
UndoMergeResolveTooltip: "Undo last merge conflict resolution.",
11441145
DiscardAllTooltip: "Discard both staged and unstaged changes in '{{.path}}'.",
11451146
DiscardUnstagedTooltip: "Discard unstaged changes in '{{.path}}'.",
1147+
DiscardUnstagedDisabled: "The selected items don't have both staged and unstaged changes.",
11461148
Pop: "Pop",
11471149
StashPopTooltip: "Apply the stash entry to your working directory and remove the stash entry.",
11481150
Drop: "Drop",

0 commit comments

Comments
 (0)