diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-16 14:46:53 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-17 19:13:40 +1100 |
commit | 1dd7307fde033dae5fececac15810a99e26c3d91 (patch) | |
tree | 4e851c9e3229a6fe3b4191f6311d05d7a9142960 /pkg/gui/remotes_panel.go | |
parent | a90b6efded49abcfa2516db794d7875b0396f558 (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/remotes_panel.go')
-rw-r--r-- | pkg/gui/remotes_panel.go | 136 |
1 files changed, 3 insertions, 133 deletions
diff --git a/pkg/gui/remotes_panel.go b/pkg/gui/remotes_panel.go index bc06f77f0..1c086e2fc 100644 --- a/pkg/gui/remotes_panel.go +++ b/pkg/gui/remotes_panel.go @@ -5,10 +5,8 @@ import ( "strings" "github.com/jesseduffield/lazygit/pkg/commands/models" - "github.com/jesseduffield/lazygit/pkg/gui/popup" "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" - "github.com/jesseduffield/lazygit/pkg/utils" ) // list panel functions @@ -42,9 +40,9 @@ func (gui *Gui) remotesRenderToMain() error { func (gui *Gui) refreshRemotes() error { prevSelectedRemote := gui.getSelectedRemote() - remotes, err := gui.Git.Loaders.Remotes.GetRemotes() + remotes, err := gui.git.Loaders.Remotes.GetRemotes() if err != nil { - return gui.PopupHandler.Error(err) + return gui.c.Error(err) } gui.State.Remotes = remotes @@ -59,133 +57,5 @@ func (gui *Gui) refreshRemotes() error { } } - return gui.postRefreshUpdate(gui.mustContextForContextKey(ContextKey(gui.Views.Branches.Context))) -} - -func (gui *Gui) handleRemoteEnter() error { - // naive implementation: get the branches and render them to the list, change the context - remote := gui.getSelectedRemote() - if remote == nil { - return nil - } - - gui.State.RemoteBranches = remote.Branches - - newSelectedLine := 0 - if len(remote.Branches) == 0 { - newSelectedLine = -1 - } - gui.State.Panels.RemoteBranches.SelectedLineIdx = newSelectedLine - - return gui.pushContext(gui.State.Contexts.RemoteBranches) -} - -func (gui *Gui) handleAddRemote() error { - return gui.PopupHandler.Prompt(popup.PromptOpts{ - Title: gui.Tr.LcNewRemoteName, - HandleConfirm: func(remoteName string) error { - return gui.PopupHandler.Prompt(popup.PromptOpts{ - Title: gui.Tr.LcNewRemoteUrl, - HandleConfirm: func(remoteUrl string) error { - gui.logAction(gui.Tr.Actions.AddRemote) - if err := gui.Git.Remote.AddRemote(remoteName, remoteUrl); err != nil { - return err - } - return gui.refreshSidePanels(types.RefreshOptions{Scope: []types.RefreshableView{types.REMOTES}}) - }, - }) - }, - }) - -} - -func (gui *Gui) handleRemoveRemote() error { - remote := gui.getSelectedRemote() - if remote == nil { - return nil - } - - return gui.PopupHandler.Ask(popup.AskOpts{ - Title: gui.Tr.LcRemoveRemote, - Prompt: gui.Tr.LcRemoveRemotePrompt + " '" + remote.Name + "'?", - HandleConfirm: func() error { - gui.logAction(gui.Tr.Actions.RemoveRemote) - if err := gui.Git.Remote.RemoveRemote(remote.Name); err != nil { - return gui.PopupHandler.Error(err) - } - - return gui.refreshSidePanels(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}}) - }, - }) -} - -func (gui *Gui) handleEditRemote() error { - remote := gui.getSelectedRemote() - if remote == nil { - return nil - } - - editNameMessage := utils.ResolvePlaceholderString( - gui.Tr.LcEditRemoteName, - map[string]string{ - "remoteName": remote.Name, - }, - ) - - return gui.PopupHandler.Prompt(popup.PromptOpts{ - Title: editNameMessage, - InitialContent: remote.Name, - HandleConfirm: func(updatedRemoteName string) error { - if updatedRemoteName != remote.Name { - gui.logAction(gui.Tr.Actions.UpdateRemote) - if err := gui.Git.Remote.RenameRemote(remote.Name, updatedRemoteName); err != nil { - return gui.PopupHandler.Error(err) - } - } - - editUrlMessage := utils.ResolvePlaceholderString( - gui.Tr.LcEditRemoteUrl, - map[string]string{ - "remoteName": updatedRemoteName, - }, - ) - - urls := remote.Urls - url := "" - if len(urls) > 0 { - url = urls[0] - } - - return gui.PopupHandler.Prompt(popup.PromptOpts{ - Title: editUrlMessage, - InitialContent: url, - HandleConfirm: func(updatedRemoteUrl string) error { - gui.logAction(gui.Tr.Actions.UpdateRemote) - if err := gui.Git.Remote.UpdateRemoteUrl(updatedRemoteName, updatedRemoteUrl); err != nil { - return gui.PopupHandler.Error(err) - } - return gui.refreshSidePanels(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}}) - }, - }) - }, - }) -} - -func (gui *Gui) handleFetchRemote() error { - remote := gui.getSelectedRemote() - if remote == nil { - return nil - } - - return gui.PopupHandler.WithWaitingStatus(gui.Tr.FetchingRemoteStatus, func() error { - gui.Mutexes.FetchMutex.Lock() - defer gui.Mutexes.FetchMutex.Unlock() - - err := gui.Git.Sync.FetchRemote(remote.Name) - if err != nil { - _ = gui.PopupHandler.Error(err) - } - - return gui.refreshSidePanels(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}}) - }) + return gui.c.PostRefreshUpdate(gui.mustContextForContextKey(types.ContextKey(gui.Views.Branches.Context))) } |