diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-23 14:43:48 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-08-23 15:11:06 +1000 |
commit | 4fb52ce2abcd9cfbd566188a20c8919e27dafebb (patch) | |
tree | 86442dcd83cf4e11fe664c1b216ef1e133b48776 /pkg/gui | |
parent | 2915134007be939bd43fae74cb7559b4cfdccc9d (diff) |
better handling of there being no commit files
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/commit_files_panel.go | 11 | ||||
-rw-r--r-- | pkg/gui/patch_building_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/presentation/commit_files.go | 6 |
3 files changed, 10 insertions, 9 deletions
diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go index 15d073785..5b244ba31 100644 --- a/pkg/gui/commit_files_panel.go +++ b/pkg/gui/commit_files_panel.go @@ -7,7 +7,7 @@ import ( func (gui *Gui) getSelectedCommitFile() *commands.CommitFile { selectedLine := gui.State.Panels.CommitFiles.SelectedLineIdx - if selectedLine == -1 { + if selectedLine == -1 || selectedLine > len(gui.State.CommitFiles)-1 { return nil } @@ -19,8 +19,6 @@ func (gui *Gui) handleCommitFileSelect() error { commitFile := gui.getSelectedCommitFile() if commitFile == nil { - // TODO: consider making it so that we can also render strings to our own view through some common interface, or just render this to the main view for consistency - gui.renderString("commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) return nil } @@ -42,7 +40,10 @@ func (gui *Gui) handleCommitFileSelect() error { } func (gui *Gui) handleCheckoutCommitFile(g *gocui.Gui, v *gocui.View) error { - file := gui.State.CommitFiles[gui.State.Panels.CommitFiles.SelectedLineIdx] + file := gui.getSelectedCommitFile() + if file == nil { + return nil + } if err := gui.GitCommand.CheckoutFile(file.Parent, file.Name); err != nil { return gui.surfaceError(err) @@ -113,7 +114,6 @@ func (gui *Gui) handleEditCommitFile(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleToggleFileForPatch(g *gocui.Gui, v *gocui.View) error { commitFile := gui.getSelectedCommitFile() if commitFile == nil { - gui.renderString("commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) return nil } @@ -166,7 +166,6 @@ func (gui *Gui) handleEnterCommitFile(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) enterCommitFile(selectedLineIdx int) error { commitFile := gui.getSelectedCommitFile() if commitFile == nil { - gui.renderString("commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) return nil } diff --git a/pkg/gui/patch_building_panel.go b/pkg/gui/patch_building_panel.go index 7f741a7b0..c69b22476 100644 --- a/pkg/gui/patch_building_panel.go +++ b/pkg/gui/patch_building_panel.go @@ -31,7 +31,6 @@ func (gui *Gui) refreshPatchBuildingPanel(selectedLineIdx int) error { // get diff from commit file that's currently selected commitFile := gui.getSelectedCommitFile() if commitFile == nil { - gui.renderString("commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) return nil } @@ -76,7 +75,6 @@ func (gui *Gui) handleToggleSelectionForPatch(g *gocui.Gui, v *gocui.View) error // add range of lines to those set for the file commitFile := gui.getSelectedCommitFile() if commitFile == nil { - gui.renderString("commitFiles", gui.Tr.SLocalize("NoCommiteFiles")) return nil } diff --git a/pkg/gui/presentation/commit_files.go b/pkg/gui/presentation/commit_files.go index 8b6fbfe5b..d930c60dc 100644 --- a/pkg/gui/presentation/commit_files.go +++ b/pkg/gui/presentation/commit_files.go @@ -9,6 +9,10 @@ import ( ) func GetCommitFileListDisplayStrings(commitFiles []*commands.CommitFile, diffName string) [][]string { + if len(commitFiles) == 0 { + return [][]string{{utils.ColoredString("(none)", color.FgRed)}} + } + lines := make([][]string, len(commitFiles)) for i := range commitFiles { @@ -54,6 +58,6 @@ func getColorForChangeStatus(changeStatus string) color.Attribute { case "T": return color.FgMagenta default: - return color.FgWhite + return theme.DefaultTextColor } } |