diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-28 20:44:36 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-03-17 19:13:40 +1100 |
commit | a90b6efded49abcfa2516db794d7875b0396f558 (patch) | |
tree | ad9c3738830437064ada223f0978dab1d726b479 /pkg/gui/remotes_panel.go | |
parent | fa8571e1f4c349e401542285ea238acdbd9d17ec (diff) |
start refactoring gui
Diffstat (limited to 'pkg/gui/remotes_panel.go')
-rw-r--r-- | pkg/gui/remotes_panel.go | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/pkg/gui/remotes_panel.go b/pkg/gui/remotes_panel.go index c74653a27..bc06f77f0 100644 --- a/pkg/gui/remotes_panel.go +++ b/pkg/gui/remotes_panel.go @@ -5,7 +5,9 @@ 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" ) @@ -42,7 +44,7 @@ func (gui *Gui) refreshRemotes() error { remotes, err := gui.Git.Loaders.Remotes.GetRemotes() if err != nil { - return gui.surfaceError(err) + return gui.PopupHandler.Error(err) } gui.State.Remotes = remotes @@ -79,17 +81,17 @@ func (gui *Gui) handleRemoteEnter() error { } func (gui *Gui) handleAddRemote() error { - return gui.prompt(promptOpts{ - title: gui.Tr.LcNewRemoteName, - handleConfirm: func(remoteName string) error { - return gui.prompt(promptOpts{ - title: gui.Tr.LcNewRemoteUrl, - handleConfirm: func(remoteUrl string) 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(refreshOptions{scope: []RefreshableView{REMOTES}}) + return gui.refreshSidePanels(types.RefreshOptions{Scope: []types.RefreshableView{types.REMOTES}}) }, }) }, @@ -103,16 +105,16 @@ func (gui *Gui) handleRemoveRemote() error { return nil } - return gui.ask(askOpts{ - title: gui.Tr.LcRemoveRemote, - prompt: gui.Tr.LcRemoveRemotePrompt + " '" + remote.Name + "'?", - handleConfirm: func() error { + 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.surfaceError(err) + return gui.PopupHandler.Error(err) } - return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{BRANCHES, REMOTES}}) + return gui.refreshSidePanels(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}}) }, }) } @@ -130,14 +132,14 @@ func (gui *Gui) handleEditRemote() error { }, ) - return gui.prompt(promptOpts{ - title: editNameMessage, - initialContent: remote.Name, - handleConfirm: func(updatedRemoteName string) error { + 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.surfaceError(err) + return gui.PopupHandler.Error(err) } } @@ -154,15 +156,15 @@ func (gui *Gui) handleEditRemote() error { url = urls[0] } - return gui.prompt(promptOpts{ - title: editUrlMessage, - initialContent: url, - handleConfirm: func(updatedRemoteUrl string) error { + 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.surfaceError(err) + return gui.PopupHandler.Error(err) } - return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{BRANCHES, REMOTES}}) + return gui.refreshSidePanels(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}}) }, }) }, @@ -175,13 +177,15 @@ func (gui *Gui) handleFetchRemote() error { return nil } - return gui.WithWaitingStatus(gui.Tr.FetchingRemoteStatus, func() error { + 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) - gui.handleCredentialsPopup(err) + if err != nil { + _ = gui.PopupHandler.Error(err) + } - return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{BRANCHES, REMOTES}}) + return gui.refreshSidePanels(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}}) }) } |