mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-04 03:48:07 +02:00
lots more stuff
This commit is contained in:
parent
e87635295a
commit
ac0eedda91
@ -16,14 +16,6 @@ func (gui *Gui) getSelectedCommitFile() *commands.CommitFile {
|
||||
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 {
|
||||
if gui.popupPanelFocused() {
|
||||
return nil
|
||||
|
@ -43,16 +43,12 @@ func (gui *Gui) handleCommitConfirm(g *gocui.Gui, v *gocui.View) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
v.Clear()
|
||||
_, _ = g.SetViewOnBottom("commitMessage") // TODO: bring into context code
|
||||
_ = v.SetCursor(0, 0)
|
||||
_ = v.SetOrigin(0, 0)
|
||||
gui.clearEditorView(v)
|
||||
_ = gui.returnFromContext()
|
||||
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
||||
}
|
||||
|
||||
func (gui *Gui) handleCommitClose(g *gocui.Gui, v *gocui.View) error {
|
||||
_, _ = g.SetViewOnBottom("commitMessage") // TODO: bring into context code
|
||||
return gui.returnFromContext()
|
||||
}
|
||||
|
||||
|
@ -31,10 +31,6 @@ func (gui *Gui) handleCommitSelect() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := gui.g.SetCurrentView("commits"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
state := gui.State.Panels.Commits
|
||||
if state.SelectedLine > 290 && state.LimitCommits {
|
||||
state.LimitCommits = false
|
||||
@ -739,9 +735,9 @@ func (gui *Gui) handleGotoBottomForCommitsPanel(g *gocui.Gui, v *gocui.View) err
|
||||
}
|
||||
}
|
||||
|
||||
for _, view := range gui.getListViews() {
|
||||
if view.ViewName == "commits" {
|
||||
return view.handleGotoBottom(g, v)
|
||||
for _, context := range gui.getListContexts() {
|
||||
if context.ViewName == "commits" {
|
||||
return context.handleGotoBottom(g, v)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -174,7 +174,7 @@ func (gui *Gui) onNewPopupPanel() {
|
||||
"menu",
|
||||
}
|
||||
for _, viewName := range viewNames {
|
||||
_, _ = gui.g.SetViewOnBottom(viewName)
|
||||
_, _ = gui.g.SetViewOnBottom(viewName) // TODO: investigate
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -76,6 +76,7 @@ type ContextTree struct {
|
||||
BranchCommits CommitsContextNode
|
||||
ReflogCommits SimpleContextNode
|
||||
Stash SimpleContextNode
|
||||
Normal SimpleContextNode
|
||||
Staging SimpleContextNode
|
||||
PatchBuilding SimpleContextNode
|
||||
Merging SimpleContextNode
|
||||
@ -120,13 +121,26 @@ func (gui *Gui) returnFromContext() error {
|
||||
|
||||
gui.State.ContextStack = gui.State.ContextStack[:n]
|
||||
|
||||
if err := currentContext.HandleFocusLost(); err != nil {
|
||||
if err := gui.deactivateContext(currentContext); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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 {
|
||||
gui.Log.Warn(gui.renderContextStack())
|
||||
|
||||
@ -188,34 +202,44 @@ func (gui *Gui) createContextTree() {
|
||||
},
|
||||
},
|
||||
Files: SimpleContextNode{
|
||||
Context: gui.filesListView(),
|
||||
Context: gui.filesListContext(),
|
||||
},
|
||||
Menu: SimpleContextNode{
|
||||
Context: gui.menuListView(),
|
||||
Context: gui.menuListContext(),
|
||||
},
|
||||
Remotes: RemotesContextNode{
|
||||
Context: gui.remotesListView(),
|
||||
Context: gui.remotesListContext(),
|
||||
Branches: SimpleContextNode{
|
||||
Context: gui.remoteBranchesListView(),
|
||||
Context: gui.remoteBranchesListContext(),
|
||||
},
|
||||
},
|
||||
BranchCommits: CommitsContextNode{
|
||||
Context: gui.branchCommitsListView(),
|
||||
Context: gui.branchCommitsListContext(),
|
||||
Files: SimpleContextNode{
|
||||
Context: gui.commitFilesListView(),
|
||||
Context: gui.commitFilesListContext(),
|
||||
},
|
||||
},
|
||||
ReflogCommits: SimpleContextNode{
|
||||
Context: gui.reflogCommitsListView(),
|
||||
Context: gui.reflogCommitsListContext(),
|
||||
},
|
||||
Branches: SimpleContextNode{
|
||||
Context: gui.branchesListView(),
|
||||
Context: gui.branchesListContext(),
|
||||
},
|
||||
Tags: SimpleContextNode{
|
||||
Context: gui.tagsListView(),
|
||||
Context: gui.tagsListContext(),
|
||||
},
|
||||
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{
|
||||
Context: BasicContext{
|
||||
@ -295,7 +319,18 @@ func (gui *Gui) createContextTree() {
|
||||
"confirmation": gui.Contexts.Confirmation.Context,
|
||||
"credentials": gui.Contexts.Credentials.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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,9 +37,7 @@ func (gui *Gui) promptUserForCredential(passOrUname string) string {
|
||||
func (gui *Gui) handleSubmitCredential(g *gocui.Gui, v *gocui.View) error {
|
||||
message := gui.trimmedContent(v)
|
||||
gui.credentials <- message
|
||||
v.Clear()
|
||||
_ = v.SetCursor(0, 0)
|
||||
_, _ = g.SetViewOnBottom("credentials") // TODO: move to context code
|
||||
gui.clearEditorView(v)
|
||||
if err := gui.returnFromContext(); err != nil {
|
||||
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 {
|
||||
_, _ = g.SetViewOnBottom("credentials")
|
||||
|
||||
gui.credentials <- ""
|
||||
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
|
||||
func (gui *Gui) handleCredentialsPopup(cmdErr error) {
|
||||
_, _ = gui.g.SetViewOnBottom("credentials")
|
||||
if cmdErr != nil {
|
||||
errMessage := cmdErr.Error()
|
||||
if strings.Contains(errMessage, "Invalid username or password") {
|
||||
|
@ -210,10 +210,6 @@ func (gui *Gui) allFilesStaged() bool {
|
||||
}
|
||||
|
||||
func (gui *Gui) focusAndSelectFile() error {
|
||||
if _, err := gui.g.SetCurrentView("files"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return gui.selectFile(false)
|
||||
}
|
||||
|
||||
|
@ -1347,12 +1347,6 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: gui.handleStatusClick,
|
||||
},
|
||||
{
|
||||
ViewName: "commitFiles",
|
||||
Key: gocui.MouseLeft,
|
||||
Modifier: gocui.ModNone,
|
||||
Handler: gui.handleCommitFilesClick,
|
||||
},
|
||||
{
|
||||
ViewName: "search",
|
||||
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)})
|
||||
}
|
||||
|
||||
for _, listView := range gui.getListViews() {
|
||||
for _, listContext := range gui.getListContexts() {
|
||||
bindings = append(bindings, []*Binding{
|
||||
{ViewName: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gui.getKey("universal.prevItem-alt"), Modifier: gocui.ModNone, Handler: listView.handlePrevLine},
|
||||
{ViewName: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gui.getKey("universal.prevItem"), Modifier: gocui.ModNone, Handler: listView.handlePrevLine},
|
||||
{ViewName: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gocui.MouseWheelUp, Modifier: gocui.ModNone, Handler: listView.handlePrevLine},
|
||||
{ViewName: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gui.getKey("universal.nextItem-alt"), Modifier: gocui.ModNone, Handler: listView.handleNextLine},
|
||||
{ViewName: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gui.getKey("universal.nextItem"), Modifier: gocui.ModNone, Handler: listView.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: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gui.getKey("universal.nextPage"), Modifier: gocui.ModNone, Handler: listView.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: listView.ViewName, Contexts: []string{listView.ContextKey}, Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: listView.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: gui.getKey("universal.prevItem-alt"), Modifier: gocui.ModNone, Handler: listContext.handlePrevLine},
|
||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.prevItem"), Modifier: gocui.ModNone, Handler: listContext.handlePrevLine},
|
||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gocui.MouseWheelUp, Modifier: gocui.ModNone, Handler: listContext.handlePrevLine},
|
||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.nextItem-alt"), Modifier: gocui.ModNone, Handler: listContext.handleNextLine},
|
||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.nextItem"), Modifier: gocui.ModNone, Handler: listContext.handleNextLine},
|
||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.prevPage"), Modifier: gocui.ModNone, Handler: listContext.handlePrevPage, Description: gui.Tr.SLocalize("prevPage")},
|
||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.nextPage"), Modifier: gocui.ModNone, Handler: listContext.handleNextPage, Description: gui.Tr.SLocalize("nextPage")},
|
||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gui.getKey("universal.gotoTop"), Modifier: gocui.ModNone, Handler: listContext.handleGotoTop, Description: gui.Tr.SLocalize("gotoTop")},
|
||||
{ViewName: listContext.ViewName, Contexts: []string{listContext.ContextKey}, Key: gocui.MouseWheelDown, Modifier: gocui.ModNone, Handler: listContext.handleNextLine},
|
||||
{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
|
||||
openSearchHandler := gui.handleOpenSearch
|
||||
gotoBottomHandler := listView.handleGotoBottom
|
||||
if listView.ViewName == "commits" {
|
||||
gotoBottomHandler := listContext.handleGotoBottom
|
||||
if listContext.ViewName == "commits" {
|
||||
openSearchHandler = gui.handleOpenSearchForCommitsPanel
|
||||
gotoBottomHandler = gui.handleGotoBottomForCommitsPanel
|
||||
}
|
||||
|
||||
bindings = append(bindings, []*Binding{
|
||||
{
|
||||
ViewName: listView.ViewName,
|
||||
Contexts: []string{listView.ContextKey},
|
||||
ViewName: listContext.ViewName,
|
||||
Contexts: []string{listContext.ContextKey},
|
||||
Key: gui.getKey("universal.startSearch"),
|
||||
Handler: openSearchHandler,
|
||||
Description: gui.Tr.SLocalize("startSearch"),
|
||||
},
|
||||
{
|
||||
ViewName: listView.ViewName,
|
||||
Contexts: []string{listView.ContextKey},
|
||||
ViewName: listContext.ViewName,
|
||||
Contexts: []string{listContext.ContextKey},
|
||||
Key: gui.getKey("universal.gotoBottom"),
|
||||
Handler: gotoBottomHandler,
|
||||
Description: gui.Tr.SLocalize("gotoBottom"),
|
||||
|
@ -282,42 +282,42 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
||||
}
|
||||
}
|
||||
|
||||
type listViewState struct {
|
||||
type listContextState struct {
|
||||
selectedLine int
|
||||
lineCount int
|
||||
view *gocui.View
|
||||
context string
|
||||
listView *ListView
|
||||
contextKey string
|
||||
listContext *ListContext
|
||||
}
|
||||
|
||||
listViewStates := []listViewState{
|
||||
{view: filesView, context: "files", selectedLine: gui.State.Panels.Files.SelectedLine, lineCount: len(gui.State.Files), listView: gui.filesListView()},
|
||||
{view: branchesView, context: "local-branches", selectedLine: gui.State.Panels.Branches.SelectedLine, lineCount: len(gui.State.Branches), listView: gui.branchesListView()},
|
||||
{view: branchesView, context: "remotes", selectedLine: gui.State.Panels.Remotes.SelectedLine, lineCount: len(gui.State.Remotes), listView: gui.remotesListView()},
|
||||
{view: branchesView, context: "remote-branches", selectedLine: gui.State.Panels.RemoteBranches.SelectedLine, lineCount: len(gui.State.Remotes), listView: gui.remoteBranchesListView()},
|
||||
{view: branchesView, context: "tags", selectedLine: gui.State.Panels.Tags.SelectedLine, lineCount: len(gui.State.Tags), listView: gui.tagsListView()},
|
||||
{view: commitsView, context: "branch-commits", selectedLine: gui.State.Panels.Commits.SelectedLine, lineCount: len(gui.State.Commits), listView: gui.branchCommitsListView()},
|
||||
{view: commitsView, context: "reflog-commits", selectedLine: gui.State.Panels.ReflogCommits.SelectedLine, lineCount: len(gui.State.FilteredReflogCommits), listView: gui.reflogCommitsListView()},
|
||||
{view: stashView, context: "stash", selectedLine: gui.State.Panels.Stash.SelectedLine, lineCount: len(gui.State.StashEntries), listView: gui.stashListView()},
|
||||
{view: commitFilesView, context: "commit-files", selectedLine: gui.State.Panels.CommitFiles.SelectedLine, lineCount: len(gui.State.CommitFiles), listView: gui.commitFilesListView()},
|
||||
listContextStates := []listContextState{
|
||||
{view: filesView, contextKey: "files", selectedLine: gui.State.Panels.Files.SelectedLine, lineCount: len(gui.State.Files), listContext: gui.filesListContext()},
|
||||
{view: branchesView, contextKey: "local-branches", selectedLine: gui.State.Panels.Branches.SelectedLine, lineCount: len(gui.State.Branches), listContext: gui.branchesListContext()},
|
||||
{view: branchesView, contextKey: "remotes", selectedLine: gui.State.Panels.Remotes.SelectedLine, lineCount: len(gui.State.Remotes), listContext: gui.remotesListContext()},
|
||||
{view: branchesView, contextKey: "remote-branches", selectedLine: gui.State.Panels.RemoteBranches.SelectedLine, lineCount: len(gui.State.Remotes), listContext: gui.remoteBranchesListContext()},
|
||||
{view: branchesView, contextKey: "tags", selectedLine: gui.State.Panels.Tags.SelectedLine, lineCount: len(gui.State.Tags), listContext: gui.tagsListContext()},
|
||||
{view: commitsView, contextKey: "branch-commits", selectedLine: gui.State.Panels.Commits.SelectedLine, lineCount: len(gui.State.Commits), listContext: gui.branchCommitsListContext()},
|
||||
{view: commitsView, contextKey: "reflog-commits", selectedLine: gui.State.Panels.ReflogCommits.SelectedLine, lineCount: len(gui.State.FilteredReflogCommits), listContext: gui.reflogCommitsListContext()},
|
||||
{view: stashView, contextKey: "stash", selectedLine: gui.State.Panels.Stash.SelectedLine, lineCount: len(gui.State.StashEntries), listContext: gui.stashListContext()},
|
||||
{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
|
||||
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 {
|
||||
// ignore views where the context doesn't match up with the selected line we're trying to focus
|
||||
if listViewState.context != "" && (listViewState.view.Context != listViewState.context) {
|
||||
for _, listContextState := range listContextStates {
|
||||
// ignore contexts whose view is owned by another context right now
|
||||
if listContextState.view.Context != listContextState.contextKey {
|
||||
continue
|
||||
}
|
||||
// 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
|
||||
listViewState.view.SetOnSelectItem(gui.onSelectItemWrapper(listViewState.listView.onSearchSelect))
|
||||
listContextState.view.SetOnSelectItem(gui.onSelectItemWrapper(listContextState.listContext.onSearchSelect))
|
||||
}
|
||||
|
||||
mainViewWidth, mainViewHeight := gui.getMainView().Size()
|
||||
@ -339,13 +339,12 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
||||
func (gui *Gui) onInitialViewsCreation() error {
|
||||
gui.createContextTree()
|
||||
|
||||
gui.switchContext(gui.Contexts.Files.Context)
|
||||
if err := gui.switchContext(gui.Contexts.Files.Context); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gui.changeMainViewsContext("normal")
|
||||
|
||||
gui.getBranchesView().Context = "local-branches"
|
||||
gui.getCommitsView().Context = "branch-commits"
|
||||
|
||||
if gui.showRecentRepos {
|
||||
if err := gui.handleCreateRecentReposMenu(); err != nil {
|
||||
return err
|
||||
|
@ -2,7 +2,7 @@ package gui
|
||||
|
||||
import "github.com/jesseduffield/gocui"
|
||||
|
||||
type ListView struct {
|
||||
type ListContext struct {
|
||||
ViewName string
|
||||
ContextKey string
|
||||
GetItemsLength func() int
|
||||
@ -16,68 +16,68 @@ type ListView struct {
|
||||
Kind int
|
||||
}
|
||||
|
||||
func (lv *ListView) GetKey() string {
|
||||
return lv.ContextKey
|
||||
func (lc *ListContext) GetKey() string {
|
||||
return lc.ContextKey
|
||||
}
|
||||
|
||||
func (lv *ListView) GetKind() int {
|
||||
return lv.Kind
|
||||
func (lc *ListContext) GetKind() int {
|
||||
return lc.Kind
|
||||
}
|
||||
|
||||
func (lv *ListView) GetViewName() string {
|
||||
return lv.ViewName
|
||||
func (lc *ListContext) GetViewName() string {
|
||||
return lc.ViewName
|
||||
}
|
||||
|
||||
func (lv *ListView) HandleFocusLost() error {
|
||||
if lv.OnFocusLost != nil {
|
||||
return lv.OnFocusLost()
|
||||
func (lc *ListContext) HandleFocusLost() error {
|
||||
if lc.OnFocusLost != nil {
|
||||
return lc.OnFocusLost()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lv *ListView) HandleFocus() error {
|
||||
return lv.OnFocus()
|
||||
func (lc *ListContext) HandleFocus() error {
|
||||
return lc.OnFocus()
|
||||
}
|
||||
|
||||
func (lv *ListView) handlePrevLine(g *gocui.Gui, v *gocui.View) error {
|
||||
return lv.handleLineChange(-1)
|
||||
func (lc *ListContext) handlePrevLine(g *gocui.Gui, v *gocui.View) error {
|
||||
return lc.handleLineChange(-1)
|
||||
}
|
||||
|
||||
func (lv *ListView) handleNextLine(g *gocui.Gui, v *gocui.View) error {
|
||||
return lv.handleLineChange(1)
|
||||
func (lc *ListContext) handleNextLine(g *gocui.Gui, v *gocui.View) error {
|
||||
return lc.handleLineChange(1)
|
||||
}
|
||||
|
||||
func (lv *ListView) handleLineChange(change int) error {
|
||||
if !lv.Gui.isPopupPanel(lv.ViewName) && lv.Gui.popupPanelFocused() {
|
||||
func (lc *ListContext) handleLineChange(change int) error {
|
||||
if !lc.Gui.isPopupPanel(lc.ViewName) && lc.Gui.popupPanelFocused() {
|
||||
return nil
|
||||
}
|
||||
|
||||
view, err := lv.Gui.g.View(lv.ViewName)
|
||||
view, err := lc.Gui.g.View(lc.ViewName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lv.Gui.changeSelectedLine(lv.GetSelectedLineIdxPtr(), lv.GetItemsLength(), change)
|
||||
view.FocusPoint(0, *lv.GetSelectedLineIdxPtr())
|
||||
lc.Gui.changeSelectedLine(lc.GetSelectedLineIdxPtr(), lc.GetItemsLength(), change)
|
||||
view.FocusPoint(0, *lc.GetSelectedLineIdxPtr())
|
||||
|
||||
if lv.RendersToMainView {
|
||||
if err := lv.Gui.resetOrigin(lv.Gui.getMainView()); err != nil {
|
||||
if lc.RendersToMainView {
|
||||
if err := lc.Gui.resetOrigin(lc.Gui.getMainView()); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := lv.Gui.resetOrigin(lv.Gui.getSecondaryView()); err != nil {
|
||||
if err := lc.Gui.resetOrigin(lc.Gui.getSecondaryView()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if lv.OnItemSelect != nil {
|
||||
return lv.OnItemSelect()
|
||||
if lc.OnItemSelect != nil {
|
||||
return lc.OnItemSelect()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lv *ListView) handleNextPage(g *gocui.Gui, v *gocui.View) error {
|
||||
view, err := lv.Gui.g.View(lv.ViewName)
|
||||
func (lc *ListContext) handleNextPage(g *gocui.Gui, v *gocui.View) error {
|
||||
view, err := lc.Gui.g.View(lc.ViewName)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@ -86,19 +86,19 @@ func (lv *ListView) handleNextPage(g *gocui.Gui, v *gocui.View) error {
|
||||
if delta == 0 {
|
||||
delta = 1
|
||||
}
|
||||
return lv.handleLineChange(delta)
|
||||
return lc.handleLineChange(delta)
|
||||
}
|
||||
|
||||
func (lv *ListView) handleGotoTop(g *gocui.Gui, v *gocui.View) error {
|
||||
return lv.handleLineChange(-lv.GetItemsLength())
|
||||
func (lc *ListContext) handleGotoTop(g *gocui.Gui, v *gocui.View) error {
|
||||
return lc.handleLineChange(-lc.GetItemsLength())
|
||||
}
|
||||
|
||||
func (lv *ListView) handleGotoBottom(g *gocui.Gui, v *gocui.View) error {
|
||||
return lv.handleLineChange(lv.GetItemsLength())
|
||||
func (lc *ListContext) handleGotoBottom(g *gocui.Gui, v *gocui.View) error {
|
||||
return lc.handleLineChange(lc.GetItemsLength())
|
||||
}
|
||||
|
||||
func (lv *ListView) handlePrevPage(g *gocui.Gui, v *gocui.View) error {
|
||||
view, err := lv.Gui.g.View(lv.ViewName)
|
||||
func (lc *ListContext) handlePrevPage(g *gocui.Gui, v *gocui.View) error {
|
||||
view, err := lc.Gui.g.View(lc.ViewName)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@ -107,49 +107,49 @@ func (lv *ListView) handlePrevPage(g *gocui.Gui, v *gocui.View) error {
|
||||
if delta == 0 {
|
||||
delta = 1
|
||||
}
|
||||
return lv.handleLineChange(-delta)
|
||||
return lc.handleLineChange(-delta)
|
||||
}
|
||||
|
||||
func (lv *ListView) handleClick(g *gocui.Gui, v *gocui.View) error {
|
||||
if !lv.Gui.isPopupPanel(lv.ViewName) && lv.Gui.popupPanelFocused() {
|
||||
func (lc *ListContext) handleClick(g *gocui.Gui, v *gocui.View) error {
|
||||
if !lc.Gui.isPopupPanel(lc.ViewName) && lc.Gui.popupPanelFocused() {
|
||||
return nil
|
||||
}
|
||||
|
||||
selectedLineIdxPtr := lv.GetSelectedLineIdxPtr()
|
||||
selectedLineIdxPtr := lc.GetSelectedLineIdxPtr()
|
||||
prevSelectedLineIdx := *selectedLineIdxPtr
|
||||
newSelectedLineIdx := v.SelectedLineIdx()
|
||||
|
||||
// we need to focus the view
|
||||
if err := lv.Gui.switchContext(lv); err != nil {
|
||||
if err := lc.Gui.switchContext(lc); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if newSelectedLineIdx > lv.GetItemsLength()-1 {
|
||||
if newSelectedLineIdx > lc.GetItemsLength()-1 {
|
||||
return nil
|
||||
}
|
||||
|
||||
*selectedLineIdxPtr = newSelectedLineIdx
|
||||
|
||||
prevViewName := lv.Gui.currentViewName()
|
||||
if prevSelectedLineIdx == newSelectedLineIdx && prevViewName == lv.ViewName && lv.OnClickSelectedItem != nil {
|
||||
return lv.OnClickSelectedItem()
|
||||
prevViewName := lc.Gui.currentViewName()
|
||||
if prevSelectedLineIdx == newSelectedLineIdx && prevViewName == lc.ViewName && lc.OnClickSelectedItem != nil {
|
||||
return lc.OnClickSelectedItem()
|
||||
}
|
||||
if lv.OnItemSelect != nil {
|
||||
return lv.OnItemSelect()
|
||||
if lc.OnItemSelect != nil {
|
||||
return lc.OnItemSelect()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (lv *ListView) onSearchSelect(selectedLineIdx int) error {
|
||||
*lv.GetSelectedLineIdxPtr() = selectedLineIdx
|
||||
if lv.OnItemSelect != nil {
|
||||
return lv.OnItemSelect()
|
||||
func (lc *ListContext) onSearchSelect(selectedLineIdx int) error {
|
||||
*lc.GetSelectedLineIdxPtr() = selectedLineIdx
|
||||
if lc.OnItemSelect != nil {
|
||||
return lc.OnItemSelect()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gui *Gui) menuListView() *ListView {
|
||||
return &ListView{
|
||||
func (gui *Gui) menuListContext() *ListContext {
|
||||
return &ListContext{
|
||||
ViewName: "menu",
|
||||
ContextKey: "menu",
|
||||
GetItemsLength: func() int { return gui.getMenuView().LinesHeight() },
|
||||
@ -164,8 +164,8 @@ func (gui *Gui) menuListView() *ListView {
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) filesListView() *ListView {
|
||||
return &ListView{
|
||||
func (gui *Gui) filesListContext() *ListContext {
|
||||
return &ListContext{
|
||||
ViewName: "files",
|
||||
ContextKey: "files",
|
||||
GetItemsLength: func() int { return len(gui.State.Files) },
|
||||
@ -179,8 +179,8 @@ func (gui *Gui) filesListView() *ListView {
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) branchesListView() *ListView {
|
||||
return &ListView{
|
||||
func (gui *Gui) branchesListContext() *ListContext {
|
||||
return &ListContext{
|
||||
ViewName: "branches",
|
||||
ContextKey: "local-branches",
|
||||
GetItemsLength: func() int { return len(gui.State.Branches) },
|
||||
@ -193,8 +193,8 @@ func (gui *Gui) branchesListView() *ListView {
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) remotesListView() *ListView {
|
||||
return &ListView{
|
||||
func (gui *Gui) remotesListContext() *ListContext {
|
||||
return &ListContext{
|
||||
ViewName: "branches",
|
||||
ContextKey: "remotes",
|
||||
GetItemsLength: func() int { return len(gui.State.Remotes) },
|
||||
@ -208,8 +208,8 @@ func (gui *Gui) remotesListView() *ListView {
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) remoteBranchesListView() *ListView {
|
||||
return &ListView{
|
||||
func (gui *Gui) remoteBranchesListContext() *ListContext {
|
||||
return &ListContext{
|
||||
ViewName: "branches",
|
||||
ContextKey: "remote-branches",
|
||||
GetItemsLength: func() int { return len(gui.State.RemoteBranches) },
|
||||
@ -222,8 +222,8 @@ func (gui *Gui) remoteBranchesListView() *ListView {
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) tagsListView() *ListView {
|
||||
return &ListView{
|
||||
func (gui *Gui) tagsListContext() *ListContext {
|
||||
return &ListContext{
|
||||
ViewName: "branches",
|
||||
ContextKey: "tags",
|
||||
GetItemsLength: func() int { return len(gui.State.Tags) },
|
||||
@ -236,8 +236,8 @@ func (gui *Gui) tagsListView() *ListView {
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) branchCommitsListView() *ListView {
|
||||
return &ListView{
|
||||
func (gui *Gui) branchCommitsListContext() *ListContext {
|
||||
return &ListContext{
|
||||
ViewName: "commits",
|
||||
ContextKey: "branch-commits",
|
||||
GetItemsLength: func() int { return len(gui.State.Commits) },
|
||||
@ -251,8 +251,8 @@ func (gui *Gui) branchCommitsListView() *ListView {
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) reflogCommitsListView() *ListView {
|
||||
return &ListView{
|
||||
func (gui *Gui) reflogCommitsListContext() *ListContext {
|
||||
return &ListContext{
|
||||
ViewName: "commits",
|
||||
ContextKey: "reflog-commits",
|
||||
GetItemsLength: func() int { return len(gui.State.FilteredReflogCommits) },
|
||||
@ -265,8 +265,8 @@ func (gui *Gui) reflogCommitsListView() *ListView {
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) stashListView() *ListView {
|
||||
return &ListView{
|
||||
func (gui *Gui) stashListContext() *ListContext {
|
||||
return &ListContext{
|
||||
ViewName: "stash",
|
||||
ContextKey: "stash",
|
||||
GetItemsLength: func() int { return len(gui.State.StashEntries) },
|
||||
@ -279,8 +279,8 @@ func (gui *Gui) stashListView() *ListView {
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) commitFilesListView() *ListView {
|
||||
return &ListView{
|
||||
func (gui *Gui) commitFilesListContext() *ListContext {
|
||||
return &ListContext{
|
||||
ViewName: "commitFiles",
|
||||
ContextKey: "commitFiles",
|
||||
GetItemsLength: func() int { return len(gui.State.CommitFiles) },
|
||||
@ -293,17 +293,17 @@ func (gui *Gui) commitFilesListView() *ListView {
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) getListViews() []*ListView {
|
||||
return []*ListView{
|
||||
gui.menuListView(),
|
||||
gui.filesListView(),
|
||||
gui.branchesListView(),
|
||||
gui.remotesListView(),
|
||||
gui.remoteBranchesListView(),
|
||||
gui.tagsListView(),
|
||||
gui.branchCommitsListView(),
|
||||
gui.reflogCommitsListView(),
|
||||
gui.stashListView(),
|
||||
gui.commitFilesListView(),
|
||||
func (gui *Gui) getListContexts() []*ListContext {
|
||||
return []*ListContext{
|
||||
gui.menuListContext(),
|
||||
gui.filesListContext(),
|
||||
gui.branchesListContext(),
|
||||
gui.remotesListContext(),
|
||||
gui.remoteBranchesListContext(),
|
||||
gui.tagsListContext(),
|
||||
gui.branchCommitsListContext(),
|
||||
gui.reflogCommitsListContext(),
|
||||
gui.stashListContext(),
|
||||
gui.commitFilesListContext(),
|
||||
}
|
||||
}
|
||||
|
@ -94,8 +94,6 @@ func (gui *Gui) createMenu(title string, items []*menuItem, createMenuOptions cr
|
||||
return err
|
||||
}
|
||||
|
||||
_, _ = gui.g.SetViewOnBottom("menu")
|
||||
|
||||
return gui.returnFromContext()
|
||||
}
|
||||
|
||||
|
@ -25,10 +25,6 @@ func (gui *Gui) handleReflogCommitSelect() error {
|
||||
|
||||
gui.State.SplitMainPanel = false
|
||||
|
||||
if _, err := gui.g.SetCurrentView("commits"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gui.getMainView().Title = "Reflog Entry"
|
||||
|
||||
commit := gui.getSelectedReflogCommit()
|
||||
|
@ -26,10 +26,6 @@ func (gui *Gui) handleRemoteBranchSelect() error {
|
||||
|
||||
gui.State.SplitMainPanel = false
|
||||
|
||||
if _, err := gui.g.SetCurrentView("branches"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gui.getMainView().Title = "Remote Branch"
|
||||
|
||||
remoteBranch := gui.getSelectedRemoteBranch()
|
||||
|
@ -29,10 +29,6 @@ func (gui *Gui) handleRemoteSelect() error {
|
||||
|
||||
gui.State.SplitMainPanel = false
|
||||
|
||||
if _, err := gui.g.SetCurrentView("branches"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gui.getMainView().Title = "Remote"
|
||||
|
||||
remote := gui.getSelectedRemote()
|
||||
|
@ -24,16 +24,13 @@ func (gui *Gui) handleStashEntrySelect() error {
|
||||
|
||||
gui.State.SplitMainPanel = false
|
||||
|
||||
if _, err := gui.g.SetCurrentView("stash"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gui.getMainView().Title = "Stash"
|
||||
|
||||
stashEntry := gui.getSelectedStashEntry()
|
||||
if stashEntry == nil {
|
||||
return gui.newStringTask("main", gui.Tr.SLocalize("NoStashEntries"))
|
||||
}
|
||||
|
||||
if gui.inDiffMode() {
|
||||
return gui.renderDiff()
|
||||
}
|
||||
|
@ -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 {
|
||||
currentBranch := gui.currentBranch()
|
||||
|
||||
if err := gui.switchContext(gui.Contexts.Status.Context); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cx, _ := v.Cursor()
|
||||
upstreamStatus := fmt.Sprintf("↑%s↓%s", currentBranch.Pushables, currentBranch.Pullables)
|
||||
repoName := utils.GetCurrentRepoName()
|
||||
@ -91,10 +95,6 @@ func (gui *Gui) handleStatusSelect() error {
|
||||
|
||||
gui.State.SplitMainPanel = false
|
||||
|
||||
if _, err := gui.g.SetCurrentView("status"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gui.getMainView().Title = ""
|
||||
|
||||
if gui.inDiffMode() {
|
||||
|
@ -359,30 +359,6 @@ func (gui *Gui) popupPanelFocused() bool {
|
||||
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`
|
||||
// but sometimes we just have a function that returns an error, so this is a
|
||||
// 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 {
|
||||
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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user