1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00

make fields private

This commit is contained in:
Jesse Duffield 2021-03-21 15:28:18 +11:00
parent e7af3bf55d
commit 1ea78c7ae7
3 changed files with 30 additions and 25 deletions

View File

@ -840,8 +840,8 @@ func (gui *Gui) handleToggleFileTreeView() error {
if node != nil { if node != nil {
path = node.Path path = node.Path
} }
gui.State.FileChangeManager.ShowTree = !gui.State.FileChangeManager.ShowTree
gui.State.FileChangeManager.SetTree() gui.State.FileChangeManager.ToggleShowTree()
// find that same node in the new format and move the cursor to it // find that same node in the new format and move the cursor to it
if path != "" { if path != "" {

View File

@ -18,72 +18,77 @@ const NESTED = "│ "
const NOTHING = " " const NOTHING = " "
type FileChangeManager struct { type FileChangeManager struct {
Files []*models.File files []*models.File
Tree *models.FileChangeNode tree *models.FileChangeNode
ShowTree bool showTree bool
Log *logrus.Entry log *logrus.Entry
CollapsedPaths map[string]bool collapsedPaths map[string]bool
} }
func NewFileChangeManager(files []*models.File, log *logrus.Entry, showTree bool) *FileChangeManager { func NewFileChangeManager(files []*models.File, log *logrus.Entry, showTree bool) *FileChangeManager {
return &FileChangeManager{ return &FileChangeManager{
Files: files, files: files,
Log: log, log: log,
ShowTree: showTree, showTree: showTree,
CollapsedPaths: map[string]bool{}, collapsedPaths: map[string]bool{},
} }
} }
func (m *FileChangeManager) ToggleShowTree() {
m.showTree = !m.showTree
m.SetTree()
}
func (m *FileChangeManager) GetItemAtIndex(index int) *models.FileChangeNode { func (m *FileChangeManager) GetItemAtIndex(index int) *models.FileChangeNode {
// need to traverse the three depth first until we get to the index. // need to traverse the three depth first until we get to the index.
return m.Tree.GetNodeAtIndex(index+1, m.CollapsedPaths) // ignoring root return m.tree.GetNodeAtIndex(index+1, m.collapsedPaths) // ignoring root
} }
func (m *FileChangeManager) GetIndexForPath(path string) (int, bool) { func (m *FileChangeManager) GetIndexForPath(path string) (int, bool) {
index, found := m.Tree.GetIndexForPath(path, m.CollapsedPaths) index, found := m.tree.GetIndexForPath(path, m.collapsedPaths)
return index - 1, found return index - 1, found
} }
func (m *FileChangeManager) GetAllItems() []*models.FileChangeNode { func (m *FileChangeManager) GetAllItems() []*models.FileChangeNode {
if m.Tree == nil { if m.tree == nil {
return nil return nil
} }
return m.Tree.Flatten(m.CollapsedPaths)[1:] // ignoring root return m.tree.Flatten(m.collapsedPaths)[1:] // ignoring root
} }
func (m *FileChangeManager) GetItemsLength() int { func (m *FileChangeManager) GetItemsLength() int {
return m.Tree.Size(m.CollapsedPaths) - 1 // ignoring root return m.tree.Size(m.collapsedPaths) - 1 // ignoring root
} }
func (m *FileChangeManager) GetAllFiles() []*models.File { func (m *FileChangeManager) GetAllFiles() []*models.File {
return m.Files return m.files
} }
func (m *FileChangeManager) SetFiles(files []*models.File) { func (m *FileChangeManager) SetFiles(files []*models.File) {
m.Files = files m.files = files
m.SetTree() m.SetTree()
} }
func (m *FileChangeManager) SetTree() { func (m *FileChangeManager) SetTree() {
if m.ShowTree { if m.showTree {
m.Tree = BuildTreeFromFiles(m.Files) m.tree = BuildTreeFromFiles(m.files)
} else { } else {
m.Tree = BuildFlatTreeFromFiles(m.Files) m.tree = BuildFlatTreeFromFiles(m.files)
} }
} }
func (m *FileChangeManager) 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) return m.renderAux(m.tree, "", -1, diffName, submoduleConfigs)
} }
func (m *FileChangeManager) IsCollapsed(s *models.FileChangeNode) bool { func (m *FileChangeManager) IsCollapsed(s *models.FileChangeNode) bool {
return m.CollapsedPaths[s.GetPath()] return m.collapsedPaths[s.GetPath()]
} }
func (m *FileChangeManager) ToggleCollapsed(s *models.FileChangeNode) { func (m *FileChangeManager) ToggleCollapsed(s *models.FileChangeNode) {
m.CollapsedPaths[s.GetPath()] = !m.CollapsedPaths[s.GetPath()] m.collapsedPaths[s.GetPath()] = !m.collapsedPaths[s.GetPath()]
} }
func (m *FileChangeManager) renderAux(s *models.FileChangeNode, 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 {

View File

@ -83,7 +83,7 @@ func TestRender(t *testing.T) {
for _, s := range scenarios { for _, s := range scenarios {
s := s s := s
t.Run(s.name, func(t *testing.T) { t.Run(s.name, func(t *testing.T) {
mngr := &FileChangeManager{Tree: s.root, CollapsedPaths: s.collapsedPaths} mngr := &FileChangeManager{tree: s.root, collapsedPaths: s.collapsedPaths}
result := mngr.Render("", nil) result := mngr.Render("", nil)
assert.EqualValues(t, s.expected, result) assert.EqualValues(t, s.expected, result)
}) })