mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-02-09 13:47:11 +02:00
small things
WIP
This commit is contained in:
parent
ed4574bda9
commit
fd8a455aff
@ -168,9 +168,11 @@ func (gui *Gui) prepareConfirmationPanel(currentView *gocui.View, title, prompt
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) onNewPopupPanel() {
|
func (gui *Gui) onNewPopupPanel() {
|
||||||
viewNames := []string{"commitMessage",
|
viewNames := []string{
|
||||||
|
"commitMessage",
|
||||||
"credentials",
|
"credentials",
|
||||||
"menu"}
|
"menu",
|
||||||
|
}
|
||||||
for _, viewName := range viewNames {
|
for _, viewName := range viewNames {
|
||||||
_, _ = gui.g.SetViewOnBottom(viewName)
|
_, _ = gui.g.SetViewOnBottom(viewName)
|
||||||
}
|
}
|
||||||
|
@ -1,60 +1,9 @@
|
|||||||
package gui
|
package gui
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/golang-collections/collections/stack"
|
|
||||||
"github.com/jesseduffield/gocui"
|
"github.com/jesseduffield/gocui"
|
||||||
)
|
)
|
||||||
|
|
||||||
// changeContext is a helper function for when we want to change a 'main' context
|
|
||||||
// which currently just means a context that affects both the main and secondary views
|
|
||||||
// other views can have their context changed directly but this function helps
|
|
||||||
// keep the main and secondary views in sync
|
|
||||||
func (gui *Gui) changeMainViewsContext(context string) {
|
|
||||||
if gui.State.MainContext == context {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch context {
|
|
||||||
case "normal", "patch-building", "staging", "merging":
|
|
||||||
gui.getMainView().Context = context
|
|
||||||
gui.getSecondaryView().Context = context
|
|
||||||
}
|
|
||||||
|
|
||||||
gui.State.MainContext = context
|
|
||||||
}
|
|
||||||
|
|
||||||
type Stack struct {
|
|
||||||
stack []Context
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Stack) Push(contextKey Context) {
|
|
||||||
s.stack = append(s.stack, contextKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Stack) Pop() (Context, bool) {
|
|
||||||
if len(s.stack) == 0 {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
|
|
||||||
n := len(s.stack) - 1
|
|
||||||
value := s.stack[n]
|
|
||||||
s.stack = s.stack[:n]
|
|
||||||
|
|
||||||
return value, true
|
|
||||||
}
|
|
||||||
|
|
||||||
// the context manager maintains a stack of contexts so that we can easily switch focus back and forth
|
|
||||||
type contextManager struct {
|
|
||||||
gui *Gui
|
|
||||||
stack stack.Stack
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *contextManager) push(contextKey string) {
|
|
||||||
c.stack.Push(contextKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
// push focus, pop focus.
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SIDE_CONTEXT int = iota
|
SIDE_CONTEXT int = iota
|
||||||
MAIN_CONTEXT
|
MAIN_CONTEXT
|
||||||
@ -156,22 +105,43 @@ func (gui *Gui) switchContextToView(viewName string) error {
|
|||||||
return gui.switchContext(gui.State.ViewContextMap[viewName])
|
return gui.switchContext(gui.State.ViewContextMap[viewName])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) renderContextStack() string {
|
func (gui *Gui) returnFromContext() error {
|
||||||
result := ""
|
// TODO: add mutexes
|
||||||
for _, context := range gui.State.ContextStack {
|
|
||||||
result += context.GetViewName() + "\n"
|
if len(gui.State.ContextStack) == 1 {
|
||||||
|
// cannot escape from bottommost context
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return result
|
|
||||||
|
n := len(gui.State.ContextStack) - 1
|
||||||
|
|
||||||
|
currentContext := gui.State.ContextStack[n]
|
||||||
|
newContext := gui.State.ContextStack[n-1]
|
||||||
|
|
||||||
|
gui.State.ContextStack = gui.State.ContextStack[:n]
|
||||||
|
|
||||||
|
if err := currentContext.HandleFocusLost(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return gui.activateContext(newContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) activateContext(c Context) error {
|
func (gui *Gui) activateContext(c Context) error {
|
||||||
gui.Log.Warn(gui.renderContextStack())
|
gui.Log.Warn(gui.renderContextStack())
|
||||||
|
|
||||||
if _, err := gui.g.SetCurrentView(c.GetViewName()); err != nil {
|
viewName := c.GetViewName()
|
||||||
|
_, err := gui.g.View(viewName)
|
||||||
|
// if view no longer exists, pop again
|
||||||
|
if err != nil {
|
||||||
|
return gui.returnFromContext()
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := gui.g.SetCurrentView(viewName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := gui.g.SetViewOnTop(c.GetViewName()); err != nil {
|
if _, err := gui.g.SetViewOnTop(viewName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,26 +167,12 @@ func (gui *Gui) activateContext(c Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) returnFromContext() error {
|
func (gui *Gui) renderContextStack() string {
|
||||||
// TODO: add mutexes
|
result := ""
|
||||||
|
for _, context := range gui.State.ContextStack {
|
||||||
if len(gui.State.ContextStack) == 1 {
|
result += context.GetViewName() + "\n"
|
||||||
// cannot escape from bottommost context
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
return result
|
||||||
n := len(gui.State.ContextStack) - 1
|
|
||||||
|
|
||||||
currentContext := gui.State.ContextStack[n]
|
|
||||||
newContext := gui.State.ContextStack[n-1]
|
|
||||||
|
|
||||||
gui.State.ContextStack = gui.State.ContextStack[:n]
|
|
||||||
|
|
||||||
if err := currentContext.HandleFocusLost(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.activateContext(newContext)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) currentContext() Context {
|
func (gui *Gui) currentContext() Context {
|
||||||
@ -267,7 +223,8 @@ func (gui *Gui) createContextTree() {
|
|||||||
Context: BasicContext{
|
Context: BasicContext{
|
||||||
// TODO: think about different situations where this arises
|
// TODO: think about different situations where this arises
|
||||||
OnFocus: func() error {
|
OnFocus: func() error {
|
||||||
return gui.refreshStagingPanel(false, -1)
|
return nil
|
||||||
|
// return gui.refreshStagingPanel(false, -1)
|
||||||
},
|
},
|
||||||
Kind: MAIN_CONTEXT,
|
Kind: MAIN_CONTEXT,
|
||||||
ViewName: "main",
|
ViewName: "main",
|
||||||
@ -400,3 +357,21 @@ func (gui *Gui) onViewFocus(newView *gocui.View) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// changeContext is a helper function for when we want to change a 'main' context
|
||||||
|
// which currently just means a context that affects both the main and secondary views
|
||||||
|
// other views can have their context changed directly but this function helps
|
||||||
|
// keep the main and secondary views in sync
|
||||||
|
func (gui *Gui) changeMainViewsContext(context string) {
|
||||||
|
if gui.State.MainContext == context {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch context {
|
||||||
|
case "normal", "patch-building", "staging", "merging":
|
||||||
|
gui.getMainView().Context = context
|
||||||
|
gui.getSecondaryView().Context = context
|
||||||
|
}
|
||||||
|
|
||||||
|
gui.State.MainContext = context
|
||||||
|
}
|
||||||
|
@ -332,7 +332,7 @@ func (gui *Gui) handleEscapeLineByLinePanel() {
|
|||||||
func (gui *Gui) handleOpenFileAtLine() error {
|
func (gui *Gui) handleOpenFileAtLine() error {
|
||||||
// again, would be good to use inheritance here (or maybe even composition)
|
// again, would be good to use inheritance here (or maybe even composition)
|
||||||
var filename string
|
var filename string
|
||||||
switch gui.currentContext().GetKey() {
|
switch gui.State.MainContext {
|
||||||
case "patch-building":
|
case "patch-building":
|
||||||
filename = gui.getSelectedCommitFileName()
|
filename = gui.getSelectedCommitFileName()
|
||||||
case "staging":
|
case "staging":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user