1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-04 23:37:41 +02:00

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.
This commit is contained in:
Stefan Haller 2024-06-23 12:46:59 +02:00 committed by GitHub
commit a5620ebe3a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 51 additions and 44 deletions

View File

@ -1062,60 +1062,65 @@ func (self *FilesController) remove(selectedNodes []*filetree.FileNode) error {
selectedNodes = normalisedSelectedNodes(selectedNodes) selectedNodes = normalisedSelectedNodes(selectedNodes)
menuItems := []*types.MenuItem{ discardAllChangesItem := types.MenuItem{
{ Label: self.c.Tr.DiscardAllChanges,
Label: self.c.Tr.DiscardAllChanges, OnPress: func() error {
OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInFile)
self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInFile)
if self.context().IsSelectingRange() { if self.context().IsSelectingRange() {
defer self.context().CancelRangeSelect() defer self.context().CancelRangeSelect()
}
for _, node := range selectedNodes {
if err := self.c.Git().WorkingTree.DiscardAllDirChanges(node); err != nil {
return err
} }
}
for _, node := range selectedNodes { return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
if err := self.c.Git().WorkingTree.DiscardAllDirChanges(node); err != nil {
return err
}
}
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
},
Key: self.c.KeybindingsOpts().GetKey(self.c.UserConfig.Keybinding.Files.ConfirmDiscard),
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.DiscardAllTooltip,
map[string]string{
"path": self.formattedPaths(selectedNodes),
},
),
}, },
Key: self.c.KeybindingsOpts().GetKey(self.c.UserConfig.Keybinding.Files.ConfirmDiscard),
Tooltip: utils.ResolvePlaceholderString(
self.c.Tr.DiscardAllTooltip,
map[string]string{
"path": self.formattedPaths(selectedNodes),
},
),
} }
if someNodesHaveStagedChanges(selectedNodes) && someNodesHaveUnstagedChanges(selectedNodes) { discardUnstagedChangesItem := types.MenuItem{
menuItems = append(menuItems, &types.MenuItem{ Label: self.c.Tr.DiscardUnstagedChanges,
Label: self.c.Tr.DiscardUnstagedChanges, OnPress: func() error {
OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.DiscardAllUnstagedChangesInFile)
self.c.LogAction(self.c.Tr.Actions.DiscardAllUnstagedChangesInFile)
if self.context().IsSelectingRange() { if self.context().IsSelectingRange() {
defer self.context().CancelRangeSelect() defer self.context().CancelRangeSelect()
}
for _, node := range selectedNodes {
if err := self.c.Git().WorkingTree.DiscardUnstagedDirChanges(node); err != nil {
return err
} }
}
for _, node := range selectedNodes { return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}})
if err := self.c.Git().WorkingTree.DiscardUnstagedDirChanges(node); err != nil { },
return err Key: 'u',
} Tooltip: utils.ResolvePlaceholderString(
} self.c.Tr.DiscardUnstagedTooltip,
map[string]string{
return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}}) "path": self.formattedPaths(selectedNodes),
}, },
Key: 'u', ),
Tooltip: utils.ResolvePlaceholderString( }
self.c.Tr.DiscardUnstagedTooltip,
map[string]string{ if !someNodesHaveStagedChanges(selectedNodes) || !someNodesHaveUnstagedChanges(selectedNodes) {
"path": self.formattedPaths(selectedNodes), discardUnstagedChangesItem.DisabledReason = &types.DisabledReason{Text: self.c.Tr.DiscardUnstagedDisabled}
}, }
),
}) menuItems := []*types.MenuItem{
&discardAllChangesItem,
&discardUnstagedChangesItem,
} }
return self.c.Menu(types.CreateMenuOptions{Title: self.c.Tr.DiscardChangesTitle, Items: menuItems}) return self.c.Menu(types.CreateMenuOptions{Title: self.c.Tr.DiscardChangesTitle, Items: menuItems})

View File

@ -175,6 +175,7 @@ type TranslationSet struct {
UndoMergeResolveTooltip string UndoMergeResolveTooltip string
DiscardAllTooltip string DiscardAllTooltip string
DiscardUnstagedTooltip string DiscardUnstagedTooltip string
DiscardUnstagedDisabled string
Pop string Pop string
StashPopTooltip string StashPopTooltip string
Drop string Drop string
@ -1143,6 +1144,7 @@ func EnglishTranslationSet() TranslationSet {
UndoMergeResolveTooltip: "Undo last merge conflict resolution.", UndoMergeResolveTooltip: "Undo last merge conflict resolution.",
DiscardAllTooltip: "Discard both staged and unstaged changes in '{{.path}}'.", DiscardAllTooltip: "Discard both staged and unstaged changes in '{{.path}}'.",
DiscardUnstagedTooltip: "Discard unstaged changes in '{{.path}}'.", DiscardUnstagedTooltip: "Discard unstaged changes in '{{.path}}'.",
DiscardUnstagedDisabled: "The selected items don't have both staged and unstaged changes.",
Pop: "Pop", Pop: "Pop",
StashPopTooltip: "Apply the stash entry to your working directory and remove the stash entry.", StashPopTooltip: "Apply the stash entry to your working directory and remove the stash entry.",
Drop: "Drop", Drop: "Drop",