diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2020-02-14 23:26:09 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2020-02-15 08:47:36 +1100 |
commit | d929b847867c696be5b9ea48ef52778157f00038 (patch) | |
tree | c417ec2a34e0072b0eaa73ad434eae9ccaf0946b /pkg | |
parent | 8ef3297b11c3ab14221a50a49c0660be1257e58c (diff) |
refactor recent repos menu panel
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/recent_repos_panel.go | 47 |
1 files changed, 20 insertions, 27 deletions
diff --git a/pkg/gui/recent_repos_panel.go b/pkg/gui/recent_repos_panel.go index a9ea5d481..c7da2409e 100644 --- a/pkg/gui/recent_repos_panel.go +++ b/pkg/gui/recent_repos_panel.go @@ -10,41 +10,34 @@ import ( "github.com/jesseduffield/lazygit/pkg/utils" ) -type recentRepo struct { - path string -} - -// GetDisplayStrings returns the path from a recent repo. -func (r *recentRepo) GetDisplayStrings(isFocused bool) []string { - yellow := color.New(color.FgMagenta) - base := filepath.Base(r.path) - path := yellow.Sprint(r.path) - return []string{base, path} -} - func (gui *Gui) handleCreateRecentReposMenu(g *gocui.Gui, v *gocui.View) error { recentRepoPaths := gui.Config.GetAppState().RecentRepos reposCount := utils.Min(len(recentRepoPaths), 20) + yellow := color.New(color.FgMagenta) // we won't show the current repo hence the -1 - recentRepos := make([]*recentRepo, reposCount-1) + menuItems := make([]*menuItem, reposCount-1) for i, path := range recentRepoPaths[1:reposCount] { - recentRepos[i] = &recentRepo{path: path} - } - - handleMenuPress := func(index int) error { - repo := recentRepos[index] - if err := os.Chdir(repo.path); err != nil { - return err - } - newGitCommand, err := commands.NewGitCommand(gui.Log, gui.OSCommand, gui.Tr, gui.Config) - if err != nil { - return err + innerPath := path + menuItems[i] = &menuItem{ + displayStrings: []string{ + filepath.Base(innerPath), + yellow.Sprint(innerPath), + }, + onPress: func() error { + if err := os.Chdir(innerPath); err != nil { + return err + } + newGitCommand, err := commands.NewGitCommand(gui.Log, gui.OSCommand, gui.Tr, gui.Config) + if err != nil { + return err + } + gui.GitCommand = newGitCommand + return gui.Errors.ErrSwitchRepo + }, } - gui.GitCommand = newGitCommand - return gui.Errors.ErrSwitchRepo } - return gui.createMenu(gui.Tr.SLocalize("RecentRepos"), recentRepos, len(recentRepos), handleMenuPress) + return gui.createMenuNew(gui.Tr.SLocalize("RecentRepos"), menuItems, createMenuOptions{showCancel: true}) } // updateRecentRepoList registers the fact that we opened lazygit in this repo, |