diff options
Diffstat (limited to 'pkg/gui/files_panel.go')
-rw-r--r-- | pkg/gui/files_panel.go | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index aaff46949..6c62240a7 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -7,7 +7,6 @@ import ( // "strings" - "errors" "os/exec" "strings" @@ -17,13 +16,6 @@ import ( "github.com/jesseduffield/lazygit/pkg/i18n" ) -var tr *i18n.Localizer - -var ( - errNoFiles = errors.New(tr.SLocalize("NoChangedFiles", "No changed files")) - errNoUsername = errors.New(tr.SLocalize("NoUsernameSetErr", `No username set. Please do: git config --global user.name "Your Name"`)) -) - func (gui *Gui) stagedFiles() []commands.File { files := gui.State.Files result := make([]commands.File, 0) @@ -57,7 +49,7 @@ func (gui *Gui) stageSelectedFile(g *gocui.Gui) error { func (gui *Gui) handleFilePress(g *gocui.Gui, v *gocui.View) error { file, err := gui.getSelectedFile(g) if err != nil { - if err == errNoFiles { + if err == gui.Errors.ErrNoFiles { return nil } return err @@ -83,16 +75,16 @@ func (gui *Gui) handleFilePress(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleAddPatch(g *gocui.Gui, v *gocui.View) error { file, err := gui.getSelectedFile(g) if err != nil { - if err == errNoFiles { + if err == gui.Errors.ErrNoFiles { return nil } return err } if !file.HasUnstagedChanges { - return gui.createErrorPanel(g, tr.SLocalize("FileHasNoUnstagedChanges", "File has no unstaged changes to add")) + return gui.createErrorPanel(g, gui.Tr.SLocalize("FileHasNoUnstagedChanges", "File has no unstaged changes to add")) } if !file.Tracked { - return gui.createErrorPanel(g, tr.SLocalize("CannotGitAdd", "Cannot git add --patch untracked files")) + return gui.createErrorPanel(g, gui.Tr.SLocalize("CannotGitAdd", "Cannot git add --patch untracked files")) } sub, err := gui.GitCommand.AddPatch(file.Name) if err != nil { @@ -104,7 +96,7 @@ func (gui *Gui) handleAddPatch(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) getSelectedFile(g *gocui.Gui) (commands.File, error) { if len(gui.State.Files) == 0 { - return commands.File{}, errNoFiles + return commands.File{}, gui.Errors.ErrNoFiles } filesView, err := g.View("files") if err != nil { @@ -117,7 +109,7 @@ func (gui *Gui) getSelectedFile(g *gocui.Gui) (commands.File, error) { func (gui *Gui) handleFileRemove(g *gocui.Gui, v *gocui.View) error { file, err := gui.getSelectedFile(g) if err != nil { - if err == errNoFiles { + if err == gui.Errors.ErrNoFiles { return nil } return err @@ -142,7 +134,7 @@ func (gui *Gui) handleIgnoreFile(g *gocui.Gui, v *gocui.View) error { return gui.createErrorPanel(g, err.Error()) } if file.Tracked { - return gui.createErrorPanel(g, tr.SLocalize("CantIgnoreTrackFiles", "Cannot ignore tracked files")) + return gui.createErrorPanel(g, gui.Tr.SLocalize("CantIgnoreTrackFiles", "Cannot ignore tracked files")) } gui.GitCommand.Ignore(file.Name) return gui.refreshFiles(g) @@ -178,7 +170,7 @@ func (gui *Gui) renderfilesOptions(g *gocui.Gui, file *commands.File) error { func (gui *Gui) handleFileSelect(g *gocui.Gui, v *gocui.View) error { file, err := gui.getSelectedFile(g) if err != nil { - if err != errNoFiles { + if err != gui.Errors.ErrNoFiles { return err } gui.renderString(g, "main", "No changed files") @@ -233,7 +225,7 @@ func (gui *Gui) PrepareSubProcess(g *gocui.Gui, commands ...string) error { func (gui *Gui) genericFileOpen(g *gocui.Gui, v *gocui.View, open func(string) (*exec.Cmd, error)) error { file, err := gui.getSelectedFile(g) if err != nil { - if err != errNoFiles { + if err != gui.Errors.ErrNoFiles { return err } return nil @@ -306,7 +298,7 @@ func (gui *Gui) renderFile(file commands.File, filesView *gocui.View) { func (gui *Gui) catSelectedFile(g *gocui.Gui) (string, error) { item, err := gui.getSelectedFile(g) if err != nil { - if err != errNoFiles { + if err != gui.Errors.ErrNoFiles { return "", err } return "", gui.renderString(g, "main", "No file to display") @@ -372,7 +364,7 @@ func (gui *Gui) handleSwitchToMerge(g *gocui.Gui, v *gocui.View) error { } file, err := gui.getSelectedFile(g) if err != nil { - if err != errNoFiles { + if err != gui.Errors.ErrNoFiles { return err } return nil |