mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-08-24 10:13:41 -05:00
Extract editConfig into a shared EditConfigAction
The "edit config file" command is about to gain a second, global keybinding alongside the existing status-panel one. Moving its body into an action struct (the convention GlobalController already follows for all its handlers) lets both controllers delegate to one implementation.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
type EditConfigAction struct {
|
||||
c *ControllerCommon
|
||||
}
|
||||
|
||||
func (self *EditConfigAction) Call() error {
|
||||
confPaths := self.c.GetConfig().GetUserConfigPaths()
|
||||
switch len(confPaths) {
|
||||
case 0:
|
||||
return errors.New(self.c.Tr.NoConfigFileFoundErr)
|
||||
case 1:
|
||||
return self.c.Helpers().Files.EditFiles(confPaths)
|
||||
default:
|
||||
menuItems := lo.Map(confPaths, func(path string, _ int) *types.MenuItem {
|
||||
return &types.MenuItem{
|
||||
Label: path,
|
||||
OnPress: func() error {
|
||||
return self.c.Helpers().Files.EditFiles([]string{path})
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
return self.c.Menu(types.CreateMenuOptions{
|
||||
Title: self.c.Tr.SelectConfigFile,
|
||||
Items: menuItems,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -12,7 +11,6 @@ import (
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/style"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
type StatusController struct {
|
||||
@@ -143,27 +141,7 @@ func lazygitTitle() string {
|
||||
}
|
||||
|
||||
func (self *StatusController) editConfig() error {
|
||||
confPaths := self.c.GetConfig().GetUserConfigPaths()
|
||||
switch len(confPaths) {
|
||||
case 0:
|
||||
return errors.New(self.c.Tr.NoConfigFileFoundErr)
|
||||
case 1:
|
||||
return self.c.Helpers().Files.EditFiles(confPaths)
|
||||
default:
|
||||
menuItems := lo.Map(confPaths, func(path string, _ int) *types.MenuItem {
|
||||
return &types.MenuItem{
|
||||
Label: path,
|
||||
OnPress: func() error {
|
||||
return self.c.Helpers().Files.EditFiles([]string{path})
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
return self.c.Menu(types.CreateMenuOptions{
|
||||
Title: self.c.Tr.SelectConfigFile,
|
||||
Items: menuItems,
|
||||
})
|
||||
}
|
||||
return (&EditConfigAction{c: self.c}).Call()
|
||||
}
|
||||
|
||||
func (self *StatusController) showAllBranchLogs() {
|
||||
|
||||
Reference in New Issue
Block a user