Repository: jesseduffield/lazygit
File: pkg/gui/controllers/files_controller.go (Go)

Code before:

func (self *FilesController) anyTrackedFile() bool {
	stagedFiles := self.c.Helpers().WorkingTree.GetStagedFiles()
	if len(stagedFiles) == 0 {
		return self.c.Helpers().WorkingTree.AnyTrackedFiles()
	}

	for _, stagedFile := range stagedFiles {
		if stagedFile.Tracked {
			return true
		}
	}
	return false
}

func (self *FilesController) hasPathStagedChanges(node *filetree.FileNode) bool {
	return node.SomeFile(func(t *models.File) bool {
		return t.HasStagedChanges
	})
}

func (self *FilesController) copyToClipboard(content string) error {
	if err := self.c.OS().CopyToClipboard(content); err != nil {
		return self.c.Error(err)
	}
	self.c.Toast(self.c.Tr.FileContentCopiedToast)
	return nil
}

func (self *FilesController) stash() error {
	return self.handleStashSave(self.c.Git().Stash.Push, self.c.Tr.Actions.StashAllChanges)
}

func (self *FilesController) createResetToUpstreamMenu() error {
	return self.c.Helpers().Refs.CreateGitResetMenu("@{upstream}")
}

func (self *FilesController) handleToggleDirCollapsed() error {
	node := self.context().GetSelected()
	if node == nil {
		return nil
	}

	self.context().FileTreeViewModel.ToggleCollapsed(node.GetPath())

	if err := self.c.PostRefreshUpdate(self.c.Contexts().Files); err != nil {
		self.c.Log.Error(err)
	}

	return nil
}

Review comment (suggestion):
OK, I know I argued for a generic text for all items, but that was for the disabled reasons, where I think it's ok. For the toast I find it important to say which item was copied, as a confirmation that you copied the right thing. We also do this for the `y` menu for commits, see [here](https://github.com/jesseduffield/lazygit/blob/d8059d7f7de21bedd2d989f6961f62ec48781463/pkg/i18n/english.go#L1304).

Code after:
}

func (self *FilesController) anyStagedOrTrackedFile() bool {
	if !self.c.Helpers().WorkingTree.AnyStagedFiles() {
		return self.c.Helpers().WorkingTree.AnyTrackedFiles()
	}
	return true
}

func (self *FilesController) hasPathStagedChanges(node *filetree.FileNode) bool {
	return node.SomeFile(func(t *models.File) bool {
		return t.HasStagedChanges
	})
}

func (self *FilesController) stash() error {
	return self.handleStashSave(self.c.Git().Stash.Push, self.c.Tr.Actions.StashAllChanges)
}

func (self *FilesController) createResetToUpstreamMenu() error {
	return self.c.Helpers().Refs.CreateGitResetMenu("@{upstream}")
}

func (self *FilesController) handleToggleDirCollapsed() error {
	node := self.context().GetSelected()
	if node == nil {
		return nil
	}

	self.context().FileTreeViewModel.ToggleCollapsed(node.GetPath())

	if err := self.c.PostRefreshUpdate(self.c.Contexts().Files); err != nil {
		self.c.Log.Error(err)
	}

	return nil
}

func (self *FilesController) toggleTreeView() error {
	self.context().FileTreeViewModel.ToggleShowTree()

	return self.c.PostRefreshUpdate(self.context())
}

func (self *FilesController) handleStashSave(stashFunc func(message string) error, action string) error {
	return self.c.Prompt(types.PromptOpts{
		Title: self.c.Tr.StashChanges,
		HandleConfirm: func(stashComment string) error {
			self.c.LogAction(action)

			if err := stashFunc(stashComment); err != nil {