2022-01-16 05:46:53 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/controllers"
|
2022-01-29 10:09:20 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
2022-01-16 05:46:53 +02:00
|
|
|
)
|
|
|
|
|
2022-01-30 01:23:39 +02:00
|
|
|
type FilesHelper struct {
|
2022-01-29 10:09:20 +02:00
|
|
|
c *types.ControllerCommon
|
2022-01-16 05:46:53 +02:00
|
|
|
git *commands.GitCommand
|
|
|
|
os *oscommands.OSCommand
|
|
|
|
}
|
|
|
|
|
2022-01-30 01:23:39 +02:00
|
|
|
func NewFilesHelper(
|
2022-01-29 10:09:20 +02:00
|
|
|
c *types.ControllerCommon,
|
2022-01-16 05:46:53 +02:00
|
|
|
git *commands.GitCommand,
|
|
|
|
os *oscommands.OSCommand,
|
2022-01-30 01:23:39 +02:00
|
|
|
) *FilesHelper {
|
|
|
|
return &FilesHelper{
|
2022-01-16 05:46:53 +02:00
|
|
|
c: c,
|
|
|
|
git: git,
|
|
|
|
os: os,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-30 01:23:39 +02:00
|
|
|
var _ controllers.IFileHelper = &FilesHelper{}
|
2022-01-16 05:46:53 +02:00
|
|
|
|
2022-01-30 01:23:39 +02:00
|
|
|
func (self *FilesHelper) EditFile(filename string) error {
|
2022-01-16 05:46:53 +02:00
|
|
|
return self.EditFileAtLine(filename, 1)
|
|
|
|
}
|
|
|
|
|
2022-01-30 01:23:39 +02:00
|
|
|
func (self *FilesHelper) EditFileAtLine(filename string, lineNumber int) error {
|
2022-01-16 05:46:53 +02:00
|
|
|
cmdStr, err := self.git.File.GetEditCmdStr(filename, lineNumber)
|
|
|
|
if err != nil {
|
|
|
|
return self.c.Error(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
self.c.LogAction(self.c.Tr.Actions.EditFile)
|
|
|
|
return self.c.RunSubprocessAndRefresh(
|
|
|
|
self.os.Cmd.NewShell(cmdStr),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-30 01:23:39 +02:00
|
|
|
func (self *FilesHelper) OpenFile(filename string) error {
|
2022-01-16 05:46:53 +02:00
|
|
|
self.c.LogAction(self.c.Tr.Actions.OpenFile)
|
|
|
|
if err := self.os.OpenFile(filename); err != nil {
|
|
|
|
return self.c.Error(err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|