1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-04 10:34:55 +02:00

refactor to no longer call these things file changes

This commit is contained in:
Jesse Duffield 2021-03-31 23:26:53 +11:00
parent 8dee06f83a
commit 9e85d37fb9
19 changed files with 339 additions and 341 deletions

View File

@ -138,12 +138,12 @@ func (c *GitCommand) DiscardAllFileChanges(file *models.File) error {
return c.DiscardUnstagedFileChanges(file)
}
func (c *GitCommand) DiscardAllDirChanges(node *filetree.FileChangeNode) error {
func (c *GitCommand) DiscardAllDirChanges(node *filetree.FileNode) error {
// this could be more efficient but we would need to handle all the edge cases
return node.ForEachFile(c.DiscardAllFileChanges)
}
func (c *GitCommand) DiscardUnstagedDirChanges(node *filetree.FileChangeNode) error {
func (c *GitCommand) DiscardUnstagedDirChanges(node *filetree.FileNode) error {
if err := c.RemoveUntrackedDirFiles(node); err != nil {
return err
}
@ -156,9 +156,9 @@ func (c *GitCommand) DiscardUnstagedDirChanges(node *filetree.FileChangeNode) er
return nil
}
func (c *GitCommand) RemoveUntrackedDirFiles(node *filetree.FileChangeNode) error {
func (c *GitCommand) RemoveUntrackedDirFiles(node *filetree.FileNode) error {
untrackedFilePaths := node.GetPathsMatching(
func(n *filetree.FileChangeNode) bool { return n.File != nil && !n.File.GetIsTracked() },
func(n *filetree.FileNode) bool { return n.File != nil && !n.File.GetIsTracked() },
)
for _, path := range untrackedFilePaths {
@ -189,7 +189,7 @@ func (c *GitCommand) WorktreeFileDiff(file *models.File, plain bool, cached bool
return s
}
func (c *GitCommand) WorktreeFileDiffCmdStr(node models.IFileChange, plain bool, cached bool) string {
func (c *GitCommand) WorktreeFileDiffCmdStr(node models.IFile, plain bool, cached bool) string {
cachedArg := ""
trackedArg := "--"
colorArg := c.colorArg()

View File

@ -22,7 +22,7 @@ type File struct {
}
// sometimes we need to deal with either a node (which contains a file) or an actual file
type IFileChange interface {
type IFile interface {
GetHasUnstagedChanges() bool
GetHasStagedChanges() bool
GetIsTracked() bool

View File

@ -7,17 +7,15 @@ import (
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
)
// todo: rename to getSelectedCommitFileChangeNode, or decide to remove the change part in the context of files
func (gui *Gui) getSelectedCommitFileNode() *filetree.CommitFileChangeNode {
func (gui *Gui) getSelectedCommitFileNode() *filetree.CommitFileNode {
selectedLine := gui.State.Panels.CommitFiles.SelectedLineIdx
if selectedLine == -1 || selectedLine > gui.State.CommitFileChangeManager.GetItemsLength()-1 {
if selectedLine == -1 || selectedLine > gui.State.CommitFileManager.GetItemsLength()-1 {
return nil
}
return gui.State.CommitFileChangeManager.GetItemAtIndex(selectedLine)
return gui.State.CommitFileManager.GetItemAtIndex(selectedLine)
}
// todo: rename to getSelectedCommitFileChange
func (gui *Gui) getSelectedCommitFile() *models.CommitFile {
node := gui.getSelectedCommitFileNode()
if node == nil {
@ -42,7 +40,7 @@ func (gui *Gui) handleCommitFileSelect() error {
return nil
}
to := gui.State.CommitFileChangeManager.GetParent()
to := gui.State.CommitFileManager.GetParent()
from, reverse := gui.getFromAndReverseArgsForDiff(to)
cmd := gui.OSCommand.ExecutableFromString(
@ -66,7 +64,7 @@ func (gui *Gui) handleCheckoutCommitFile(g *gocui.Gui, v *gocui.View) error {
}
// TODO: verify this works for directories
if err := gui.GitCommand.CheckoutFile(gui.State.CommitFileChangeManager.GetParent(), node.GetPath()); err != nil {
if err := gui.GitCommand.CheckoutFile(gui.State.CommitFileManager.GetParent(), node.GetPath()); err != nil {
return gui.surfaceError(err)
}
@ -109,7 +107,7 @@ func (gui *Gui) refreshCommitFilesView() error {
if err != nil {
return gui.surfaceError(err)
}
gui.State.CommitFileChangeManager.SetFiles(files, to)
gui.State.CommitFileManager.SetFiles(files, to)
return gui.postRefreshUpdate(gui.Contexts.CommitFiles.Context)
}
@ -152,7 +150,7 @@ func (gui *Gui) handleToggleFileForPatch(g *gocui.Gui, v *gocui.View) error {
// if there is any file that hasn't been fully added we'll fully add everything,
// otherwise we'll remove everything
adding := node.AnyFile(func(file *models.CommitFile) bool {
return gui.GitCommand.PatchManager.GetFileStatus(file.Name, gui.State.CommitFileChangeManager.GetParent()) != patch.WHOLE
return gui.GitCommand.PatchManager.GetFileStatus(file.Name, gui.State.CommitFileManager.GetParent()) != patch.WHOLE
})
err := node.ForEachFile(func(file *models.CommitFile) error {
@ -174,7 +172,7 @@ func (gui *Gui) handleToggleFileForPatch(g *gocui.Gui, v *gocui.View) error {
return gui.postRefreshUpdate(gui.Contexts.CommitFiles.Context)
}
if gui.GitCommand.PatchManager.Active() && gui.GitCommand.PatchManager.To != gui.State.CommitFileChangeManager.GetParent() {
if gui.GitCommand.PatchManager.Active() && gui.GitCommand.PatchManager.To != gui.State.CommitFileManager.GetParent() {
return gui.ask(askOpts{
title: gui.Tr.DiscardPatch,
prompt: gui.Tr.DiscardPatchConfirm,
@ -225,7 +223,7 @@ func (gui *Gui) enterCommitFile(selectedLineIdx int) error {
return gui.handleRefreshPatchBuildingPanel(selectedLineIdx)
}
if gui.GitCommand.PatchManager.Active() && gui.GitCommand.PatchManager.To != gui.State.CommitFileChangeManager.GetParent() {
if gui.GitCommand.PatchManager.Active() && gui.GitCommand.PatchManager.To != gui.State.CommitFileManager.GetParent() {
return gui.ask(askOpts{
title: gui.Tr.DiscardPatch,
prompt: gui.Tr.DiscardPatchConfirm,
@ -249,7 +247,7 @@ func (gui *Gui) handleToggleCommitFileDirCollapsed() error {
return nil
}
gui.State.CommitFileChangeManager.ToggleCollapsed(node.GetPath())
gui.State.CommitFileManager.ToggleCollapsed(node.GetPath())
if err := gui.postRefreshUpdate(gui.Contexts.CommitFiles.Context); err != nil {
gui.Log.Error(err)
@ -280,12 +278,12 @@ func (gui *Gui) switchToCommitFilesContext(refName string, canRebase bool, conte
func (gui *Gui) handleToggleCommitFileTreeView() error {
path := gui.getSelectedCommitFilePath()
gui.State.CommitFileChangeManager.ToggleShowTree()
gui.State.CommitFileManager.ToggleShowTree()
// find that same node in the new format and move the cursor to it
if path != "" {
gui.State.CommitFileChangeManager.ExpandToPath(path)
index, found := gui.State.CommitFileChangeManager.GetIndexForPath(path)
gui.State.CommitFileManager.ExpandToPath(path)
index, found := gui.State.CommitFileManager.GetIndexForPath(path)
if found {
gui.commitFilesListContext().GetPanelState().SetSelectedLineIdx(index)
}

View File

@ -1,7 +1,7 @@
package gui
func (gui *Gui) handleCreateDiscardMenu() error {
node := gui.getSelectedFileChangeNode()
node := gui.getSelectedFileNode()
if node == nil {
return nil
}

View File

@ -22,17 +22,17 @@ import (
// list panel functions
func (gui *Gui) getSelectedFileChangeNode() *filetree.FileChangeNode {
func (gui *Gui) getSelectedFileNode() *filetree.FileNode {
selectedLine := gui.State.Panels.Files.SelectedLineIdx
if selectedLine == -1 {
return nil
}
return gui.State.FileChangeManager.GetItemAtIndex(selectedLine)
return gui.State.FileManager.GetItemAtIndex(selectedLine)
}
func (gui *Gui) getSelectedFile() *models.File {
node := gui.getSelectedFileChangeNode()
node := gui.getSelectedFileNode()
if node == nil {
return nil
}
@ -40,7 +40,7 @@ func (gui *Gui) getSelectedFile() *models.File {
}
func (gui *Gui) getSelectedPath() string {
node := gui.getSelectedFileChangeNode()
node := gui.getSelectedFileNode()
if node == nil {
return ""
}
@ -51,7 +51,7 @@ func (gui *Gui) getSelectedPath() string {
func (gui *Gui) selectFile(alreadySelected bool) error {
gui.getFilesView().FocusPoint(0, gui.State.Panels.Files.SelectedLineIdx)
node := gui.getSelectedFileChangeNode()
node := gui.getSelectedFileNode()
if node == nil {
return gui.refreshMainViews(refreshMainOpts{
@ -152,7 +152,7 @@ func (gui *Gui) refreshFilesAndSubmodules() error {
// specific functions
func (gui *Gui) stagedFiles() []*models.File {
files := gui.State.FileChangeManager.GetAllFiles()
files := gui.State.FileManager.GetAllFiles()
result := make([]*models.File, 0)
for _, file := range files {
if file.HasStagedChanges {
@ -163,7 +163,7 @@ func (gui *Gui) stagedFiles() []*models.File {
}
func (gui *Gui) trackedFiles() []*models.File {
files := gui.State.FileChangeManager.GetAllFiles()
files := gui.State.FileManager.GetAllFiles()
result := make([]*models.File, 0, len(files))
for _, file := range files {
if file.Tracked {
@ -187,7 +187,7 @@ func (gui *Gui) handleEnterFile(g *gocui.Gui, v *gocui.View) error {
}
func (gui *Gui) enterFile(forceSecondaryFocused bool, selectedLineIdx int) error {
node := gui.getSelectedFileChangeNode()
node := gui.getSelectedFileNode()
if node == nil {
return nil
}
@ -216,7 +216,7 @@ func (gui *Gui) enterFile(forceSecondaryFocused bool, selectedLineIdx int) error
}
func (gui *Gui) handleFilePress() error {
node := gui.getSelectedFileChangeNode()
node := gui.getSelectedFileNode()
if node == nil {
return nil
}
@ -264,7 +264,7 @@ func (gui *Gui) handleFilePress() error {
}
func (gui *Gui) allFilesStaged() bool {
for _, file := range gui.State.FileChangeManager.GetAllFiles() {
for _, file := range gui.State.FileManager.GetAllFiles() {
if file.HasUnstagedChanges {
return false
}
@ -295,7 +295,7 @@ func (gui *Gui) handleStageAll(g *gocui.Gui, v *gocui.View) error {
}
func (gui *Gui) handleIgnoreFile() error {
node := gui.getSelectedFileChangeNode()
node := gui.getSelectedFileNode()
if node == nil {
return nil
}
@ -500,7 +500,7 @@ func (gui *Gui) editFile(filename string) error {
}
func (gui *Gui) handleFileEdit(g *gocui.Gui, v *gocui.View) error {
node := gui.getSelectedFileChangeNode()
node := gui.getSelectedFileNode()
if node == nil {
return nil
}
@ -513,7 +513,7 @@ func (gui *Gui) handleFileEdit(g *gocui.Gui, v *gocui.View) error {
}
func (gui *Gui) handleFileOpen(g *gocui.Gui, v *gocui.View) error {
node := gui.getSelectedFileChangeNode()
node := gui.getSelectedFileNode()
if node == nil {
return nil
}
@ -530,9 +530,9 @@ func (gui *Gui) refreshStateFiles() error {
// when we refresh, go looking for a matching name
// move the cursor to there.
selectedNode := gui.getSelectedFileChangeNode()
selectedNode := gui.getSelectedFileNode()
prevNodes := gui.State.FileChangeManager.GetAllItems()
prevNodes := gui.State.FileManager.GetAllItems()
prevSelectedLineIdx := gui.State.Panels.Files.SelectedLineIdx
files := gui.GitCommand.GetStatusFiles(commands.GetStatusFileOptions{})
@ -540,24 +540,24 @@ func (gui *Gui) refreshStateFiles() error {
// for when you stage the old file of a rename and the new file is in a collapsed dir
for _, file := range files {
if selectedNode != nil && selectedNode.Path != "" && file.PreviousName == selectedNode.Path {
gui.State.FileChangeManager.ExpandToPath(file.Name)
gui.State.FileManager.ExpandToPath(file.Name)
}
}
gui.State.FileChangeManager.SetFiles(files)
gui.State.FileManager.SetFiles(files)
if err := gui.fileWatcher.addFilesToFileWatcher(files); err != nil {
return err
}
if selectedNode != nil {
newIdx := gui.findNewSelectedIdx(prevNodes[prevSelectedLineIdx:], gui.State.FileChangeManager.GetAllItems())
newIdx := gui.findNewSelectedIdx(prevNodes[prevSelectedLineIdx:], gui.State.FileManager.GetAllItems())
if newIdx != -1 && newIdx != prevSelectedLineIdx {
gui.State.Panels.Files.SelectedLineIdx = newIdx
}
}
gui.refreshSelectedLine(gui.State.Panels.Files, gui.State.FileChangeManager.GetItemsLength())
gui.refreshSelectedLine(gui.State.Panels.Files, gui.State.FileManager.GetItemsLength())
return nil
}
@ -568,8 +568,8 @@ func (gui *Gui) refreshStateFiles() error {
// nodes until we find one that exists in the new set of nodes, then move the cursor
// to that.
// prevNodes starts from our previously selected node because we don't need to consider anything above that
func (gui *Gui) findNewSelectedIdx(prevNodes []*filetree.FileChangeNode, currNodes []*filetree.FileChangeNode) int {
getPaths := func(node *filetree.FileChangeNode) []string {
func (gui *Gui) findNewSelectedIdx(prevNodes []*filetree.FileNode, currNodes []*filetree.FileNode) int {
getPaths := func(node *filetree.FileNode) []string {
if node == nil {
return nil
}
@ -788,7 +788,7 @@ func (gui *Gui) openFile(filename string) error {
}
func (gui *Gui) anyFilesWithMergeConflicts() bool {
for _, file := range gui.State.FileChangeManager.GetAllFiles() {
for _, file := range gui.State.FileManager.GetAllFiles() {
if file.HasMergeConflicts {
return true
}
@ -834,12 +834,12 @@ func (gui *Gui) handleCreateResetToUpstreamMenu(g *gocui.Gui, v *gocui.View) err
}
func (gui *Gui) handleToggleDirCollapsed() error {
node := gui.getSelectedFileChangeNode()
node := gui.getSelectedFileNode()
if node == nil {
return nil
}
gui.State.FileChangeManager.ToggleCollapsed(node.GetPath())
gui.State.FileManager.ToggleCollapsed(node.GetPath())
if err := gui.postRefreshUpdate(gui.Contexts.Files.Context); err != nil {
gui.Log.Error(err)
@ -852,12 +852,12 @@ func (gui *Gui) handleToggleFileTreeView() error {
// get path of currently selected file
path := gui.getSelectedPath()
gui.State.FileChangeManager.ToggleShowTree()
gui.State.FileManager.ToggleShowTree()
// find that same node in the new format and move the cursor to it
if path != "" {
gui.State.FileChangeManager.ExpandToPath(path)
index, found := gui.State.FileChangeManager.GetIndexForPath(path)
gui.State.FileManager.ExpandToPath(path)
index, found := gui.State.FileManager.GetIndexForPath(path)
if found {
gui.filesListContext().GetPanelState().SetSelectedLineIdx(index)
}

View File

@ -9,10 +9,10 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
)
func BuildTreeFromFiles(files []*models.File) *FileChangeNode {
root := &FileChangeNode{}
func BuildTreeFromFiles(files []*models.File) *FileNode {
root := &FileNode{}
var curr *FileChangeNode
var curr *FileNode
for _, file := range files {
split := strings.Split(file.Name, string(os.PathSeparator))
curr = root
@ -33,7 +33,7 @@ func BuildTreeFromFiles(files []*models.File) *FileChangeNode {
}
}
newChild := &FileChangeNode{
newChild := &FileNode{
Path: path,
File: setFile,
}
@ -49,17 +49,17 @@ func BuildTreeFromFiles(files []*models.File) *FileChangeNode {
return root
}
func BuildFlatTreeFromCommitFiles(files []*models.CommitFile) *CommitFileChangeNode {
func BuildFlatTreeFromCommitFiles(files []*models.CommitFile) *CommitFileNode {
rootAux := BuildTreeFromCommitFiles(files)
sortedFiles := rootAux.GetLeaves()
return &CommitFileChangeNode{Children: sortedFiles}
return &CommitFileNode{Children: sortedFiles}
}
func BuildTreeFromCommitFiles(files []*models.CommitFile) *CommitFileChangeNode {
root := &CommitFileChangeNode{}
func BuildTreeFromCommitFiles(files []*models.CommitFile) *CommitFileNode {
root := &CommitFileNode{}
var curr *CommitFileChangeNode
var curr *CommitFileNode
for _, file := range files {
split := strings.Split(file.Name, string(os.PathSeparator))
curr = root
@ -80,7 +80,7 @@ func BuildTreeFromCommitFiles(files []*models.CommitFile) *CommitFileChangeNode
}
}
newChild := &CommitFileChangeNode{
newChild := &CommitFileNode{
Path: path,
File: setFile,
}
@ -96,7 +96,7 @@ func BuildTreeFromCommitFiles(files []*models.CommitFile) *CommitFileChangeNode
return root
}
func BuildFlatTreeFromFiles(files []*models.File) *FileChangeNode {
func BuildFlatTreeFromFiles(files []*models.File) *FileNode {
rootAux := BuildTreeFromFiles(files)
sortedFiles := rootAux.GetLeaves()
@ -106,5 +106,5 @@ func BuildFlatTreeFromFiles(files []*models.File) *FileChangeNode {
return sortedFiles[i].File != nil && sortedFiles[i].File.HasMergeConflicts && !(sortedFiles[j].File != nil && sortedFiles[j].File.HasMergeConflicts)
})
return &FileChangeNode{Children: sortedFiles}
return &FileNode{Children: sortedFiles}
}

View File

@ -1,162 +0,0 @@
package filetree
import (
"os"
"path/filepath"
"strings"
"github.com/jesseduffield/lazygit/pkg/commands/models"
)
type CommitFileChangeNode struct {
Children []*CommitFileChangeNode
File *models.CommitFile
Path string // e.g. '/path/to/mydir'
CompressionLevel int // equal to the number of forward slashes you'll see in the path when it's rendered in tree mode
}
// methods satisfying ListItem interface
func (s *CommitFileChangeNode) ID() string {
return s.GetPath()
}
func (s *CommitFileChangeNode) Description() string {
return s.GetPath()
}
// methods satisfying INode interface
func (s *CommitFileChangeNode) IsLeaf() bool {
return s.File != nil
}
func (s *CommitFileChangeNode) GetPath() string {
return s.Path
}
func (s *CommitFileChangeNode) GetChildren() []INode {
result := make([]INode, len(s.Children))
for i, child := range s.Children {
result[i] = child
}
return result
}
func (s *CommitFileChangeNode) SetChildren(children []INode) {
castChildren := make([]*CommitFileChangeNode, len(children))
for i, child := range children {
castChildren[i] = child.(*CommitFileChangeNode)
}
s.Children = castChildren
}
func (s *CommitFileChangeNode) GetCompressionLevel() int {
return s.CompressionLevel
}
func (s *CommitFileChangeNode) SetCompressionLevel(level int) {
s.CompressionLevel = level
}
// methods utilising generic functions for INodes
func (s *CommitFileChangeNode) Sort() {
sortNode(s)
}
func (s *CommitFileChangeNode) ForEachFile(cb func(*models.CommitFile) error) error {
return forEachLeaf(s, func(n INode) error {
castNode := n.(*CommitFileChangeNode)
return cb(castNode.File)
})
}
func (s *CommitFileChangeNode) Any(test func(node *CommitFileChangeNode) bool) bool {
return any(s, func(n INode) bool {
castNode := n.(*CommitFileChangeNode)
return test(castNode)
})
}
func (s *CommitFileChangeNode) Every(test func(node *CommitFileChangeNode) bool) bool {
return every(s, func(n INode) bool {
castNode := n.(*CommitFileChangeNode)
return test(castNode)
})
}
func (s *CommitFileChangeNode) EveryFile(test func(file *models.CommitFile) bool) bool {
return every(s, func(n INode) bool {
castNode := n.(*CommitFileChangeNode)
return castNode.File == nil || test(castNode.File)
})
}
func (n *CommitFileChangeNode) Flatten(collapsedPaths map[string]bool) []*CommitFileChangeNode {
results := flatten(n, collapsedPaths)
nodes := make([]*CommitFileChangeNode, len(results))
for i, result := range results {
nodes[i] = result.(*CommitFileChangeNode)
}
return nodes
}
func (node *CommitFileChangeNode) GetNodeAtIndex(index int, collapsedPaths map[string]bool) *CommitFileChangeNode {
return getNodeAtIndex(node, index, collapsedPaths).(*CommitFileChangeNode)
}
func (node *CommitFileChangeNode) GetIndexForPath(path string, collapsedPaths map[string]bool) (int, bool) {
return getIndexForPath(node, path, collapsedPaths)
}
func (node *CommitFileChangeNode) Size(collapsedPaths map[string]bool) int {
return size(node, collapsedPaths)
}
func (s *CommitFileChangeNode) Compress() {
// with these functions I try to only have type conversion code on the actual struct,
// but comparing interface values to nil is fraught with danger so I'm duplicating
// that code here.
if s == nil {
return
}
compressAux(s)
}
// This ignores the root
func (node *CommitFileChangeNode) GetPathsMatching(test func(*CommitFileChangeNode) bool) []string {
return getPathsMatching(node, func(n INode) bool {
return test(n.(*CommitFileChangeNode))
})
}
func (s *CommitFileChangeNode) GetLeaves() []*CommitFileChangeNode {
leaves := getLeaves(s)
castLeaves := make([]*CommitFileChangeNode, len(leaves))
for i := range leaves {
castLeaves[i] = leaves[i].(*CommitFileChangeNode)
}
return castLeaves
}
// extra methods
func (s *CommitFileChangeNode) AnyFile(test func(file *models.CommitFile) bool) bool {
return s.Any(func(node *CommitFileChangeNode) bool {
return node.IsLeaf() && test(node.File)
})
}
func (s *CommitFileChangeNode) NameAtDepth(depth int) string {
splitName := strings.Split(s.Path, string(os.PathSeparator))
name := filepath.Join(splitName[depth:]...)
return name
}

View File

@ -7,9 +7,9 @@ import (
"github.com/sirupsen/logrus"
)
type CommitFileChangeManager struct {
type CommitFileManager struct {
files []*models.CommitFile
tree *CommitFileChangeNode
tree *CommitFileNode
showTree bool
log *logrus.Entry
collapsedPaths CollapsedPaths
@ -17,12 +17,12 @@ type CommitFileChangeManager struct {
parent string
}
func (m *CommitFileChangeManager) GetParent() string {
func (m *CommitFileManager) GetParent() string {
return m.parent
}
func NewCommitFileChangeManager(files []*models.CommitFile, log *logrus.Entry, showTree bool) *CommitFileChangeManager {
return &CommitFileChangeManager{
func NewCommitFileManager(files []*models.CommitFile, log *logrus.Entry, showTree bool) *CommitFileManager {
return &CommitFileManager{
files: files,
log: log,
showTree: showTree,
@ -30,26 +30,26 @@ func NewCommitFileChangeManager(files []*models.CommitFile, log *logrus.Entry, s
}
}
func (m *CommitFileChangeManager) ExpandToPath(path string) {
func (m *CommitFileManager) ExpandToPath(path string) {
m.collapsedPaths.ExpandToPath(path)
}
func (m *CommitFileChangeManager) ToggleShowTree() {
func (m *CommitFileManager) ToggleShowTree() {
m.showTree = !m.showTree
m.SetTree()
}
func (m *CommitFileChangeManager) GetItemAtIndex(index int) *CommitFileChangeNode {
func (m *CommitFileManager) GetItemAtIndex(index int) *CommitFileNode {
// need to traverse the three depth first until we get to the index.
return m.tree.GetNodeAtIndex(index+1, m.collapsedPaths) // ignoring root
}
func (m *CommitFileChangeManager) GetIndexForPath(path string) (int, bool) {
func (m *CommitFileManager) GetIndexForPath(path string) (int, bool) {
index, found := m.tree.GetIndexForPath(path, m.collapsedPaths)
return index - 1, found
}
func (m *CommitFileChangeManager) GetAllItems() []*CommitFileChangeNode {
func (m *CommitFileManager) GetAllItems() []*CommitFileNode {
if m.tree == nil {
return nil
}
@ -57,22 +57,22 @@ func (m *CommitFileChangeManager) GetAllItems() []*CommitFileChangeNode {
return m.tree.Flatten(m.collapsedPaths)[1:] // ignoring root
}
func (m *CommitFileChangeManager) GetItemsLength() int {
func (m *CommitFileManager) GetItemsLength() int {
return m.tree.Size(m.collapsedPaths) - 1 // ignoring root
}
func (m *CommitFileChangeManager) GetAllFiles() []*models.CommitFile {
func (m *CommitFileManager) GetAllFiles() []*models.CommitFile {
return m.files
}
func (m *CommitFileChangeManager) SetFiles(files []*models.CommitFile, parent string) {
func (m *CommitFileManager) SetFiles(files []*models.CommitFile, parent string) {
m.files = files
m.parent = parent
m.SetTree()
}
func (m *CommitFileChangeManager) SetTree() {
func (m *CommitFileManager) SetTree() {
if m.showTree {
m.tree = BuildTreeFromCommitFiles(m.files)
} else {
@ -80,17 +80,17 @@ func (m *CommitFileChangeManager) SetTree() {
}
}
func (m *CommitFileChangeManager) IsCollapsed(path string) bool {
func (m *CommitFileManager) IsCollapsed(path string) bool {
return m.collapsedPaths.IsCollapsed(path)
}
func (m *CommitFileChangeManager) ToggleCollapsed(path string) {
func (m *CommitFileManager) ToggleCollapsed(path string) {
m.collapsedPaths.ToggleCollapsed(path)
}
func (m *CommitFileChangeManager) Render(diffName string, patchManager *patch.PatchManager) []string {
func (m *CommitFileManager) Render(diffName string, patchManager *patch.PatchManager) []string {
return renderAux(m.tree, m.collapsedPaths, "", -1, func(n INode, depth int) string {
castN := n.(*CommitFileChangeNode)
castN := n.(*CommitFileNode)
// This is a little convoluted because we're dealing with either a leaf or a non-leaf.
// But this code actually applies to both. If it's a leaf, the status will just

View File

@ -0,0 +1,162 @@
package filetree
import (
"os"
"path/filepath"
"strings"
"github.com/jesseduffield/lazygit/pkg/commands/models"
)
type CommitFileNode struct {
Children []*CommitFileNode
File *models.CommitFile
Path string // e.g. '/path/to/mydir'
CompressionLevel int // equal to the number of forward slashes you'll see in the path when it's rendered in tree mode
}
// methods satisfying ListItem interface
func (s *CommitFileNode) ID() string {
return s.GetPath()
}
func (s *CommitFileNode) Description() string {
return s.GetPath()
}
// methods satisfying INode interface
func (s *CommitFileNode) IsLeaf() bool {
return s.File != nil
}
func (s *CommitFileNode) GetPath() string {
return s.Path
}
func (s *CommitFileNode) GetChildren() []INode {
result := make([]INode, len(s.Children))
for i, child := range s.Children {
result[i] = child
}
return result
}
func (s *CommitFileNode) SetChildren(children []INode) {
castChildren := make([]*CommitFileNode, len(children))
for i, child := range children {
castChildren[i] = child.(*CommitFileNode)
}
s.Children = castChildren
}
func (s *CommitFileNode) GetCompressionLevel() int {
return s.CompressionLevel
}
func (s *CommitFileNode) SetCompressionLevel(level int) {
s.CompressionLevel = level
}
// methods utilising generic functions for INodes
func (s *CommitFileNode) Sort() {
sortNode(s)
}
func (s *CommitFileNode) ForEachFile(cb func(*models.CommitFile) error) error {
return forEachLeaf(s, func(n INode) error {
castNode := n.(*CommitFileNode)
return cb(castNode.File)
})
}
func (s *CommitFileNode) Any(test func(node *CommitFileNode) bool) bool {
return any(s, func(n INode) bool {
castNode := n.(*CommitFileNode)
return test(castNode)
})
}
func (s *CommitFileNode) Every(test func(node *CommitFileNode) bool) bool {
return every(s, func(n INode) bool {
castNode := n.(*CommitFileNode)
return test(castNode)
})
}
func (s *CommitFileNode) EveryFile(test func(file *models.CommitFile) bool) bool {
return every(s, func(n INode) bool {
castNode := n.(*CommitFileNode)
return castNode.File == nil || test(castNode.File)
})
}
func (n *CommitFileNode) Flatten(collapsedPaths map[string]bool) []*CommitFileNode {
results := flatten(n, collapsedPaths)
nodes := make([]*CommitFileNode, len(results))
for i, result := range results {
nodes[i] = result.(*CommitFileNode)
}
return nodes
}
func (node *CommitFileNode) GetNodeAtIndex(index int, collapsedPaths map[string]bool) *CommitFileNode {
return getNodeAtIndex(node, index, collapsedPaths).(*CommitFileNode)
}
func (node *CommitFileNode) GetIndexForPath(path string, collapsedPaths map[string]bool) (int, bool) {
return getIndexForPath(node, path, collapsedPaths)
}
func (node *CommitFileNode) Size(collapsedPaths map[string]bool) int {
return size(node, collapsedPaths)
}
func (s *CommitFileNode) Compress() {
// with these functions I try to only have type conversion code on the actual struct,
// but comparing interface values to nil is fraught with danger so I'm duplicating
// that code here.
if s == nil {
return
}
compressAux(s)
}
// This ignores the root
func (node *CommitFileNode) GetPathsMatching(test func(*CommitFileNode) bool) []string {
return getPathsMatching(node, func(n INode) bool {
return test(n.(*CommitFileNode))
})
}
func (s *CommitFileNode) GetLeaves() []*CommitFileNode {
leaves := getLeaves(s)
castLeaves := make([]*CommitFileNode, len(leaves))
for i := range leaves {
castLeaves[i] = leaves[i].(*CommitFileNode)
}
return castLeaves
}
// extra methods
func (s *CommitFileNode) AnyFile(test func(file *models.CommitFile) bool) bool {
return s.Any(func(node *CommitFileNode) bool {
return node.IsLeaf() && test(node.File)
})
}
func (s *CommitFileNode) NameAtDepth(depth int) string {
splitName := strings.Split(s.Path, string(os.PathSeparator))
name := filepath.Join(splitName[depth:]...)
return name
}

View File

@ -6,16 +6,16 @@ import (
"github.com/sirupsen/logrus"
)
type FileChangeManager struct {
type FileManager struct {
files []*models.File
tree *FileChangeNode
tree *FileNode
showTree bool
log *logrus.Entry
collapsedPaths CollapsedPaths
}
func NewFileChangeManager(files []*models.File, log *logrus.Entry, showTree bool) *FileChangeManager {
return &FileChangeManager{
func NewFileChangeManager(files []*models.File, log *logrus.Entry, showTree bool) *FileManager {
return &FileManager{
files: files,
log: log,
showTree: showTree,
@ -23,26 +23,26 @@ func NewFileChangeManager(files []*models.File, log *logrus.Entry, showTree bool
}
}
func (m *FileChangeManager) ExpandToPath(path string) {
func (m *FileManager) ExpandToPath(path string) {
m.collapsedPaths.ExpandToPath(path)
}
func (m *FileChangeManager) ToggleShowTree() {
func (m *FileManager) ToggleShowTree() {
m.showTree = !m.showTree
m.SetTree()
}
func (m *FileChangeManager) GetItemAtIndex(index int) *FileChangeNode {
func (m *FileManager) GetItemAtIndex(index int) *FileNode {
// need to traverse the three depth first until we get to the index.
return m.tree.GetNodeAtIndex(index+1, m.collapsedPaths) // ignoring root
}
func (m *FileChangeManager) GetIndexForPath(path string) (int, bool) {
func (m *FileManager) GetIndexForPath(path string) (int, bool) {
index, found := m.tree.GetIndexForPath(path, m.collapsedPaths)
return index - 1, found
}
func (m *FileChangeManager) GetAllItems() []*FileChangeNode {
func (m *FileManager) GetAllItems() []*FileNode {
if m.tree == nil {
return nil
}
@ -50,21 +50,21 @@ func (m *FileChangeManager) GetAllItems() []*FileChangeNode {
return m.tree.Flatten(m.collapsedPaths)[1:] // ignoring root
}
func (m *FileChangeManager) GetItemsLength() int {
func (m *FileManager) GetItemsLength() int {
return m.tree.Size(m.collapsedPaths) - 1 // ignoring root
}
func (m *FileChangeManager) GetAllFiles() []*models.File {
func (m *FileManager) GetAllFiles() []*models.File {
return m.files
}
func (m *FileChangeManager) SetFiles(files []*models.File) {
func (m *FileManager) SetFiles(files []*models.File) {
m.files = files
m.SetTree()
}
func (m *FileChangeManager) SetTree() {
func (m *FileManager) SetTree() {
if m.showTree {
m.tree = BuildTreeFromFiles(m.files)
} else {
@ -72,17 +72,17 @@ func (m *FileChangeManager) SetTree() {
}
}
func (m *FileChangeManager) IsCollapsed(path string) bool {
func (m *FileManager) IsCollapsed(path string) bool {
return m.collapsedPaths.IsCollapsed(path)
}
func (m *FileChangeManager) ToggleCollapsed(path string) {
func (m *FileManager) ToggleCollapsed(path string) {
m.collapsedPaths.ToggleCollapsed(path)
}
func (m *FileChangeManager) Render(diffName string, submoduleConfigs []*models.SubmoduleConfig) []string {
func (m *FileManager) Render(diffName string, submoduleConfigs []*models.SubmoduleConfig) []string {
return renderAux(m.tree, m.collapsedPaths, "", -1, func(n INode, depth int) string {
castN := n.(*FileChangeNode)
castN := n.(*FileNode)
return presentation.GetFileLine(castN.GetHasUnstagedChanges(), castN.GetHasStagedChanges(), castN.NameAtDepth(depth), diffName, submoduleConfigs, castN.File)
})
}

View File

@ -10,7 +10,7 @@ import (
func TestRender(t *testing.T) {
scenarios := []struct {
name string
root *FileChangeNode
root *FileNode
collapsedPaths map[string]bool
expected []string
}{
@ -21,9 +21,9 @@ func TestRender(t *testing.T) {
},
{
name: "leaf node",
root: &FileChangeNode{
root: &FileNode{
Path: "",
Children: []*FileChangeNode{
Children: []*FileNode{
{File: &models.File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Path: "test"},
},
},
@ -31,12 +31,12 @@ func TestRender(t *testing.T) {
},
{
name: "big example",
root: &FileChangeNode{
root: &FileNode{
Path: "",
Children: []*FileChangeNode{
Children: []*FileNode{
{
Path: "dir1",
Children: []*FileChangeNode{
Children: []*FileNode{
{
File: &models.File{Name: "dir1/file2", ShortStatus: "M ", HasUnstagedChanges: true},
Path: "dir1/file2",
@ -49,10 +49,10 @@ func TestRender(t *testing.T) {
},
{
Path: "dir2",
Children: []*FileChangeNode{
Children: []*FileNode{
{
Path: "dir2/dir2",
Children: []*FileChangeNode{
Children: []*FileNode{
{
File: &models.File{Name: "dir2/dir2/file3", ShortStatus: " M", HasStagedChanges: true},
Path: "dir2/dir2/file3",
@ -83,7 +83,7 @@ func TestRender(t *testing.T) {
for _, s := range scenarios {
s := s
t.Run(s.name, func(t *testing.T) {
mngr := &FileChangeManager{tree: s.root, collapsedPaths: s.collapsedPaths}
mngr := &FileManager{tree: s.root, collapsedPaths: s.collapsedPaths}
result := mngr.Render("", nil)
assert.EqualValues(t, s.expected, result)
})

View File

@ -9,8 +9,8 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
)
type FileChangeNode struct {
Children []*FileChangeNode
type FileNode struct {
Children []*FileNode
File *models.File
Path string // e.g. '/path/to/mydir'
CompressionLevel int // equal to the number of forward slashes you'll see in the path when it's rendered in tree mode
@ -18,25 +18,25 @@ type FileChangeNode struct {
// methods satisfying ListItem interface
func (s *FileChangeNode) ID() string {
func (s *FileNode) ID() string {
return s.GetPath()
}
func (s *FileChangeNode) Description() string {
func (s *FileNode) Description() string {
return s.GetPath()
}
// methods satisfying INode interface
func (s *FileChangeNode) IsLeaf() bool {
func (s *FileNode) IsLeaf() bool {
return s.File != nil
}
func (s *FileChangeNode) GetPath() string {
func (s *FileNode) GetPath() string {
return s.Path
}
func (s *FileChangeNode) GetChildren() []INode {
func (s *FileNode) GetChildren() []INode {
result := make([]INode, len(s.Children))
for i, child := range s.Children {
result[i] = child
@ -45,66 +45,66 @@ func (s *FileChangeNode) GetChildren() []INode {
return result
}
func (s *FileChangeNode) SetChildren(children []INode) {
castChildren := make([]*FileChangeNode, len(children))
func (s *FileNode) SetChildren(children []INode) {
castChildren := make([]*FileNode, len(children))
for i, child := range children {
castChildren[i] = child.(*FileChangeNode)
castChildren[i] = child.(*FileNode)
}
s.Children = castChildren
}
func (s *FileChangeNode) GetCompressionLevel() int {
func (s *FileNode) GetCompressionLevel() int {
return s.CompressionLevel
}
func (s *FileChangeNode) SetCompressionLevel(level int) {
func (s *FileNode) SetCompressionLevel(level int) {
s.CompressionLevel = level
}
// methods utilising generic functions for INodes
func (s *FileChangeNode) Sort() {
func (s *FileNode) Sort() {
sortNode(s)
}
func (s *FileChangeNode) ForEachFile(cb func(*models.File) error) error {
func (s *FileNode) ForEachFile(cb func(*models.File) error) error {
return forEachLeaf(s, func(n INode) error {
castNode := n.(*FileChangeNode)
castNode := n.(*FileNode)
return cb(castNode.File)
})
}
func (s *FileChangeNode) Any(test func(node *FileChangeNode) bool) bool {
func (s *FileNode) Any(test func(node *FileNode) bool) bool {
return any(s, func(n INode) bool {
castNode := n.(*FileChangeNode)
castNode := n.(*FileNode)
return test(castNode)
})
}
func (n *FileChangeNode) Flatten(collapsedPaths map[string]bool) []*FileChangeNode {
func (n *FileNode) Flatten(collapsedPaths map[string]bool) []*FileNode {
results := flatten(n, collapsedPaths)
nodes := make([]*FileChangeNode, len(results))
nodes := make([]*FileNode, len(results))
for i, result := range results {
nodes[i] = result.(*FileChangeNode)
nodes[i] = result.(*FileNode)
}
return nodes
}
func (node *FileChangeNode) GetNodeAtIndex(index int, collapsedPaths map[string]bool) *FileChangeNode {
return getNodeAtIndex(node, index, collapsedPaths).(*FileChangeNode)
func (node *FileNode) GetNodeAtIndex(index int, collapsedPaths map[string]bool) *FileNode {
return getNodeAtIndex(node, index, collapsedPaths).(*FileNode)
}
func (node *FileChangeNode) GetIndexForPath(path string, collapsedPaths map[string]bool) (int, bool) {
func (node *FileNode) GetIndexForPath(path string, collapsedPaths map[string]bool) (int, bool) {
return getIndexForPath(node, path, collapsedPaths)
}
func (node *FileChangeNode) Size(collapsedPaths map[string]bool) int {
func (node *FileNode) Size(collapsedPaths map[string]bool) int {
return size(node, collapsedPaths)
}
func (s *FileChangeNode) Compress() {
func (s *FileNode) Compress() {
// with these functions I try to only have type conversion code on the actual struct,
// but comparing interface values to nil is fraught with danger so I'm duplicating
// that code here.
@ -116,17 +116,17 @@ func (s *FileChangeNode) Compress() {
}
// This ignores the root
func (node *FileChangeNode) GetPathsMatching(test func(*FileChangeNode) bool) []string {
func (node *FileNode) GetPathsMatching(test func(*FileNode) bool) []string {
return getPathsMatching(node, func(n INode) bool {
return test(n.(*FileChangeNode))
return test(n.(*FileNode))
})
}
func (s *FileChangeNode) GetLeaves() []*FileChangeNode {
func (s *FileNode) GetLeaves() []*FileNode {
leaves := getLeaves(s)
castLeaves := make([]*FileChangeNode, len(leaves))
castLeaves := make([]*FileNode, len(leaves))
for i := range leaves {
castLeaves[i] = leaves[i].(*FileChangeNode)
castLeaves[i] = leaves[i].(*FileNode)
}
return castLeaves
@ -134,29 +134,29 @@ func (s *FileChangeNode) GetLeaves() []*FileChangeNode {
// extra methods
func (s *FileChangeNode) GetHasUnstagedChanges() bool {
func (s *FileNode) GetHasUnstagedChanges() bool {
return s.AnyFile(func(file *models.File) bool { return file.HasUnstagedChanges })
}
func (s *FileChangeNode) GetHasStagedChanges() bool {
func (s *FileNode) GetHasStagedChanges() bool {
return s.AnyFile(func(file *models.File) bool { return file.HasStagedChanges })
}
func (s *FileChangeNode) GetHasInlineMergeConflicts() bool {
func (s *FileNode) GetHasInlineMergeConflicts() bool {
return s.AnyFile(func(file *models.File) bool { return file.HasInlineMergeConflicts })
}
func (s *FileChangeNode) GetIsTracked() bool {
func (s *FileNode) GetIsTracked() bool {
return s.AnyFile(func(file *models.File) bool { return file.Tracked })
}
func (s *FileChangeNode) AnyFile(test func(file *models.File) bool) bool {
return s.Any(func(node *FileChangeNode) bool {
func (s *FileNode) AnyFile(test func(file *models.File) bool) bool {
return s.Any(func(node *FileNode) bool {
return node.IsLeaf() && test(node.File)
})
}
func (s *FileChangeNode) NameAtDepth(depth int) string {
func (s *FileNode) NameAtDepth(depth int) string {
splitName := strings.Split(s.Path, string(os.PathSeparator))
name := filepath.Join(splitName[depth:]...)

View File

@ -10,8 +10,8 @@ import (
func TestCompress(t *testing.T) {
scenarios := []struct {
name string
root *FileChangeNode
expected *FileChangeNode
root *FileNode
expected *FileNode
}{
{
name: "nil node",
@ -20,27 +20,27 @@ func TestCompress(t *testing.T) {
},
{
name: "leaf node",
root: &FileChangeNode{
root: &FileNode{
Path: "",
Children: []*FileChangeNode{
Children: []*FileNode{
{File: &models.File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Path: "test"},
},
},
expected: &FileChangeNode{
expected: &FileNode{
Path: "",
Children: []*FileChangeNode{
Children: []*FileNode{
{File: &models.File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Path: "test"},
},
},
},
{
name: "big example",
root: &FileChangeNode{
root: &FileNode{
Path: "",
Children: []*FileChangeNode{
Children: []*FileNode{
{
Path: "dir1",
Children: []*FileChangeNode{
Children: []*FileNode{
{
File: &models.File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true},
Path: "dir1/file2",
@ -49,7 +49,7 @@ func TestCompress(t *testing.T) {
},
{
Path: "dir2",
Children: []*FileChangeNode{
Children: []*FileNode{
{
File: &models.File{Name: "file3", ShortStatus: " M", HasStagedChanges: true},
Path: "dir2/file3",
@ -62,10 +62,10 @@ func TestCompress(t *testing.T) {
},
{
Path: "dir3",
Children: []*FileChangeNode{
Children: []*FileNode{
{
Path: "dir3/dir3-1",
Children: []*FileChangeNode{
Children: []*FileNode{
{
File: &models.File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true},
Path: "dir3/dir3-1/file5",
@ -80,9 +80,9 @@ func TestCompress(t *testing.T) {
},
},
},
expected: &FileChangeNode{
expected: &FileNode{
Path: "",
Children: []*FileChangeNode{
Children: []*FileNode{
{
Path: "dir1/file2",
File: &models.File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true},
@ -90,7 +90,7 @@ func TestCompress(t *testing.T) {
},
{
Path: "dir2",
Children: []*FileChangeNode{
Children: []*FileNode{
{
File: &models.File{Name: "file3", ShortStatus: " M", HasStagedChanges: true},
Path: "dir2/file3",

View File

@ -15,7 +15,7 @@ func (gui *Gui) handleCreateFilteringMenuPanel(g *gocui.Gui, v *gocui.View) erro
fileName := ""
switch v.Name() {
case "files":
node := gui.getSelectedFileChangeNode()
node := gui.getSelectedFileNode()
if node != nil {
fileName = node.GetPath()
}

View File

@ -304,12 +304,12 @@ type guiStateMutexes struct {
}
type guiState struct {
FileChangeManager *filetree.FileChangeManager
CommitFileChangeManager *filetree.CommitFileChangeManager
Submodules []*models.SubmoduleConfig
Branches []*models.Branch
Commits []*models.Commit
StashEntries []*models.StashEntry
FileManager *filetree.FileManager
CommitFileManager *filetree.CommitFileManager
Submodules []*models.SubmoduleConfig
Branches []*models.Branch
Commits []*models.Commit
StashEntries []*models.StashEntry
// Suggestions will sometimes appear when typing into a prompt
Suggestions []*types.Suggestion
// FilteredReflogCommits are the ones that appear in the reflog panel.
@ -381,12 +381,12 @@ func (gui *Gui) resetState() {
showTree := gui.Config.GetUserConfig().Gui.ShowFileTree
gui.State = &guiState{
FileChangeManager: filetree.NewFileChangeManager(make([]*models.File, 0), gui.Log, showTree),
CommitFileChangeManager: filetree.NewCommitFileChangeManager(make([]*models.CommitFile, 0), gui.Log, showTree),
Commits: make([]*models.Commit, 0),
FilteredReflogCommits: make([]*models.Commit, 0),
ReflogCommits: make([]*models.Commit, 0),
StashEntries: make([]*models.StashEntry, 0),
FileManager: filetree.NewFileChangeManager(make([]*models.File, 0), gui.Log, showTree),
CommitFileManager: filetree.NewCommitFileManager(make([]*models.CommitFile, 0), gui.Log, showTree),
Commits: make([]*models.Commit, 0),
FilteredReflogCommits: make([]*models.Commit, 0),
ReflogCommits: make([]*models.Commit, 0),
StashEntries: make([]*models.StashEntry, 0),
Panels: &panelStates{
// TODO: work out why some of these are -1 and some are 0. Last time I checked there was a good reason but I'm less certain now
Files: &filePanelState{listPanelState{SelectedLineIdx: -1}},

View File

@ -229,7 +229,7 @@ func (gui *Gui) handleMouseScrollDown(g *gocui.Gui, v *gocui.View) error {
func (gui *Gui) getSelectedCommitFileName() string {
idx := gui.State.Panels.CommitFiles.SelectedLineIdx
return gui.State.CommitFileChangeManager.GetItemAtIndex(idx).GetPath()
return gui.State.CommitFileManager.GetItemAtIndex(idx).GetPath()
}
func (gui *Gui) refreshMainViewForLineByLine(state *lBlPanelState) error {

View File

@ -264,7 +264,7 @@ func (gui *Gui) filesListContext() *ListContext {
return &ListContext{
ViewName: "files",
ContextKey: FILES_CONTEXT_KEY,
GetItemsLength: func() int { return gui.State.FileChangeManager.GetItemsLength() },
GetItemsLength: func() int { return gui.State.FileManager.GetItemsLength() },
GetPanelState: func() IListPanelState { return gui.State.Panels.Files },
OnFocus: gui.focusAndSelectFile,
OnClickSelectedItem: gui.handleFilePress,
@ -272,7 +272,7 @@ func (gui *Gui) filesListContext() *ListContext {
ResetMainViewOriginOnFocus: false,
Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
lines := gui.State.FileChangeManager.Render(gui.State.Modes.Diffing.Ref, gui.State.Submodules)
lines := gui.State.FileManager.Render(gui.State.Modes.Diffing.Ref, gui.State.Submodules)
mappedLines := make([][]string, len(lines))
for i, line := range lines {
mappedLines[i] = []string{line}
@ -281,7 +281,7 @@ func (gui *Gui) filesListContext() *ListContext {
return mappedLines
},
SelectedItem: func() (ListItem, bool) {
item := gui.getSelectedFileChangeNode()
item := gui.getSelectedFileNode()
return item, item != nil
},
}
@ -454,18 +454,18 @@ func (gui *Gui) commitFilesListContext() *ListContext {
ViewName: "commitFiles",
WindowName: "commits",
ContextKey: COMMIT_FILES_CONTEXT_KEY,
GetItemsLength: func() int { return gui.State.CommitFileChangeManager.GetItemsLength() },
GetItemsLength: func() int { return gui.State.CommitFileManager.GetItemsLength() },
GetPanelState: func() IListPanelState { return gui.State.Panels.CommitFiles },
OnFocus: gui.handleCommitFileSelect,
Gui: gui,
ResetMainViewOriginOnFocus: true,
Kind: SIDE_CONTEXT,
GetDisplayStrings: func() [][]string {
if gui.State.CommitFileChangeManager.GetItemsLength() == 0 {
if gui.State.CommitFileManager.GetItemsLength() == 0 {
return [][]string{{utils.ColoredString("(none)", color.FgRed)}}
}
lines := gui.State.CommitFileChangeManager.Render(gui.State.Modes.Diffing.Ref, gui.GitCommand.PatchManager)
lines := gui.State.CommitFileManager.Render(gui.State.Modes.Diffing.Ref, gui.GitCommand.PatchManager)
mappedLines := make([][]string, len(lines))
for i, line := range lines {
mappedLines[i] = []string{line}

View File

@ -33,7 +33,7 @@ func (gui *Gui) refreshPatchBuildingPanel(selectedLineIdx int, state *lBlPanelSt
return nil
}
to := gui.State.CommitFileChangeManager.GetParent()
to := gui.State.CommitFileManager.GetParent()
from, reverse := gui.getFromAndReverseArgsForDiff(to)
diff, err := gui.GitCommand.ShowFileDiff(from, to, reverse, node.GetPath(), true)
if err != nil {

View File

@ -98,7 +98,7 @@ func (gui *Gui) handleResetSubmodule(submodule *models.SubmoduleConfig) error {
}
func (gui *Gui) fileForSubmodule(submodule *models.SubmoduleConfig) *models.File {
for _, file := range gui.State.FileChangeManager.GetAllFiles() {
for _, file := range gui.State.FileManager.GetAllFiles() {
if file.IsSubmodule([]*models.SubmoduleConfig{submodule}) {
return file
}