mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Add unstaged, staged tabs on [2] Files section
This commit is contained in:
parent
434abc7994
commit
c57461a1e6
|
|
@ -862,6 +862,14 @@ func (gui *Gui) viewTabMap() map[string][]context.TabView {
|
|||
Tab: gui.c.Tr.FilesTitle,
|
||||
ViewName: "files",
|
||||
},
|
||||
{
|
||||
Tab: gui.c.Tr.UnstagedChanges,
|
||||
ViewName: "files",
|
||||
},
|
||||
{
|
||||
Tab: gui.c.Tr.StagedChanges,
|
||||
ViewName: "files",
|
||||
},
|
||||
context.TabView{
|
||||
Tab: gui.c.Tr.WorktreesTitle,
|
||||
ViewName: "worktrees",
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
"github.com/jesseduffield/lazygit/pkg/gocui"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/context"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/filetree"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/jesseduffield/lazygit/pkg/tasks"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
|
|
@ -63,6 +64,12 @@ func (gui *Gui) onViewTabClick(windowName string, tabIndex int) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if windowName == "files" {
|
||||
if err := gui.applyFilesTab(tabs[tabIndex].Tab); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
viewName := tabs[tabIndex].ViewName
|
||||
|
||||
context, ok := gui.helpers.View.ContextForView(viewName)
|
||||
|
|
@ -114,9 +121,54 @@ func getTabbedView(gui *Gui) *gocui.View {
|
|||
// It safe assumption that only static contexts have tabs
|
||||
context := gui.c.Context().CurrentStatic()
|
||||
view, _ := gui.g.View(context.GetViewName())
|
||||
if view != nil && view.Name() == "files" {
|
||||
view.TabIndex = gui.filesTabIndex()
|
||||
}
|
||||
return view
|
||||
}
|
||||
|
||||
func (gui *Gui) filesTabIndex() int {
|
||||
if gui.State == nil || gui.State.Contexts == nil || gui.State.Contexts.Files == nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
filter := gui.State.Contexts.Files.GetStatusFilter()
|
||||
switch filter {
|
||||
case filetree.DisplayUnstaged:
|
||||
return 1
|
||||
case filetree.DisplayStaged:
|
||||
return 2
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) applyFilesTab(tabName string) error {
|
||||
if gui.State == nil || gui.State.Contexts == nil || gui.State.Contexts.Files == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
filesContext := gui.State.Contexts.Files
|
||||
desiredFilter := filetree.DisplayAll
|
||||
|
||||
switch tabName {
|
||||
case gui.c.Tr.UnstagedChanges:
|
||||
desiredFilter = filetree.DisplayUnstaged
|
||||
case gui.c.Tr.StagedChanges:
|
||||
desiredFilter = filetree.DisplayStaged
|
||||
case gui.c.Tr.FilesTitle:
|
||||
desiredFilter = filetree.DisplayAll
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
filesContext.FileTreeViewModel.SetStatusFilter(desiredFilter)
|
||||
filesContext.GetView().Subtitle = ""
|
||||
filesContext.GetView().TabIndex = gui.filesTabIndex()
|
||||
gui.postRefreshUpdate(filesContext)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gui *Gui) render() {
|
||||
gui.c.OnUIThread(func() error { return nil })
|
||||
}
|
||||
|
|
|
|||
|
|
@ -271,4 +271,8 @@ func (gui *Gui) configureViewProperties() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if gui.Views.Files != nil {
|
||||
gui.Views.Files.TabIndex = gui.filesTabIndex()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue