diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-17 12:02:39 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-11-21 22:07:14 +1100 |
commit | 6b7aaeca45847ebc41aa0fd9b773362d4a79f1ab (patch) | |
tree | d8f35e24c44a1474414cd09c76b9ae9d904c6451 /pkg/gui | |
parent | 1f3e1720a3a0bd31c0816a94d0b7c5bca1589f96 (diff) |
support adding/removing remotes
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/branches_panel.go | 44 | ||||
-rw-r--r-- | pkg/gui/confirmation_panel.go | 8 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 16 | ||||
-rw-r--r-- | pkg/gui/remote_branches_panel.go | 14 | ||||
-rw-r--r-- | pkg/gui/remotes_panel.go | 50 |
5 files changed, 106 insertions, 26 deletions
diff --git a/pkg/gui/branches_panel.go b/pkg/gui/branches_panel.go index 54a9301e2..c47138bd1 100644 --- a/pkg/gui/branches_panel.go +++ b/pkg/gui/branches_panel.go @@ -95,9 +95,12 @@ func (gui *Gui) refreshBranches(g *gocui.Gui) error { } gui.State.Branches = builder.Build() - gui.refreshSelectedLine(&gui.State.Panels.Branches.SelectedLine, len(gui.State.Branches)) - if err := gui.RenderSelectedBranchUpstreamDifferences(); err != nil { - return err + // TODO: if we're in the remotes view and we've just deleted a remote we need to refresh accordingly + if gui.getBranchesView().Context == "local-branches" { + gui.refreshSelectedLine(&gui.State.Panels.Branches.SelectedLine, len(gui.State.Branches)) + if err := gui.RenderSelectedBranchUpstreamDifferences(); err != nil { + return err + } } return gui.refreshStatus(g) @@ -105,6 +108,20 @@ func (gui *Gui) refreshBranches(g *gocui.Gui) error { return nil } +func (gui *Gui) renderLocalBranchesWithSelection() error { + branchesView := gui.getBranchesView() + + gui.refreshSelectedLine(&gui.State.Panels.Branches.SelectedLine, len(gui.State.Branches)) + if err := gui.renderListPanel(branchesView, gui.State.Branches); err != nil { + return err + } + if err := gui.handleBranchSelect(gui.g, branchesView); err != nil { + return err + } + + return nil +} + // specific functions func (gui *Gui) handleBranchPress(g *gocui.Gui, v *gocui.View) error { @@ -350,26 +367,11 @@ func (gui *Gui) switchBranchesPanelContext(context string) error { switch context { case "local-branches": - if err := gui.renderListPanel(branchesView, gui.State.Branches); err != nil { - return err - } - if err := gui.handleBranchSelect(gui.g, gui.getBranchesView()); err != nil { - return err - } + return gui.renderLocalBranchesWithSelection() case "remotes": - if err := gui.renderListPanel(branchesView, gui.State.Remotes); err != nil { - return err - } - if err := gui.handleRemoteSelect(gui.g, gui.getBranchesView()); err != nil { - return err - } + return gui.renderRemotesWithSelection() case "remote-branches": - if err := gui.renderListPanel(branchesView, gui.State.RemoteBranches); err != nil { - return err - } - if err := gui.handleRemoteBranchSelect(gui.g, gui.getBranchesView()); err != nil { - return err - } + return gui.renderRemoteBranchesWithSelection() } return nil diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index db0bf7bdc..0638f6fba 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -17,12 +17,18 @@ import ( func (gui *Gui) wrappedConfirmationFunction(function func(*gocui.Gui, *gocui.View) error, returnFocusOnClose bool) func(*gocui.Gui, *gocui.View) error { return func(g *gocui.Gui, v *gocui.View) error { + + if err := gui.closeConfirmationPrompt(g, returnFocusOnClose); err != nil { + return err + } + if function != nil { if err := function(g, v); err != nil { return err } } - return gui.closeConfirmationPrompt(g, returnFocusOnClose) + + return nil } } diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index a67894999..eb817e76d 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -1042,6 +1042,22 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Handler: gui.handleRemoteEnter, }, { + ViewName: "branches", + Contexts: []string{"remotes"}, + Key: 'n', + Modifier: gocui.ModNone, + Handler: gui.handleAddRemote, + Description: gui.Tr.SLocalize("addNewRemote"), + }, + { + ViewName: "branches", + Contexts: []string{"remotes"}, + Key: 'd', + Modifier: gocui.ModNone, + Handler: gui.handleRemoveRemote, + Description: gui.Tr.SLocalize("removeRemote"), + }, + { ViewName: "commits", Key: gocui.MouseLeft, Modifier: gocui.ModNone, diff --git a/pkg/gui/remote_branches_panel.go b/pkg/gui/remote_branches_panel.go index 544e8bf81..f47ea9f63 100644 --- a/pkg/gui/remote_branches_panel.go +++ b/pkg/gui/remote_branches_panel.go @@ -67,3 +67,17 @@ func (gui *Gui) handleRemoteBranchSelect(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleRemoteBranchesEscape(g *gocui.Gui, v *gocui.View) error { return gui.switchBranchesPanelContext("remotes") } + +func (gui *Gui) renderRemoteBranchesWithSelection() error { + branchesView := gui.getBranchesView() + + gui.refreshSelectedLine(&gui.State.Panels.RemoteBranches.SelectedLine, len(gui.State.RemoteBranches)) + if err := gui.renderListPanel(branchesView, gui.State.RemoteBranches); err != nil { + return err + } + if err := gui.handleRemoteBranchSelect(gui.g, branchesView); err != nil { + return err + } + + return nil +} diff --git a/pkg/gui/remotes_panel.go b/pkg/gui/remotes_panel.go index c63b2f07d..1402cfd0f 100644 --- a/pkg/gui/remotes_panel.go +++ b/pkg/gui/remotes_panel.go @@ -60,10 +60,23 @@ func (gui *Gui) refreshRemotes() error { gui.State.Remotes = remotes - gui.g.Update(func(g *gocui.Gui) error { - gui.refreshSelectedLine(&gui.State.Panels.Remotes.SelectedLine, len(gui.State.Remotes)) - return nil - }) + if gui.getBranchesView().Context == "remotes" { + return gui.renderRemotesWithSelection() + } + + return nil +} + +func (gui *Gui) renderRemotesWithSelection() error { + branchesView := gui.getBranchesView() + + gui.refreshSelectedLine(&gui.State.Panels.Remotes.SelectedLine, len(gui.State.Remotes)) + if err := gui.renderListPanel(branchesView, gui.State.Remotes); err != nil { + return err + } + if err := gui.handleRemoteSelect(gui.g, branchesView); err != nil { + return err + } return nil } @@ -82,3 +95,32 @@ func (gui *Gui) handleRemoteEnter(g *gocui.Gui, v *gocui.View) error { return gui.switchBranchesPanelContext("remote-branches") } + +func (gui *Gui) handleAddRemote(g *gocui.Gui, v *gocui.View) error { + branchesView := gui.getBranchesView() + return gui.createPromptPanel(g, branchesView, gui.Tr.SLocalize("newRemoteName"), "", func(g *gocui.Gui, v *gocui.View) error { + remoteName := gui.trimmedContent(v) + return gui.createPromptPanel(g, branchesView, gui.Tr.SLocalize("newRemoteUrl"), "", func(g *gocui.Gui, v *gocui.View) error { + remoteUrl := gui.trimmedContent(v) + if err := gui.GitCommand.AddRemote(remoteName, remoteUrl); err != nil { + return err + } + return gui.refreshRemotes() + }) + }) +} + +func (gui *Gui) handleRemoveRemote(g *gocui.Gui, v *gocui.View) error { + remote := gui.getSelectedRemote() + if remote == nil { + return nil + } + return gui.createConfirmationPanel(g, v, true, gui.Tr.SLocalize("removeRemote"), gui.Tr.SLocalize("removeRemotePrompt")+" '"+remote.Name+"'?", func(*gocui.Gui, *gocui.View) error { + if err := gui.GitCommand.RemoveRemote(remote.Name); err != nil { + return err + } + + return gui.refreshRemotes() + + }, nil) +} |