summaryrefslogtreecommitdiffstats
path: root/pkg/gui/file_helper.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-01-16 14:46:53 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-03-17 19:13:40 +1100
commit1dd7307fde033dae5fececac15810a99e26c3d91 (patch)
tree4e851c9e3229a6fe3b4191f6311d05d7a9142960 /pkg/gui/file_helper.go
parenta90b6efded49abcfa2516db794d7875b0396f558 (diff)
start moving commit panel handlers into controller
more and more move rebase commit refreshing into existing abstraction and more and more WIP and more handling clicks properly fix merge conflicts update cheatsheet lots more preparation to start moving things into controllers WIP better typing expand on remotes controller moving more code into controllers
Diffstat (limited to 'pkg/gui/file_helper.go')
-rw-r--r--pkg/gui/file_helper.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/pkg/gui/file_helper.go b/pkg/gui/file_helper.go
new file mode 100644
index 000000000..1b50aac82
--- /dev/null
+++ b/pkg/gui/file_helper.go
@@ -0,0 +1,51 @@
+package gui
+
+import (
+ "github.com/jesseduffield/lazygit/pkg/commands"
+ "github.com/jesseduffield/lazygit/pkg/commands/oscommands"
+ "github.com/jesseduffield/lazygit/pkg/gui/controllers"
+)
+
+type FileHelper struct {
+ c *controllers.ControllerCommon
+ git *commands.GitCommand
+ os *oscommands.OSCommand
+}
+
+func NewFileHelper(
+ c *controllers.ControllerCommon,
+ git *commands.GitCommand,
+ os *oscommands.OSCommand,
+) *FileHelper {
+ return &FileHelper{
+ c: c,
+ git: git,
+ os: os,
+ }
+}
+
+var _ controllers.IFileHelper = &FileHelper{}
+
+func (self *FileHelper) EditFile(filename string) error {
+ return self.EditFileAtLine(filename, 1)
+}
+
+func (self *FileHelper) EditFileAtLine(filename string, lineNumber int) error {
+ 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),
+ )
+}
+
+func (self *FileHelper) OpenFile(filename string) error {
+ self.c.LogAction(self.c.Tr.Actions.OpenFile)
+ if err := self.os.OpenFile(filename); err != nil {
+ return self.c.Error(err)
+ }
+ return nil
+}