1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-06 03:53:59 +02:00

lots more stuff

This commit is contained in:
Jesse Duffield 2020-08-17 21:58:30 +10:00
parent e87635295a
commit ac0eedda91
17 changed files with 186 additions and 218 deletions

View File

@ -16,14 +16,6 @@ func (gui *Gui) getSelectedCommitFile() *commands.CommitFile {
return gui.State.CommitFiles[selectedLine] return gui.State.CommitFiles[selectedLine]
} }
func (gui *Gui) handleCommitFilesClick(g *gocui.Gui, v *gocui.View) error {
itemCount := len(gui.State.CommitFiles)
handleSelect := gui.wrappedHandler(gui.handleCommitFileSelect)
selectedLine := &gui.State.Panels.CommitFiles.SelectedLine
return gui.handleClick(v, itemCount, selectedLine, handleSelect)
}
func (gui *Gui) handleCommitFileSelect() error { func (gui *Gui) handleCommitFileSelect() error {
if gui.popupPanelFocused() { if gui.popupPanelFocused() {
return nil return nil

View File

@ -43,16 +43,12 @@ func (gui *Gui) handleCommitConfirm(g *gocui.Gui, v *gocui.View) error {
return nil return nil
} }
v.Clear() gui.clearEditorView(v)
_, _ = g.SetViewOnBottom("commitMessage") // TODO: bring into context code
_ = v.SetCursor(0, 0)
_ = v.SetOrigin(0, 0)
_ = gui.returnFromContext() _ = gui.returnFromContext()
return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
} }
func (gui *Gui) handleCommitClose(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCommitClose(g *gocui.Gui, v *gocui.View) error {
_, _ = g.SetViewOnBottom("commitMessage") // TODO: bring into context code
return gui.returnFromContext() return gui.returnFromContext()
} }

View File

@ -31,10 +31,6 @@ func (gui *Gui) handleCommitSelect() error {
return err return err
} }
if _, err := gui.g.SetCurrentView("commits"); err != nil {
return err
}
state := gui.State.Panels.Commits state := gui.State.Panels.Commits
if state.SelectedLine > 290 && state.LimitCommits { if state.SelectedLine > 290 && state.LimitCommits {
state.LimitCommits = false state.LimitCommits = false
@ -739,9 +735,9 @@ func (gui *Gui) handleGotoBottomForCommitsPanel(g *gocui.Gui, v *gocui.View) err
} }
} }
for _, view := range gui.getListViews() { for _, context := range gui.getListContexts() {
if view.ViewName == "commits" { if context.ViewName == "commits" {
return view.handleGotoBottom(g, v) return context.handleGotoBottom(g, v)
} }
} }

View File

@ -174,7 +174,7 @@ func (gui *Gui) onNewPopupPanel() {
"menu", "menu",
} }
for _, viewName := range viewNames { for _, viewName := range viewNames {
_, _ = gui.g.SetViewOnBottom(viewName) _, _ = gui.g.SetViewOnBottom(viewName) // TODO: investigate
} }
} }

View File

@ -76,6 +76,7 @@ type ContextTree struct {
BranchCommits CommitsContextNode BranchCommits CommitsContextNode
ReflogCommits SimpleContextNode ReflogCommits SimpleContextNode
Stash SimpleContextNode Stash SimpleContextNode
Normal SimpleContextNode
Staging SimpleContextNode Staging SimpleContextNode
PatchBuilding SimpleContextNode PatchBuilding SimpleContextNode
Merging SimpleContextNode Merging SimpleContextNode
@ -120,13 +121,26 @@ func (gui *Gui) returnFromContext() error {
gui.State.ContextStack = gui.State.ContextStack[:n] gui.State.ContextStack = gui.State.ContextStack[:n]
if err := currentContext.HandleFocusLost(); err != nil { if err := gui.deactivateContext(currentContext); err != nil {
return err return err
} }
return gui.activateContext(newContext) return gui.activateContext(newContext)
} }
func (gui *Gui) deactivateContext(c Context) error {
// if we are the kind of context that is sent to back upon deactivation, we should do that
if c.GetKind() == TEMPORARY_POPUP || c.GetKind() == PERSISTENT_POPUP {
_, _ = gui.g.SetViewOnBottom(c.GetViewName())
}
if err := c.HandleFocusLost(); err != nil {
return err
}
return nil
}
func (gui *Gui) activateContext(c Context) error { func (gui *Gui) activateContext(c Context) error {
gui.Log.Warn(gui.renderContextStack()) gui.Log.Warn(gui.renderContextStack())
@ -188,34 +202,44 @@ func (gui *Gui) createContextTree() {
}, },
}, },
Files: SimpleContextNode{ Files: SimpleContextNode{
Context: gui.filesListView(), Context: gui.filesListContext(),
}, },
Menu: SimpleContextNode{ Menu: SimpleContextNode{
Context: gui.menuListView(), Context: gui.menuListContext(),
}, },
Remotes: RemotesContextNode{ Remotes: RemotesContextNode{
Context: gui.remotesListView(), Context: gui.remotesListContext(),
Branches: SimpleContextNode{ Branches: SimpleContextNode{
Context: gui.remoteBranchesListView(), Context: gui.remoteBranchesListContext(),
}, },
}, },
BranchCommits: CommitsContextNode{ BranchCommits: CommitsContextNode{
Context: gui.branchCommitsListView(), Context: gui.branchCommitsListContext(),
Files: SimpleContextNode{ Files: SimpleContextNode{
Context: gui.commitFilesListView(), Context: gui.commitFilesListContext(),
}, },
}, },
ReflogCommits: SimpleContextNode{ ReflogCommits: SimpleContextNode{
Context: gui.reflogCommitsListView(), Context: gui.reflogCommitsListContext(),
}, },
Branches: SimpleContextNode{ Branches: SimpleContextNode{
Context: gui.branchesListView(), Context: gui.branchesListContext(),
}, },
Tags: SimpleContextNode{ Tags: SimpleContextNode{
Context: gui.tagsListView(), Context: gui.tagsListContext(),
}, },
Stash: SimpleContextNode{ Stash: SimpleContextNode{
Context: gui.stashListView(), Context: gui.stashListContext(),
},
Normal: SimpleContextNode{
Context: BasicContext{
OnFocus: func() error {
return nil // TODO: should we do something here? We should allow for scrolling the panel
},
Kind: MAIN_CONTEXT,
ViewName: "main",
Key: "normal",
},
}, },
Staging: SimpleContextNode{ Staging: SimpleContextNode{
Context: BasicContext{ Context: BasicContext{
@ -295,7 +319,18 @@ func (gui *Gui) createContextTree() {
"confirmation": gui.Contexts.Confirmation.Context, "confirmation": gui.Contexts.Confirmation.Context,
"credentials": gui.Contexts.Credentials.Context, "credentials": gui.Contexts.Credentials.Context,
"commitMessage": gui.Contexts.CommitMessage.Context, "commitMessage": gui.Contexts.CommitMessage.Context,
"main": gui.Contexts.Staging.Context, "main": gui.Contexts.Normal.Context,
"secondary": gui.Contexts.Normal.Context,
}
for viewName, context := range gui.State.ViewContextMap {
// see if the view exists. If it does, set the context on it
view, err := gui.g.View(viewName)
if err != nil {
continue
}
view.Context = context.GetKey()
} }
} }

View File

@ -37,9 +37,7 @@ func (gui *Gui) promptUserForCredential(passOrUname string) string {
func (gui *Gui) handleSubmitCredential(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleSubmitCredential(g *gocui.Gui, v *gocui.View) error {
message := gui.trimmedContent(v) message := gui.trimmedContent(v)
gui.credentials <- message gui.credentials <- message
v.Clear() gui.clearEditorView(v)
_ = v.SetCursor(0, 0)
_, _ = g.SetViewOnBottom("credentials") // TODO: move to context code
if err := gui.returnFromContext(); err != nil { if err := gui.returnFromContext(); err != nil {
return err return err
} }
@ -48,8 +46,6 @@ func (gui *Gui) handleSubmitCredential(g *gocui.Gui, v *gocui.View) error {
} }
func (gui *Gui) handleCloseCredentialsView(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleCloseCredentialsView(g *gocui.Gui, v *gocui.View) error {
_, _ = g.SetViewOnBottom("credentials")
gui.credentials <- "" gui.credentials <- ""
return gui.returnFromContext() return gui.returnFromContext()
} }
@ -68,7 +64,6 @@ func (gui *Gui) handleCredentialsViewFocused() error {
// handleCredentialsPopup handles the views after executing a command that might ask for credentials // handleCredentialsPopup handles the views after executing a command that might ask for credentials
func (gui *Gui) handleCredentialsPopup(cmdErr error) { func (gui *Gui) handleCredentialsPopup(cmdErr error) {
_, _ = gui.g.SetViewOnBottom("credentials")
if cmdErr != nil { if cmdErr != nil {
errMessage := cmdErr.Error() errMessage := cmdErr.Error()
if strings.Contains(errMessage, "Invalid username or password") { if strings.Contains(errMessage, "Invalid username or password") {

View File

@ -210,10 +210,6 @@ func (gui *Gui) allFilesStaged() bool {
} }
func (gui *Gui) focusAndSelectFile() error { func (gui *Gui) focusAndSelectFile() error {
if _, err := gui.g.SetCurrentView("files"); err != nil {
return err
}
return gui.selectFile(false) return gui.selectFile(false)
} }

View File

@ -1347,12 +1347,6 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: gui.handleStatusClick, Handler: gui.handleStatusClick,
}, },
{
ViewName: "commitFiles",
Key: gocui.MouseLeft,
Modifier: gocui.ModNone,
Handler: gui.handleCommitFilesClick,
},
{ {
ViewName: "search", ViewName: "search",
Key: gui.getKey("universal.confirm"), Key: gui.getKey("universal.confirm"),
@ -1406,39 +1400,39 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
bindings = append(bindings, &Binding{ViewName: "", Key: rune(i+1) + '0', Modifier: gocui.ModNone, Handler: gui.goToSideWindow(window)}) bindings = append(bindings, &Binding{ViewName: "", Key: rune(i+1) + '0', Modifier: gocui.ModNone, Handler: gui.goToSideWindow(window)})
} }
for _, listView := range gui.getListViews() { for _, listContext := range gui.getListContexts() {
bindings = append(bindings, []*Binding{ bindings = append(bindings, []*Binding{
{ViewName: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gui.getKey("universal.prevItem-alt"), Modifier: gocui.ModNone, Handler: listView.handlePrevLine}, {ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.prevItem-alt"), Modifier: gocui.ModNone, Handler: listContext.handlePrevLine},
{ViewName: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gui.getKey("universal.prevItem"), Modifier: gocui.ModNone, Handler: listView.handlePrevLine}, {ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.prevItem"), Modifier: gocui.ModNone, Handler: listContext.handlePrevLine},
{ViewName: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gocui.MouseWheelUp, Modifier: gocui.ModNone, Handler: listView.handlePrevLine}, {ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gocui.MouseWheelUp, Modifier: gocui.ModNone, Handler: listContext.handlePrevLine},
{ViewName: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gui.getKey("universal.nextItem-alt"), Modifier: gocui.ModNone, Handler: listView.handleNextLine}, {ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.nextItem-alt"), Modifier: gocui.ModNone, Handler: listContext.handleNextLine},
{ViewName: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gui.getKey("universal.nextItem"), Modifier: gocui.ModNone, Handler: listView.handleNextLine}, {ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.nextItem"), Modifier: gocui.ModNone, Handler: listContext.handleNextLine},
{ViewName: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gui.getKey("universal.prevPage"), Modifier: gocui.ModNone, Handler: listView.handlePrevPage, Description: gui.Tr.SLocalize("prevPage")}, {ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.prevPage"), Modifier: gocui.ModNone, Handler: listContext.handlePrevPage, Description: gui.Tr.SLocalize("prevPage")},
{ViewName: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gui.getKey("universal.nextPage"), Modifier: gocui.ModNone, Handler: listView.handleNextPage, Description: gui.Tr.SLocalize("nextPage")}, {ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.nextPage"), Modifier: gocui.ModNone, Handler: listContext.handleNextPage, Description: gui.Tr.SLocalize("nextPage")},
{ViewName: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gui.getKey("universal.gotoTop"), Modifier: gocui.ModNone, Handler: listView.handleGotoTop, Description: gui.Tr.SLocalize("gotoTop")}, {ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.gotoTop"), Modifier: gocui.ModNone, Handler: listContext.handleGotoTop, Description: gui.Tr.SLocalize("gotoTop")},
{ViewName: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: listView.handleNextLine}, {ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: listContext.handleNextLine},
{ViewName: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gocui.MouseLeft, Modifier: gocui.ModNone, Handler: listView.handleClick}, {ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gocui.MouseLeft, Modifier: gocui.ModNone, Handler: listContext.handleClick},
}...) }...)
// the commits panel needs to lazyload things so it has a couple of its own handlers // the commits panel needs to lazyload things so it has a couple of its own handlers
openSearchHandler := gui.handleOpenSearch openSearchHandler := gui.handleOpenSearch
gotoBottomHandler := listView.handleGotoBottom gotoBottomHandler := listContext.handleGotoBottom
if listView.ViewName == "commits" { if listContext.ViewName == "commits" {
openSearchHandler = gui.handleOpenSearchForCommitsPanel openSearchHandler = gui.handleOpenSearchForCommitsPanel
gotoBottomHandler = gui.handleGotoBottomForCommitsPanel gotoBottomHandler = gui.handleGotoBottomForCommitsPanel
} }
bindings = append(bindings, []*Binding{ bindings = append(bindings, []*Binding{
{ {
ViewName: listView.ViewName, ViewName: listContext.ViewName,
Contexts: []string{listView.ContextKey}, Contexts: []string{listContext.ContextKey},
Key: gui.getKey("universal.startSearch"), Key: gui.getKey("universal.startSearch"),
Handler: openSearchHandler, Handler: openSearchHandler,
Description: gui.Tr.SLocalize("startSearch"), Description: gui.Tr.SLocalize("startSearch"),
}, },
{ {
ViewName: listView.ViewName, ViewName: listContext.ViewName,
Contexts: []string{listView.ContextKey}, Contexts: []string{listContext.ContextKey},
Key: gui.getKey("universal.gotoBottom"), Key: gui.getKey("universal.gotoBottom"),
Handler: gotoBottomHandler, Handler: gotoBottomHandler,
Description: gui.Tr.SLocalize("gotoBottom"), Description: gui.Tr.SLocalize("gotoBottom"),

View File

@ -282,42 +282,42 @@ func (gui *Gui) layout(g *gocui.Gui) error {
} }
} }
type listViewState struct { type listContextState struct {
selectedLine int selectedLine int
lineCount int lineCount int
view *gocui.View view *gocui.View
context string contextKey string
listView *ListView listContext *ListContext
} }
listViewStates := []listViewState{ listContextStates := []listContextState{
{view: filesView, context: "files", selectedLine: gui.State.Panels.Files.SelectedLine, lineCount: len(gui.State.Files), listView: gui.filesListView()}, {view: filesView, contextKey: "files", selectedLine: gui.State.Panels.Files.SelectedLine, lineCount: len(gui.State.Files), listContext: gui.filesListContext()},
{view: branchesView, context: "local-branches", selectedLine: gui.State.Panels.Branches.SelectedLine, lineCount: len(gui.State.Branches), listView: gui.branchesListView()}, {view: branchesView, contextKey: "local-branches", selectedLine: gui.State.Panels.Branches.SelectedLine, lineCount: len(gui.State.Branches), listContext: gui.branchesListContext()},
{view: branchesView, context: "remotes", selectedLine: gui.State.Panels.Remotes.SelectedLine, lineCount: len(gui.State.Remotes), listView: gui.remotesListView()}, {view: branchesView, contextKey: "remotes", selectedLine: gui.State.Panels.Remotes.SelectedLine, lineCount: len(gui.State.Remotes), listContext: gui.remotesListContext()},
{view: branchesView, context: "remote-branches", selectedLine: gui.State.Panels.RemoteBranches.SelectedLine, lineCount: len(gui.State.Remotes), listView: gui.remoteBranchesListView()}, {view: branchesView, contextKey: "remote-branches", selectedLine: gui.State.Panels.RemoteBranches.SelectedLine, lineCount: len(gui.State.Remotes), listContext: gui.remoteBranchesListContext()},
{view: branchesView, context: "tags", selectedLine: gui.State.Panels.Tags.SelectedLine, lineCount: len(gui.State.Tags), listView: gui.tagsListView()}, {view: branchesView, contextKey: "tags", selectedLine: gui.State.Panels.Tags.SelectedLine, lineCount: len(gui.State.Tags), listContext: gui.tagsListContext()},
{view: commitsView, context: "branch-commits", selectedLine: gui.State.Panels.Commits.SelectedLine, lineCount: len(gui.State.Commits), listView: gui.branchCommitsListView()}, {view: commitsView, contextKey: "branch-commits", selectedLine: gui.State.Panels.Commits.SelectedLine, lineCount: len(gui.State.Commits), listContext: gui.branchCommitsListContext()},
{view: commitsView, context: "reflog-commits", selectedLine: gui.State.Panels.ReflogCommits.SelectedLine, lineCount: len(gui.State.FilteredReflogCommits), listView: gui.reflogCommitsListView()}, {view: commitsView, contextKey: "reflog-commits", selectedLine: gui.State.Panels.ReflogCommits.SelectedLine, lineCount: len(gui.State.FilteredReflogCommits), listContext: gui.reflogCommitsListContext()},
{view: stashView, context: "stash", selectedLine: gui.State.Panels.Stash.SelectedLine, lineCount: len(gui.State.StashEntries), listView: gui.stashListView()}, {view: stashView, contextKey: "stash", selectedLine: gui.State.Panels.Stash.SelectedLine, lineCount: len(gui.State.StashEntries), listContext: gui.stashListContext()},
{view: commitFilesView, context: "commit-files", selectedLine: gui.State.Panels.CommitFiles.SelectedLine, lineCount: len(gui.State.CommitFiles), listView: gui.commitFilesListView()}, {view: commitFilesView, contextKey: "commit-files", selectedLine: gui.State.Panels.CommitFiles.SelectedLine, lineCount: len(gui.State.CommitFiles), listContext: gui.commitFilesListContext()},
} }
// menu view might not exist so we check to be safe // menu view might not exist so we check to be safe
if menuView, err := gui.g.View("menu"); err == nil { if menuView, err := gui.g.View("menu"); err == nil {
listViewStates = append(listViewStates, listViewState{view: menuView, context: "menu", selectedLine: gui.State.Panels.Menu.SelectedLine, lineCount: gui.State.MenuItemCount, listView: gui.menuListView()}) listContextStates = append(listContextStates, listContextState{view: menuView, contextKey: "menu", selectedLine: gui.State.Panels.Menu.SelectedLine, lineCount: gui.State.MenuItemCount, listContext: gui.menuListContext()})
} }
for _, listViewState := range listViewStates { for _, listContextState := range listContextStates {
// ignore views where the context doesn't match up with the selected line we're trying to focus // ignore contexts whose view is owned by another context right now
if listViewState.context != "" && (listViewState.view.Context != listViewState.context) { if listContextState.view.Context != listContextState.contextKey {
continue continue
} }
// check if the selected line is now out of view and if so refocus it // check if the selected line is now out of view and if so refocus it
listViewState.view.FocusPoint(0, listViewState.selectedLine) listContextState.view.FocusPoint(0, listContextState.selectedLine)
listViewState.view.SelBgColor = theme.GocuiSelectedLineBgColor listContextState.view.SelBgColor = theme.GocuiSelectedLineBgColor
// I doubt this is expensive though it's admittedly redundant after the first render // I doubt this is expensive though it's admittedly redundant after the first render
listViewState.view.SetOnSelectItem(gui.onSelectItemWrapper(listViewState.listView.onSearchSelect)) listContextState.view.SetOnSelectItem(gui.onSelectItemWrapper(listContextState.listContext.onSearchSelect))
} }
mainViewWidth, mainViewHeight := gui.getMainView().Size() mainViewWidth, mainViewHeight := gui.getMainView().Size()
@ -339,13 +339,12 @@ func (gui *Gui) layout(g *gocui.Gui) error {
func (gui *Gui) onInitialViewsCreation() error { func (gui *Gui) onInitialViewsCreation() error {
gui.createContextTree() gui.createContextTree()
gui.switchContext(gui.Contexts.Files.Context) if err := gui.switchContext(gui.Contexts.Files.Context); err != nil {
return err
}
gui.changeMainViewsContext("normal") gui.changeMainViewsContext("normal")
gui.getBranchesView().Context = "local-branches"
gui.getCommitsView().Context = "branch-commits"
if gui.showRecentRepos { if gui.showRecentRepos {
if err := gui.handleCreateRecentReposMenu(); err != nil { if err := gui.handleCreateRecentReposMenu(); err != nil {
return err return err

View File

@ -2,7 +2,7 @@ package gui
import "github.com/jesseduffield/gocui" import "github.com/jesseduffield/gocui"
type ListView struct { type ListContext struct {
ViewName string ViewName string
ContextKey string ContextKey string
GetItemsLength func() int GetItemsLength func() int
@ -16,68 +16,68 @@ type ListView struct {
Kind int Kind int
} }
func (lv *ListView) GetKey() string { func (lc *ListContext) GetKey() string {
return lv.ContextKey return lc.ContextKey
} }
func (lv *ListView) GetKind() int { func (lc *ListContext) GetKind() int {
return lv.Kind return lc.Kind
} }
func (lv *ListView) GetViewName() string { func (lc *ListContext) GetViewName() string {
return lv.ViewName return lc.ViewName
} }
func (lv *ListView) HandleFocusLost() error { func (lc *ListContext) HandleFocusLost() error {
if lv.OnFocusLost != nil { if lc.OnFocusLost != nil {
return lv.OnFocusLost() return lc.OnFocusLost()
} }
return nil return nil
} }
func (lv *ListView) HandleFocus() error { func (lc *ListContext) HandleFocus() error {
return lv.OnFocus() return lc.OnFocus()
} }
func (lv *ListView) handlePrevLine(g *gocui.Gui, v *gocui.View) error { func (lc *ListContext) handlePrevLine(g *gocui.Gui, v *gocui.View) error {
return lv.handleLineChange(-1) return lc.handleLineChange(-1)
} }
func (lv *ListView) handleNextLine(g *gocui.Gui, v *gocui.View) error { func (lc *ListContext) handleNextLine(g *gocui.Gui, v *gocui.View) error {
return lv.handleLineChange(1) return lc.handleLineChange(1)
} }
func (lv *ListView) handleLineChange(change int) error { func (lc *ListContext) handleLineChange(change int) error {
if !lv.Gui.isPopupPanel(lv.ViewName) && lv.Gui.popupPanelFocused() { if !lc.Gui.isPopupPanel(lc.ViewName) && lc.Gui.popupPanelFocused() {
return nil return nil
} }
view, err := lv.Gui.g.View(lv.ViewName) view, err := lc.Gui.g.View(lc.ViewName)
if err != nil { if err != nil {
return err return err
} }
lv.Gui.changeSelectedLine(lv.GetSelectedLineIdxPtr(), lv.GetItemsLength(), change) lc.Gui.changeSelectedLine(lc.GetSelectedLineIdxPtr(), lc.GetItemsLength(), change)
view.FocusPoint(0, *lv.GetSelectedLineIdxPtr()) view.FocusPoint(0, *lc.GetSelectedLineIdxPtr())
if lv.RendersToMainView { if lc.RendersToMainView {
if err := lv.Gui.resetOrigin(lv.Gui.getMainView()); err != nil { if err := lc.Gui.resetOrigin(lc.Gui.getMainView()); err != nil {
return err return err
} }
if err := lv.Gui.resetOrigin(lv.Gui.getSecondaryView()); err != nil { if err := lc.Gui.resetOrigin(lc.Gui.getSecondaryView()); err != nil {
return err return err
} }
} }
if lv.OnItemSelect != nil { if lc.OnItemSelect != nil {
return lv.OnItemSelect() return lc.OnItemSelect()
} }
return nil return nil
} }
func (lv *ListView) handleNextPage(g *gocui.Gui, v *gocui.View) error { func (lc *ListContext) handleNextPage(g *gocui.Gui, v *gocui.View) error {
view, err := lv.Gui.g.View(lv.ViewName) view, err := lc.Gui.g.View(lc.ViewName)
if err != nil { if err != nil {
return nil return nil
} }
@ -86,19 +86,19 @@ func (lv *ListView) handleNextPage(g *gocui.Gui, v *gocui.View) error {
if delta == 0 { if delta == 0 {
delta = 1 delta = 1
} }
return lv.handleLineChange(delta) return lc.handleLineChange(delta)
} }
func (lv *ListView) handleGotoTop(g *gocui.Gui, v *gocui.View) error { func (lc *ListContext) handleGotoTop(g *gocui.Gui, v *gocui.View) error {
return lv.handleLineChange(-lv.GetItemsLength()) return lc.handleLineChange(-lc.GetItemsLength())
} }
func (lv *ListView) handleGotoBottom(g *gocui.Gui, v *gocui.View) error { func (lc *ListContext) handleGotoBottom(g *gocui.Gui, v *gocui.View) error {
return lv.handleLineChange(lv.GetItemsLength()) return lc.handleLineChange(lc.GetItemsLength())
} }
func (lv *ListView) handlePrevPage(g *gocui.Gui, v *gocui.View) error { func (lc *ListContext) handlePrevPage(g *gocui.Gui, v *gocui.View) error {
view, err := lv.Gui.g.View(lv.ViewName) view, err := lc.Gui.g.View(lc.ViewName)
if err != nil { if err != nil {
return nil return nil
} }
@ -107,49 +107,49 @@ func (lv *ListView) handlePrevPage(g *gocui.Gui, v *gocui.View) error {
if delta == 0 { if delta == 0 {
delta = 1 delta = 1
} }
return lv.handleLineChange(-delta) return lc.handleLineChange(-delta)
} }
func (lv *ListView) handleClick(g *gocui.Gui, v *gocui.View) error { func (lc *ListContext) handleClick(g *gocui.Gui, v *gocui.View) error {
if !lv.Gui.isPopupPanel(lv.ViewName) && lv.Gui.popupPanelFocused() { if !lc.Gui.isPopupPanel(lc.ViewName) && lc.Gui.popupPanelFocused() {
return nil return nil
} }
selectedLineIdxPtr := lv.GetSelectedLineIdxPtr() selectedLineIdxPtr := lc.GetSelectedLineIdxPtr()
prevSelectedLineIdx := *selectedLineIdxPtr prevSelectedLineIdx := *selectedLineIdxPtr
newSelectedLineIdx := v.SelectedLineIdx() newSelectedLineIdx := v.SelectedLineIdx()
// we need to focus the view // we need to focus the view
if err := lv.Gui.switchContext(lv); err != nil { if err := lc.Gui.switchContext(lc); err != nil {
return err return err
} }
if newSelectedLineIdx > lv.GetItemsLength()-1 { if newSelectedLineIdx > lc.GetItemsLength()-1 {
return nil return nil
} }
*selectedLineIdxPtr = newSelectedLineIdx *selectedLineIdxPtr = newSelectedLineIdx
prevViewName := lv.Gui.currentViewName() prevViewName := lc.Gui.currentViewName()
if prevSelectedLineIdx == newSelectedLineIdx && prevViewName == lv.ViewName && lv.OnClickSelectedItem != nil { if prevSelectedLineIdx == newSelectedLineIdx && prevViewName == lc.ViewName && lc.OnClickSelectedItem != nil {
return lv.OnClickSelectedItem() return lc.OnClickSelectedItem()
} }
if lv.OnItemSelect != nil { if lc.OnItemSelect != nil {
return lv.OnItemSelect() return lc.OnItemSelect()
} }
return nil return nil
} }
func (lv *ListView) onSearchSelect(selectedLineIdx int) error { func (lc *ListContext) onSearchSelect(selectedLineIdx int) error {
*lv.GetSelectedLineIdxPtr() = selectedLineIdx *lc.GetSelectedLineIdxPtr() = selectedLineIdx
if lv.OnItemSelect != nil { if lc.OnItemSelect != nil {
return lv.OnItemSelect() return lc.OnItemSelect()
} }
return nil return nil
} }
func (gui *Gui) menuListView() *ListView { func (gui *Gui) menuListContext() *ListContext {
return &ListView{ return &ListContext{
ViewName: "menu", ViewName: "menu",
ContextKey: "menu", ContextKey: "menu",
GetItemsLength: func() int { return gui.getMenuView().LinesHeight() }, GetItemsLength: func() int { return gui.getMenuView().LinesHeight() },
@ -164,8 +164,8 @@ func (gui *Gui) menuListView() *ListView {
} }
} }
func (gui *Gui) filesListView() *ListView { func (gui *Gui) filesListContext() *ListContext {
return &ListView{ return &ListContext{
ViewName: "files", ViewName: "files",
ContextKey: "files", ContextKey: "files",
GetItemsLength: func() int { return len(gui.State.Files) }, GetItemsLength: func() int { return len(gui.State.Files) },
@ -179,8 +179,8 @@ func (gui *Gui) filesListView() *ListView {
} }
} }
func (gui *Gui) branchesListView() *ListView { func (gui *Gui) branchesListContext() *ListContext {
return &ListView{ return &ListContext{
ViewName: "branches", ViewName: "branches",
ContextKey: "local-branches", ContextKey: "local-branches",
GetItemsLength: func() int { return len(gui.State.Branches) }, GetItemsLength: func() int { return len(gui.State.Branches) },
@ -193,8 +193,8 @@ func (gui *Gui) branchesListView() *ListView {
} }
} }
func (gui *Gui) remotesListView() *ListView { func (gui *Gui) remotesListContext() *ListContext {
return &ListView{ return &ListContext{
ViewName: "branches", ViewName: "branches",
ContextKey: "remotes", ContextKey: "remotes",
GetItemsLength: func() int { return len(gui.State.Remotes) }, GetItemsLength: func() int { return len(gui.State.Remotes) },
@ -208,8 +208,8 @@ func (gui *Gui) remotesListView() *ListView {
} }
} }
func (gui *Gui) remoteBranchesListView() *ListView { func (gui *Gui) remoteBranchesListContext() *ListContext {
return &ListView{ return &ListContext{
ViewName: "branches", ViewName: "branches",
ContextKey: "remote-branches", ContextKey: "remote-branches",
GetItemsLength: func() int { return len(gui.State.RemoteBranches) }, GetItemsLength: func() int { return len(gui.State.RemoteBranches) },
@ -222,8 +222,8 @@ func (gui *Gui) remoteBranchesListView() *ListView {
} }
} }
func (gui *Gui) tagsListView() *ListView { func (gui *Gui) tagsListContext() *ListContext {
return &ListView{ return &ListContext{
ViewName: "branches", ViewName: "branches",
ContextKey: "tags", ContextKey: "tags",
GetItemsLength: func() int { return len(gui.State.Tags) }, GetItemsLength: func() int { return len(gui.State.Tags) },
@ -236,8 +236,8 @@ func (gui *Gui) tagsListView() *ListView {
} }
} }
func (gui *Gui) branchCommitsListView() *ListView { func (gui *Gui) branchCommitsListContext() *ListContext {
return &ListView{ return &ListContext{
ViewName: "commits", ViewName: "commits",
ContextKey: "branch-commits", ContextKey: "branch-commits",
GetItemsLength: func() int { return len(gui.State.Commits) }, GetItemsLength: func() int { return len(gui.State.Commits) },
@ -251,8 +251,8 @@ func (gui *Gui) branchCommitsListView() *ListView {
} }
} }
func (gui *Gui) reflogCommitsListView() *ListView { func (gui *Gui) reflogCommitsListContext() *ListContext {
return &ListView{ return &ListContext{
ViewName: "commits", ViewName: "commits",
ContextKey: "reflog-commits", ContextKey: "reflog-commits",
GetItemsLength: func() int { return len(gui.State.FilteredReflogCommits) }, GetItemsLength: func() int { return len(gui.State.FilteredReflogCommits) },
@ -265,8 +265,8 @@ func (gui *Gui) reflogCommitsListView() *ListView {
} }
} }
func (gui *Gui) stashListView() *ListView { func (gui *Gui) stashListContext() *ListContext {
return &ListView{ return &ListContext{
ViewName: "stash", ViewName: "stash",
ContextKey: "stash", ContextKey: "stash",
GetItemsLength: func() int { return len(gui.State.StashEntries) }, GetItemsLength: func() int { return len(gui.State.StashEntries) },
@ -279,8 +279,8 @@ func (gui *Gui) stashListView() *ListView {
} }
} }
func (gui *Gui) commitFilesListView() *ListView { func (gui *Gui) commitFilesListContext() *ListContext {
return &ListView{ return &ListContext{
ViewName: "commitFiles", ViewName: "commitFiles",
ContextKey: "commitFiles", ContextKey: "commitFiles",
GetItemsLength: func() int { return len(gui.State.CommitFiles) }, GetItemsLength: func() int { return len(gui.State.CommitFiles) },
@ -293,17 +293,17 @@ func (gui *Gui) commitFilesListView() *ListView {
} }
} }
func (gui *Gui) getListViews() []*ListView { func (gui *Gui) getListContexts() []*ListContext {
return []*ListView{ return []*ListContext{
gui.menuListView(), gui.menuListContext(),
gui.filesListView(), gui.filesListContext(),
gui.branchesListView(), gui.branchesListContext(),
gui.remotesListView(), gui.remotesListContext(),
gui.remoteBranchesListView(), gui.remoteBranchesListContext(),
gui.tagsListView(), gui.tagsListContext(),
gui.branchCommitsListView(), gui.branchCommitsListContext(),
gui.reflogCommitsListView(), gui.reflogCommitsListContext(),
gui.stashListView(), gui.stashListContext(),
gui.commitFilesListView(), gui.commitFilesListContext(),
} }
} }

View File

@ -94,8 +94,6 @@ func (gui *Gui) createMenu(title string, items []*menuItem, createMenuOptions cr
return err return err
} }
_, _ = gui.g.SetViewOnBottom("menu")
return gui.returnFromContext() return gui.returnFromContext()
} }

View File

@ -25,10 +25,6 @@ func (gui *Gui) handleReflogCommitSelect() error {
gui.State.SplitMainPanel = false gui.State.SplitMainPanel = false
if _, err := gui.g.SetCurrentView("commits"); err != nil {
return err
}
gui.getMainView().Title = "Reflog Entry" gui.getMainView().Title = "Reflog Entry"
commit := gui.getSelectedReflogCommit() commit := gui.getSelectedReflogCommit()

View File

@ -26,10 +26,6 @@ func (gui *Gui) handleRemoteBranchSelect() error {
gui.State.SplitMainPanel = false gui.State.SplitMainPanel = false
if _, err := gui.g.SetCurrentView("branches"); err != nil {
return err
}
gui.getMainView().Title = "Remote Branch" gui.getMainView().Title = "Remote Branch"
remoteBranch := gui.getSelectedRemoteBranch() remoteBranch := gui.getSelectedRemoteBranch()

View File

@ -29,10 +29,6 @@ func (gui *Gui) handleRemoteSelect() error {
gui.State.SplitMainPanel = false gui.State.SplitMainPanel = false
if _, err := gui.g.SetCurrentView("branches"); err != nil {
return err
}
gui.getMainView().Title = "Remote" gui.getMainView().Title = "Remote"
remote := gui.getSelectedRemote() remote := gui.getSelectedRemote()

View File

@ -24,16 +24,13 @@ func (gui *Gui) handleStashEntrySelect() error {
gui.State.SplitMainPanel = false gui.State.SplitMainPanel = false
if _, err := gui.g.SetCurrentView("stash"); err != nil {
return err
}
gui.getMainView().Title = "Stash" gui.getMainView().Title = "Stash"
stashEntry := gui.getSelectedStashEntry() stashEntry := gui.getSelectedStashEntry()
if stashEntry == nil { if stashEntry == nil {
return gui.newStringTask("main", gui.Tr.SLocalize("NoStashEntries")) return gui.newStringTask("main", gui.Tr.SLocalize("NoStashEntries"))
} }
if gui.inDiffMode() { if gui.inDiffMode() {
return gui.renderDiff() return gui.renderDiff()
} }

View File

@ -63,6 +63,10 @@ func (gui *Gui) handleCheckForUpdate(g *gocui.Gui, v *gocui.View) error {
func (gui *Gui) handleStatusClick(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleStatusClick(g *gocui.Gui, v *gocui.View) error {
currentBranch := gui.currentBranch() currentBranch := gui.currentBranch()
if err := gui.switchContext(gui.Contexts.Status.Context); err != nil {
return err
}
cx, _ := v.Cursor() cx, _ := v.Cursor()
upstreamStatus := fmt.Sprintf("↑%s↓%s", currentBranch.Pushables, currentBranch.Pullables) upstreamStatus := fmt.Sprintf("↑%s↓%s", currentBranch.Pushables, currentBranch.Pullables)
repoName := utils.GetCurrentRepoName() repoName := utils.GetCurrentRepoName()
@ -91,10 +95,6 @@ func (gui *Gui) handleStatusSelect() error {
gui.State.SplitMainPanel = false gui.State.SplitMainPanel = false
if _, err := gui.g.SetCurrentView("status"); err != nil {
return err
}
gui.getMainView().Title = "" gui.getMainView().Title = ""
if gui.inDiffMode() { if gui.inDiffMode() {

View File

@ -359,30 +359,6 @@ func (gui *Gui) popupPanelFocused() bool {
return gui.isPopupPanel(gui.currentViewName()) return gui.isPopupPanel(gui.currentViewName())
} }
func (gui *Gui) handleClick(v *gocui.View, itemCount int, selectedLine *int, handleSelect func(*gocui.Gui, *gocui.View) error) error {
if gui.popupPanelFocused() && v != nil && !gui.isPopupPanel(v.Name()) {
return nil
}
if _, err := gui.g.SetCurrentView(v.Name()); err != nil {
return err
}
newSelectedLine := v.SelectedLineIdx()
if newSelectedLine < 0 {
newSelectedLine = 0
}
if newSelectedLine > itemCount-1 {
newSelectedLine = itemCount - 1
}
*selectedLine = newSelectedLine
return handleSelect(gui.g, v)
}
// often gocui wants functions in the form `func(g *gocui.Gui, v *gocui.View) error` // often gocui wants functions in the form `func(g *gocui.Gui, v *gocui.View) error`
// but sometimes we just have a function that returns an error, so this is a // but sometimes we just have a function that returns an error, so this is a
// convenience wrapper to give gocui what it wants. // convenience wrapper to give gocui what it wants.
@ -396,3 +372,9 @@ func (gui *Gui) wrappedHandler(f func() error) func(g *gocui.Gui, v *gocui.View)
func (gui *Gui) secondaryViewFocused() bool { func (gui *Gui) secondaryViewFocused() bool {
return gui.State.Panels.LineByLine != nil && gui.State.Panels.LineByLine.SecondaryFocused return gui.State.Panels.LineByLine != nil && gui.State.Panels.LineByLine.SecondaryFocused
} }
func (gui *Gui) clearEditorView(v *gocui.View) {
v.Clear()
_ = v.SetCursor(0, 0)
_ = v.SetOrigin(0, 0)
}