diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-06-21 21:15:28 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2024-06-23 12:43:34 +0200 |
commit | 1b245ef5f6b7d78ff5077be4899a0a370f5f3781 (patch) | |
tree | 6a05323efe5367962f16b1ac31340c3f3bbcacde /pkg | |
parent | a08c86c18289548c1b22ebfc50d2ad8c65f8e4dc (diff) |
Always show the "Discard unchanged changes" menu item
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.
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/controllers/files_controller.go | 89 | ||||
-rw-r--r-- | pkg/i18n/english.go | 2 |
2 files changed, 49 insertions, 42 deletions
diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index b71991fc2..81d3f4cf0 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -1062,60 +1062,65 @@ func (self *FilesController) remove(selectedNodes []*filetree.FileNode) error { selectedNodes = normalisedSelectedNodes(selectedNodes) - menuItems := []*types.MenuItem{ - { - Label: self.c.Tr.DiscardAllChanges, - OnPress: func() error { - self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInFile) + discardAllChangesItem := types.MenuItem{ + Label: self.c.Tr.DiscardAllChanges, + OnPress: func() error { + self.c.LogAction(self.c.Tr.Actions.DiscardAllChangesInFile) - if self.context().IsSelectingRange() { - defer self.context().CancelRangeSelect() - } + if self.context().IsSelectingRange() { + defer self.context().CancelRangeSelect() + } - for _, node := range selectedNodes { - if err := self.c.Git().WorkingTree.DiscardAllDirChanges(node); err != nil { - return err - } + for _, node := range selectedNodes { + 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), - }, - ), + 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), + }, + ), } - if someNodesHaveStagedChanges(selectedNodes) && someNodesHaveUnstagedChanges(selectedNodes) { - menuItems = append(menuItems, &types.MenuItem{ - Label: self.c.Tr.DiscardUnstagedChanges, - OnPress: func() error { - self.c.LogAction(self.c.Tr.Actions.DiscardAllUnstagedChangesInFile) + discardUnstagedChangesItem := types.MenuItem{ + Label: self.c.Tr.DiscardUnstagedChanges, + OnPress: func() error { + self.c.LogAction(self.c.Tr.Actions.DiscardAllUnstagedChangesInFile) - if self.context().IsSelectingRange() { - defer self.context().CancelRangeSelect() - } + if self.context().IsSelectingRange() { + defer self.context().CancelRangeSelect() + } - for _, node := range selectedNodes { - if err := self.c.Git().WorkingTree.DiscardUnstagedDirChanges(node); err != nil { - return err - } + for _, node := range selectedNodes { + if err := self.c.Git().WorkingTree.DiscardUnstagedDirChanges(node); err != nil { + return err } + } - return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}}) + return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.FILES, types.WORKTREES}}) + }, + Key: 'u', + Tooltip: utils.ResolvePlaceholderString( + self.c.Tr.DiscardUnstagedTooltip, + map[string]string{ + "path": self.formattedPaths(selectedNodes), }, - Key: 'u', - Tooltip: utils.ResolvePlaceholderString( - self.c.Tr.DiscardUnstagedTooltip, - map[string]string{ - "path": self.formattedPaths(selectedNodes), - }, - ), - }) + ), + } + + if !someNodesHaveStagedChanges(selectedNodes) || !someNodesHaveUnstagedChanges(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}) diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 78b8b84cf..09cab542d 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -175,6 +175,7 @@ type TranslationSet struct { UndoMergeResolveTooltip string DiscardAllTooltip string DiscardUnstagedTooltip string + DiscardUnstagedDisabled string Pop string StashPopTooltip string Drop string @@ -1143,6 +1144,7 @@ func EnglishTranslationSet() TranslationSet { UndoMergeResolveTooltip: "Undo last merge conflict resolution.", DiscardAllTooltip: "Discard both staged and unstaged changes in '{{.path}}'.", DiscardUnstagedTooltip: "Discard unstaged changes in '{{.path}}'.", + DiscardUnstagedDisabled: "The selected items don't have both staged and unstaged changes.", Pop: "Pop", StashPopTooltip: "Apply the stash entry to your working directory and remove the stash entry.", Drop: "Drop", |