diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-03-21 10:23:14 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2021-03-30 21:57:00 +1100 |
commit | 1b94462410daa7424f1d050549d4da278da4a02b (patch) | |
tree | 91004f85f88380c69e040d093256e6dfaea78bda /pkg | |
parent | 120bb443febe96dfb72e6f5859df697e5fb27e0a (diff) |
rename some things
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/commands/files.go | 10 | ||||
-rw-r--r-- | pkg/commands/models/status_line.go | 2 | ||||
-rw-r--r-- | pkg/commands/models/status_line_node.go | 50 | ||||
-rw-r--r-- | pkg/commands/models/status_line_node_test.go | 30 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 34 | ||||
-rw-r--r-- | pkg/gui/gui.go | 4 | ||||
-rw-r--r-- | pkg/gui/list_context.go | 6 | ||||
-rw-r--r-- | pkg/gui/status_line_manager.go | 30 | ||||
-rw-r--r-- | pkg/gui/status_line_manager_test.go | 18 | ||||
-rw-r--r-- | pkg/gui/status_tree.go | 14 | ||||
-rw-r--r-- | pkg/gui/submodules_panel.go | 2 |
11 files changed, 100 insertions, 100 deletions
diff --git a/pkg/commands/files.go b/pkg/commands/files.go index 163e006e1..82d3ae244 100644 --- a/pkg/commands/files.go +++ b/pkg/commands/files.go @@ -137,12 +137,12 @@ func (c *GitCommand) DiscardAllFileChanges(file *models.File) error { return c.DiscardUnstagedFileChanges(file) } -func (c *GitCommand) DiscardAllDirChanges(node *models.StatusLineNode) error { +func (c *GitCommand) DiscardAllDirChanges(node *models.FileChangeNode) 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 *models.StatusLineNode) error { +func (c *GitCommand) DiscardUnstagedDirChanges(node *models.FileChangeNode) error { if err := c.RemoveUntrackedDirFiles(node); err != nil { return err } @@ -155,9 +155,9 @@ func (c *GitCommand) DiscardUnstagedDirChanges(node *models.StatusLineNode) erro return nil } -func (c *GitCommand) RemoveUntrackedDirFiles(node *models.StatusLineNode) error { +func (c *GitCommand) RemoveUntrackedDirFiles(node *models.FileChangeNode) error { untrackedFilePaths := node.GetPathsMatching( - func(n *models.StatusLineNode) bool { return n.File != nil && !n.File.GetIsTracked() }, + func(n *models.FileChangeNode) bool { return n.File != nil && !n.File.GetIsTracked() }, ) for _, path := range untrackedFilePaths { @@ -188,7 +188,7 @@ func (c *GitCommand) WorktreeFileDiff(file *models.File, plain bool, cached bool return s } -func (c *GitCommand) WorktreeFileDiffCmdStr(node models.IStatusLine, plain bool, cached bool) string { +func (c *GitCommand) WorktreeFileDiffCmdStr(node models.IFileChange, plain bool, cached bool) string { cachedArg := "" trackedArg := "--" colorArg := c.colorArg() diff --git a/pkg/commands/models/status_line.go b/pkg/commands/models/status_line.go index 57a54573c..5413b076f 100644 --- a/pkg/commands/models/status_line.go +++ b/pkg/commands/models/status_line.go @@ -1,6 +1,6 @@ package models -type IStatusLine interface { +type IFileChange interface { GetHasUnstagedChanges() bool GetHasStagedChanges() bool GetIsTracked() bool diff --git a/pkg/commands/models/status_line_node.go b/pkg/commands/models/status_line_node.go index 94527ee9f..9e0f241f3 100644 --- a/pkg/commands/models/status_line_node.go +++ b/pkg/commands/models/status_line_node.go @@ -8,14 +8,14 @@ import ( "strings" ) -type StatusLineNode struct { - Children []*StatusLineNode +type FileChangeNode struct { + Children []*FileChangeNode File *File Path string // e.g. '/path/to/mydir' Collapsed bool } -func (s *StatusLineNode) GetHasUnstagedChanges() bool { +func (s *FileChangeNode) GetHasUnstagedChanges() bool { if s.IsLeaf() { return s.File.HasUnstagedChanges } @@ -29,7 +29,7 @@ func (s *StatusLineNode) GetHasUnstagedChanges() bool { return false } -func (s *StatusLineNode) GetHasStagedChanges() bool { +func (s *FileChangeNode) GetHasStagedChanges() bool { if s.IsLeaf() { return s.File.HasStagedChanges } @@ -43,13 +43,13 @@ func (s *StatusLineNode) GetHasStagedChanges() bool { return false } -func (s *StatusLineNode) GetNodeAtIndex(index int, collapsedPaths map[string]bool) *StatusLineNode { +func (s *FileChangeNode) GetNodeAtIndex(index int, collapsedPaths map[string]bool) *FileChangeNode { node, _ := s.getNodeAtIndexAux(index, collapsedPaths) return node } -func (s *StatusLineNode) getNodeAtIndexAux(index int, collapsedPaths map[string]bool) (*StatusLineNode, int) { +func (s *FileChangeNode) getNodeAtIndexAux(index int, collapsedPaths map[string]bool) (*FileChangeNode, int) { offset := 1 if index == 0 { @@ -69,11 +69,11 @@ func (s *StatusLineNode) getNodeAtIndexAux(index int, collapsedPaths map[string] return nil, offset } -func (s *StatusLineNode) GetIndexForPath(path string, collapsedPaths map[string]bool) (int, bool) { +func (s *FileChangeNode) GetIndexForPath(path string, collapsedPaths map[string]bool) (int, bool) { return s.getIndexForPathAux(path, collapsedPaths) } -func (s *StatusLineNode) getIndexForPathAux(path string, collapsedPaths map[string]bool) (int, bool) { +func (s *FileChangeNode) getIndexForPathAux(path string, collapsedPaths map[string]bool) (int, bool) { offset := 0 if s.Path == path { @@ -93,11 +93,11 @@ func (s *StatusLineNode) getIndexForPathAux(path string, collapsedPaths map[stri return offset, false } -func (s *StatusLineNode) IsLeaf() bool { +func (s *FileChangeNode) IsLeaf() bool { return len(s.Children) == 0 } -func (s *StatusLineNode) Size(collapsedPaths map[string]bool) int { +func (s *FileChangeNode) Size(collapsedPaths map[string]bool) int { output := 1 if !collapsedPaths[s.GetPath()] { @@ -109,8 +109,8 @@ func (s *StatusLineNode) Size(collapsedPaths map[string]bool) int { return output } -func (s *StatusLineNode) Flatten(collapsedPaths map[string]bool) []*StatusLineNode { - arr := []*StatusLineNode{s} +func (s *FileChangeNode) Flatten(collapsedPaths map[string]bool) []*FileChangeNode { + arr := []*FileChangeNode{s} if !collapsedPaths[s.GetPath()] { for _, child := range s.Children { @@ -121,7 +121,7 @@ func (s *StatusLineNode) Flatten(collapsedPaths map[string]bool) []*StatusLineNo return arr } -func (s *StatusLineNode) Sort() { +func (s *FileChangeNode) Sort() { s.sortChildren() for _, child := range s.Children { @@ -129,12 +129,12 @@ func (s *StatusLineNode) Sort() { } } -func (s *StatusLineNode) sortChildren() { +func (s *FileChangeNode) sortChildren() { if s.IsLeaf() { return } - sortedChildren := make([]*StatusLineNode, len(s.Children)) + sortedChildren := make([]*FileChangeNode, len(s.Children)) copy(sortedChildren, s.Children) sort.Slice(sortedChildren, func(i, j int) bool { @@ -153,7 +153,7 @@ func (s *StatusLineNode) sortChildren() { } // returns true if any descendant file is tracked -func (s *StatusLineNode) GetIsTracked() bool { +func (s *FileChangeNode) GetIsTracked() bool { if s.File != nil { return s.File.GetIsTracked() } @@ -167,11 +167,11 @@ func (s *StatusLineNode) GetIsTracked() bool { return false } -func (s *StatusLineNode) GetPath() string { +func (s *FileChangeNode) GetPath() string { return s.Path } -func (s *StatusLineNode) Compress() { +func (s *FileChangeNode) Compress() { if s == nil { return } @@ -179,7 +179,7 @@ func (s *StatusLineNode) Compress() { s.compressAux() } -func (s *StatusLineNode) compressAux() *StatusLineNode { +func (s *FileChangeNode) compressAux() *FileChangeNode { if s.IsLeaf() { return s } @@ -198,12 +198,12 @@ func (s *StatusLineNode) compressAux() *StatusLineNode { return s } -func (s *StatusLineNode) HasExactlyOneChild() bool { +func (s *FileChangeNode) HasExactlyOneChild() bool { return len(s.Children) == 1 } // This ignores the root -func (s *StatusLineNode) GetPathsMatching(test func(*StatusLineNode) bool) []string { +func (s *FileChangeNode) GetPathsMatching(test func(*FileChangeNode) bool) []string { paths := []string{} if test(s) { @@ -217,15 +217,15 @@ func (s *StatusLineNode) GetPathsMatching(test func(*StatusLineNode) bool) []str return paths } -func (s *StatusLineNode) ID() string { +func (s *FileChangeNode) ID() string { return s.GetPath() } -func (s *StatusLineNode) Description() string { +func (s *FileChangeNode) Description() string { return s.GetPath() } -func (s *StatusLineNode) ForEachFile(cb func(*File) error) error { +func (s *FileChangeNode) ForEachFile(cb func(*File) error) error { if s.File != nil { if err := cb(s.File); err != nil { return err @@ -241,7 +241,7 @@ func (s *StatusLineNode) ForEachFile(cb func(*File) error) error { return nil } -func (s *StatusLineNode) NameAtDepth(depth int) string { +func (s *FileChangeNode) NameAtDepth(depth int) string { splitName := strings.Split(s.Path, string(os.PathSeparator)) name := filepath.Join(splitName[depth:]...) diff --git a/pkg/commands/models/status_line_node_test.go b/pkg/commands/models/status_line_node_test.go index 5f0a1a853..0f0f95ce5 100644 --- a/pkg/commands/models/status_line_node_test.go +++ b/pkg/commands/models/status_line_node_test.go @@ -9,8 +9,8 @@ import ( func TestCompress(t *testing.T) { scenarios := []struct { name string - root *StatusLineNode - expected *StatusLineNode + root *FileChangeNode + expected *FileChangeNode }{ { name: "nil node", @@ -19,28 +19,28 @@ func TestCompress(t *testing.T) { }, { name: "leaf node", - root: &StatusLineNode{ + root: &FileChangeNode{ Name: "", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ {File: &File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Name: "test"}, }, }, - expected: &StatusLineNode{ + expected: &FileChangeNode{ Name: "", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ {File: &File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Name: "test"}, }, }, }, { name: "big example", - root: &StatusLineNode{ + root: &FileChangeNode{ Name: "", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ { Name: "dir1", Path: "dir1", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ { File: &File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true}, Name: "file2", @@ -51,7 +51,7 @@ func TestCompress(t *testing.T) { { Name: "dir2", Path: "dir2", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ { File: &File{Name: "file3", ShortStatus: " M", HasStagedChanges: true}, Name: "file3", @@ -67,11 +67,11 @@ func TestCompress(t *testing.T) { { Name: "dir3", Path: "dir3", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ { Name: "dir3-1", Path: "dir3/dir3-1", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ { File: &File{Name: "file5", ShortStatus: "M ", HasUnstagedChanges: true}, Name: "file5", @@ -88,9 +88,9 @@ func TestCompress(t *testing.T) { }, }, }, - expected: &StatusLineNode{ + expected: &FileChangeNode{ Name: "", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ { Name: "dir1/file2", File: &File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true}, @@ -99,7 +99,7 @@ func TestCompress(t *testing.T) { { Name: "dir2", Path: "dir2", - Children: []*StatusLineNode{ + Children: []*FileChangeNode{ { File: &File{Name: "file3", ShortStatus: " M", HasStagedChanges: true}, Name: "file3", diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 01ae3b14b..6d3bdbec5 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -21,13 +21,13 @@ import ( // list panel functions -func (gui *Gui) getSelectedStatusNode() *models.StatusLineNode { +func (gui *Gui) getSelectedStatusNode() *models.FileChangeNode { selectedLine := gui.State.Panels.Files.SelectedLineIdx if selectedLine == -1 { return nil } - return gui.State.StatusLineManager.GetItemAtIndex(selectedLine) + return gui.State.FileChangeManager.GetItemAtIndex(selectedLine) } func (gui *Gui) getSelectedFile() *models.File { @@ -36,7 +36,7 @@ func (gui *Gui) getSelectedFile() *models.File { return nil } - node := gui.State.StatusLineManager.GetItemAtIndex(selectedLine) + node := gui.State.FileChangeManager.GetItemAtIndex(selectedLine) if node == nil { return nil } @@ -156,7 +156,7 @@ func (gui *Gui) refreshFilesAndSubmodules() error { // specific functions func (gui *Gui) stagedFiles() []*models.File { - files := gui.State.StatusLineManager.GetAllFiles() + files := gui.State.FileChangeManager.GetAllFiles() result := make([]*models.File, 0) for _, file := range files { if file.HasStagedChanges { @@ -167,7 +167,7 @@ func (gui *Gui) stagedFiles() []*models.File { } func (gui *Gui) trackedFiles() []*models.File { - files := gui.State.StatusLineManager.GetAllFiles() + files := gui.State.FileChangeManager.GetAllFiles() result := make([]*models.File, 0, len(files)) for _, file := range files { if file.Tracked { @@ -264,7 +264,7 @@ func (gui *Gui) handleFilePress() error { } func (gui *Gui) allFilesStaged() bool { - for _, file := range gui.State.StatusLineManager.GetAllFiles() { + for _, file := range gui.State.FileChangeManager.GetAllFiles() { if file.HasUnstagedChanges { return false } @@ -525,24 +525,24 @@ func (gui *Gui) refreshStateFiles() error { selectedNode := gui.getSelectedStatusNode() - prevNodes := gui.State.StatusLineManager.GetAllItems() + prevNodes := gui.State.FileChangeManager.GetAllItems() prevSelectedLineIdx := gui.State.Panels.Files.SelectedLineIdx files := gui.GitCommand.GetStatusFiles(commands.GetStatusFileOptions{}) - gui.State.StatusLineManager.SetFiles(files) + gui.State.FileChangeManager.SetFiles(files) if err := gui.fileWatcher.addFilesToFileWatcher(files); err != nil { return err } if selectedNode != nil { - newIdx := gui.findNewSelectedIdx(prevNodes[prevSelectedLineIdx:], gui.State.StatusLineManager.GetAllItems()) + newIdx := gui.findNewSelectedIdx(prevNodes[prevSelectedLineIdx:], gui.State.FileChangeManager.GetAllItems()) if newIdx != -1 && newIdx != prevSelectedLineIdx { gui.State.Panels.Files.SelectedLineIdx = newIdx } } - gui.refreshSelectedLine(gui.State.Panels.Files, gui.State.StatusLineManager.GetItemsLength()) + gui.refreshSelectedLine(gui.State.Panels.Files, gui.State.FileChangeManager.GetItemsLength()) return nil } @@ -553,8 +553,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 []*models.StatusLineNode, currNodes []*models.StatusLineNode) int { - getPaths := func(node *models.StatusLineNode) []string { +func (gui *Gui) findNewSelectedIdx(prevNodes []*models.FileChangeNode, currNodes []*models.FileChangeNode) int { + getPaths := func(node *models.FileChangeNode) []string { if node == nil { return nil } @@ -773,7 +773,7 @@ func (gui *Gui) openFile(filename string) error { } func (gui *Gui) anyFilesWithMergeConflicts() bool { - for _, file := range gui.State.StatusLineManager.GetAllFiles() { + for _, file := range gui.State.FileChangeManager.GetAllFiles() { if file.HasMergeConflicts { return true } @@ -824,7 +824,7 @@ func (gui *Gui) handleToggleDirCollapsed() error { return nil } - gui.State.StatusLineManager.ToggleCollapsed(node) + gui.State.FileChangeManager.ToggleCollapsed(node) if err := gui.postRefreshUpdate(gui.Contexts.Files.Context); err != nil { gui.Log.Error(err) @@ -840,12 +840,12 @@ func (gui *Gui) handleToggleFileTreeView() error { if node != nil { path = node.Path } - gui.State.StatusLineManager.ShowTree = !gui.State.StatusLineManager.ShowTree - gui.State.StatusLineManager.SetTree() + gui.State.FileChangeManager.ShowTree = !gui.State.FileChangeManager.ShowTree + gui.State.FileChangeManager.SetTree() // find that same node in the new format and move the cursor to it if path != "" { - index, found := gui.State.StatusLineManager.GetIndexForPath(path) + index, found := gui.State.FileChangeManager.GetIndexForPath(path) if found { gui.filesListContext().GetPanelState().SetSelectedLineIdx(index) } diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index e7ca0bf5e..b36ab14db 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -303,7 +303,7 @@ type guiStateMutexes struct { } type guiState struct { - StatusLineManager *StatusLineManager + FileChangeManager *FileChangeManager Submodules []*models.SubmoduleConfig Branches []*models.Branch Commits []*models.Commit @@ -380,7 +380,7 @@ func (gui *Gui) resetState() { showTree := gui.Config.GetUserConfig().Gui.ShowFileTree gui.State = &guiState{ - StatusLineManager: NewStatusLineManager(make([]*models.File, 0), gui.Log, showTree), + FileChangeManager: NewFileChangeManager(make([]*models.File, 0), gui.Log, showTree), Commits: make([]*models.Commit, 0), FilteredReflogCommits: make([]*models.Commit, 0), ReflogCommits: make([]*models.Commit, 0), diff --git a/pkg/gui/list_context.go b/pkg/gui/list_context.go index 748813f4f..c0df02014 100644 --- a/pkg/gui/list_context.go +++ b/pkg/gui/list_context.go @@ -262,7 +262,7 @@ func (gui *Gui) filesListContext() *ListContext { return &ListContext{ ViewName: "files", ContextKey: FILES_CONTEXT_KEY, - GetItemsLength: func() int { return gui.State.StatusLineManager.GetItemsLength() }, + GetItemsLength: func() int { return gui.State.FileChangeManager.GetItemsLength() }, GetPanelState: func() IListPanelState { return gui.State.Panels.Files }, OnFocus: gui.focusAndSelectFile, OnClickSelectedItem: gui.handleFilePress, @@ -270,7 +270,7 @@ func (gui *Gui) filesListContext() *ListContext { ResetMainViewOriginOnFocus: false, Kind: SIDE_CONTEXT, GetDisplayStrings: func() [][]string { - lines := gui.State.StatusLineManager.Render(gui.State.Modes.Diffing.Ref, gui.State.Submodules) + lines := gui.State.FileChangeManager.Render(gui.State.Modes.Diffing.Ref, gui.State.Submodules) mappedLines := make([][]string, len(lines)) for i, line := range lines { mappedLines[i] = []string{line} @@ -279,7 +279,7 @@ func (gui *Gui) filesListContext() *ListContext { return mappedLines // TODO: Fix this up - return presentation.GetFileListDisplayStrings(gui.State.StatusLineManager.GetAllFiles(), gui.State.Modes.Diffing.Ref, gui.State.Submodules) + return presentation.GetFileListDisplayStrings(gui.State.FileChangeManager.GetAllFiles(), gui.State.Modes.Diffing.Ref, gui.State.Submodules) }, SelectedItem: func() (ListItem, bool) { item := gui.getSelectedStatusNode() diff --git a/pkg/gui/status_line_manager.go b/pkg/gui/status_line_manager.go index 14300a0f8..41c0d07d1 100644 --- a/pkg/gui/status_line_manager.go +++ b/pkg/gui/status_line_manager.go @@ -12,16 +12,16 @@ import ( const EXPANDED_ARROW = "▼" const COLLAPSED_ARROW = "►" -type StatusLineManager struct { +type FileChangeManager struct { Files []*models.File - Tree *models.StatusLineNode + Tree *models.FileChangeNode ShowTree bool Log *logrus.Entry CollapsedPaths map[string]bool } -func NewStatusLineManager(files []*models.File, log *logrus.Entry, showTree bool) *StatusLineManager { - return &StatusLineManager{ +func NewFileChangeManager(files []*models.File, log *logrus.Entry, showTree bool) *FileChangeManager { + return &FileChangeManager{ Files: files, Log: log, ShowTree: showTree, @@ -29,17 +29,17 @@ func NewStatusLineManager(files []*models.File, log *logrus.Entry, showTree bool } } -func (m *StatusLineManager) GetItemAtIndex(index int) *models.StatusLineNode { +func (m *FileChangeManager) GetItemAtIndex(index int) *models.FileChangeNode { // 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 *StatusLineManager) GetIndexForPath(path string) (int, bool) { +func (m *FileChangeManager) GetIndexForPath(path string) (int, bool) { index, found := m.Tree.GetIndexForPath(path, m.CollapsedPaths) return index - 1, found } -func (m *StatusLineManager) GetAllItems() []*models.StatusLineNode { +func (m *FileChangeManager) GetAllItems() []*models.FileChangeNode { if m.Tree == nil { return nil } @@ -47,21 +47,21 @@ func (m *StatusLineManager) GetAllItems() []*models.StatusLineNode { return m.Tree.Flatten(m.CollapsedPaths)[1:] // ignoring root } -func (m *StatusLineManager) GetItemsLength() int { +func (m *FileChangeManager) GetItemsLength() int { return m.Tree.Size(m.CollapsedPaths) - 1 // ignoring root } -func (m *StatusLineManager) GetAllFiles() []*models.File { +func (m *FileChangeManager) GetAllFiles() []*models.File { return m.Files } -func (m *StatusLineManager) SetFiles(files []*models.File) { +func (m *FileChangeManager) SetFiles(files []*models.File) { m.Files = files m.SetTree() } -func (m *StatusLineManager) SetTree() { +func (m *FileChangeManager) SetTree() { if m.ShowTree { m.Tree = GetTreeFromStatusFiles(m.Files, m.Log) } else { @@ -69,7 +69,7 @@ func (m *StatusLineManager) SetTree() { } } -func (m *StatusLineManager) Render(diffName string, submoduleConfigs []*models.SubmoduleConfig) []string { +func (m *FileChangeManager) Render(diffName string, submoduleConfigs []*models.SubmoduleConfig) []string { return m.renderAux(m.Tree, "", -1, diffName, submoduleConfigs) } @@ -78,15 +78,15 @@ const LAST_ITEM = "└─ " const NESTED = "│ " const NOTHING = " " -func (m *StatusLineManager) IsCollapsed(s *models.StatusLineNode) bool { +func (m *FileChangeManager) IsCollapsed(s *models.FileChangeNode) bool { return m.CollapsedPaths[s.GetPath()] } -func (m *StatusLineManager) ToggleCollapsed(s *models.StatusLineNode) { +func (m *FileChangeManager) ToggleCollapsed(s *models.FileChangeNode) { m.CollapsedPaths[s.GetPath()] = !m.CollapsedPaths[s.GetPath()] } -func (m *StatusLineManager) renderAux(s *models.StatusLineNode, prefix string, depth int, diffName string, submoduleConfigs []*models.SubmoduleConfig) []string { +func (m *FileChangeManager) renderAux(s *models.FileChangeNode, prefix string, depth int, diffName string, submoduleConfigs []*models.SubmoduleConfig) []string { isRoot := depth == -1 if s == nil { return []string{} diff --git a/pkg/gui/status_line_manager_test.go b/pkg/gui/status_line_manager_test.go index 7ef5c15e6..3d078f61d 100644 --- a/pkg/gui/status_line_manager_test.go +++ b/pkg/gui/status_line_manager_test.go @@ -10,7 +10,7 @@ import ( func TestRender(t *testing.T) { scenarios := []struct { name string - root *models.StatusLineNode + root *models.FileChangeNode expected []string }{ { @@ -20,9 +20,9 @@ func TestRender(t *testing.T) { }, { name: "leaf node", - root: &models.StatusLineNode{ + root: &models.FileChangeNode{ Path: "", - Children: []*models.StatusLineNode{ + Children: []*models.FileChangeNode{ {File: &models.File{Name: "test", ShortStatus: " M", HasStagedChanges: true}, Path: "test"}, }, }, @@ -30,13 +30,13 @@ func TestRender(t *testing.T) { }, { name: "big example", - root: &models.StatusLineNode{ + root: &models.FileChangeNode{ Path: "", - Children: []*models.StatusLineNode{ + Children: []*models.FileChangeNode{ { Path: "dir1", Collapsed: true, - Children: []*models.StatusLineNode{ + Children: []*models.FileChangeNode{ { File: &models.File{Name: "file2", ShortStatus: "M ", HasUnstagedChanges: true}, Path: "file2", @@ -45,10 +45,10 @@ func TestRender(t *testing.T) { }, { Path: "dir2", - Children: []*models.StatusLineNode{ + Children: []*models.FileChangeNode{ { Path: "dir2", - Children: []*models.StatusLineNode{ + Children: []*models.FileChangeNode{ { File: &models.File{Name: "file3", ShortStatus: " M", HasStagedChanges: true}, Path: "file3", @@ -79,7 +79,7 @@ func TestRender(t *testing.T) { for _, s := range scenarios { s := s t.Run(s.name, func(t *testing.T) { - mngr := &StatusLineManager{Tree: s.root} + mngr := &FileChangeManager{Tree: s.root} result := mngr.Render("", nil) assert.EqualValues(t, s.expected, result) }) diff --git a/pkg/gui/status_tree.go b/pkg/gui/status_tree.go index 37de6c95e..f95dff160 100644 --- a/pkg/gui/status_tree.go +++ b/pkg/gui/status_tree.go @@ -10,10 +10,10 @@ import ( "github.com/sirupsen/logrus" ) -func GetTreeFromStatusFiles(files []*models.File, log *logrus.Entry) *models.StatusLineNode { - root := &models.StatusLineNode{} +func GetTreeFromStatusFiles(files []*models.File, log *logrus.Entry) *models.FileChangeNode { + root := &models.FileChangeNode{} - var curr *models.StatusLineNode + var curr *models.FileChangeNode for _, file := range files { split := strings.Split(file.Name, string(os.PathSeparator)) curr = root @@ -34,7 +34,7 @@ func GetTreeFromStatusFiles(files []*models.File, log *logrus.Entry) *models.Sta } } - newChild := &models.StatusLineNode{ + newChild := &models.FileChangeNode{ Path: path, File: setFile, } @@ -50,10 +50,10 @@ func GetTreeFromStatusFiles(files []*models.File, log *logrus.Entry) *models.Sta return root } -func GetFlatTreeFromStatusFiles(files []*models.File) *models.StatusLineNode { - root := &models.StatusLineNode{} +func GetFlatTreeFromStatusFiles(files []*models.File) *models.FileChangeNode { + root := &models.FileChangeNode{} for _, file := range files { - root.Children = append(root.Children, &models.StatusLineNode{ + root.Children = append(root.Children, &models.FileChangeNode{ Path: file.GetPath(), File: file, }) diff --git a/pkg/gui/submodules_panel.go b/pkg/gui/submodules_panel.go index c9ce7168a..ad513141d 100644 --- a/pkg/gui/submodules_panel.go +++ b/pkg/gui/submodules_panel.go @@ -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.StatusLineManager.GetAllFiles() { + for _, file := range gui.State.FileChangeManager.GetAllFiles() { if file.IsSubmodule([]*models.SubmoduleConfig{submodule}) { return file } |