summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-11-05 17:57:59 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-11-05 19:22:01 +1100
commit10fe88a2cf79d525f4dfa767b2d0fab1793127e8 (patch)
tree127b3cf0d06c9ddd114a3863bca01519ffab92fc
parent1a38bfb76d5e2f1b0f03c35fc17f463b0ecf54f1 (diff)
more work on managing focus when applying patch command
-rw-r--r--pkg/gui/commit_files_panel.go4
-rw-r--r--pkg/gui/commits_panel.go2
-rw-r--r--pkg/gui/gui.go6
-rw-r--r--pkg/gui/patch_building_panel.go7
-rw-r--r--pkg/gui/patch_options_panel.go33
5 files changed, 40 insertions, 12 deletions
diff --git a/pkg/gui/commit_files_panel.go b/pkg/gui/commit_files_panel.go
index 952f2bbfa..0141e25b8 100644
--- a/pkg/gui/commit_files_panel.go
+++ b/pkg/gui/commit_files_panel.go
@@ -96,6 +96,10 @@ func (gui *Gui) refreshCommitFilesView() error {
return err
}
+ if err := gui.refreshPatchBuildingPanel(); err != nil {
+ return err
+ }
+
commit := gui.getSelectedCommit(gui.g)
if commit == nil {
return nil
diff --git a/pkg/gui/commits_panel.go b/pkg/gui/commits_panel.go
index 1d7547868..ee4841aab 100644
--- a/pkg/gui/commits_panel.go
+++ b/pkg/gui/commits_panel.go
@@ -85,7 +85,7 @@ func (gui *Gui) refreshCommits(g *gocui.Gui) error {
if g.CurrentView() == v {
gui.handleCommitSelect(g, v)
}
- if g.CurrentView() == gui.getCommitFilesView() {
+ if g.CurrentView() == gui.getCommitFilesView() || (g.CurrentView() == gui.getMainView() || gui.State.Contexts["main"] == "patch-building") {
return gui.refreshCommitFilesView()
}
return nil
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index bc3e3a65a..8a14fde36 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -277,8 +277,10 @@ func (gui *Gui) onFocusLost(v *gocui.View, newView *gocui.View) error {
return err
}
case "commitFiles":
- if _, err := gui.g.SetViewOnBottom(v.Name()); err != nil {
- return err
+ if gui.State.Contexts["main"] != "patch-building" {
+ if _, err := gui.g.SetViewOnBottom(v.Name()); err != nil {
+ return err
+ }
}
}
gui.Log.Info(v.Name() + " focus lost")
diff --git a/pkg/gui/patch_building_panel.go b/pkg/gui/patch_building_panel.go
index 863e464fe..b32253557 100644
--- a/pkg/gui/patch_building_panel.go
+++ b/pkg/gui/patch_building_panel.go
@@ -5,6 +5,10 @@ import (
)
func (gui *Gui) refreshPatchBuildingPanel() error {
+ if gui.GitCommand.PatchManager == nil {
+ return gui.handleEscapePatchBuildingPanel(gui.g, nil)
+ }
+
gui.State.SplitMainPanel = true
// get diff from commit file that's currently selected
@@ -23,8 +27,6 @@ func (gui *Gui) refreshPatchBuildingPanel() error {
return err
}
- gui.Log.Warn(secondaryDiff)
-
empty, err := gui.refreshLineByLinePanel(diff, secondaryDiff, false)
if err != nil {
return err
@@ -83,6 +85,7 @@ func (gui *Gui) handleRemoveSelectionFromPatch(g *gocui.Gui, v *gocui.View) erro
func (gui *Gui) handleEscapePatchBuildingPanel(g *gocui.Gui, v *gocui.View) error {
gui.State.Panels.LineByLine = nil
+ gui.State.Contexts["main"] = "normal"
return gui.switchFocus(gui.g, nil, gui.getCommitFilesView())
}
diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go
index a55e0d4a7..a966040e2 100644
--- a/pkg/gui/patch_options_panel.go
+++ b/pkg/gui/patch_options_panel.go
@@ -60,11 +60,29 @@ func (gui *Gui) getPatchCommitIndex() int {
return -1
}
+func (gui *Gui) validateNormalWorkingTreeState() (bool, error) {
+ if gui.State.WorkingTreeState != "normal" {
+ return false, gui.createErrorPanel(gui.g, gui.Tr.SLocalize("CantPatchWhileRebasingError"))
+ }
+ return true, nil
+}
+
+func (gui *Gui) returnFocusFromLineByLinePanelIfNecessary() error {
+ if gui.State.Contexts["main"] == "patch-building" {
+ return gui.handleEscapePatchBuildingPanel(gui.g, nil)
+ }
+ return nil
+}
+
func (gui *Gui) handleDeletePatchFromCommit() error {
if ok, err := gui.validateNormalWorkingTreeState(); !ok {
return err
}
+ if err := gui.returnFocusFromLineByLinePanelIfNecessary(); err != nil {
+ return err
+ }
+
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
commitIndex := gui.getPatchCommitIndex()
err := gui.GitCommand.DeletePatchesFromCommit(gui.State.Commits, commitIndex, gui.GitCommand.PatchManager)
@@ -77,6 +95,10 @@ func (gui *Gui) handleMovePatchToSelectedCommit() error {
return err
}
+ if err := gui.returnFocusFromLineByLinePanelIfNecessary(); err != nil {
+ return err
+ }
+
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
commitIndex := gui.getPatchCommitIndex()
err := gui.GitCommand.MovePatchToSelectedCommit(gui.State.Commits, commitIndex, gui.State.Panels.Commits.SelectedLine, gui.GitCommand.PatchManager)
@@ -84,18 +106,15 @@ func (gui *Gui) handleMovePatchToSelectedCommit() error {
})
}
-func (gui *Gui) validateNormalWorkingTreeState() (bool, error) {
- if gui.State.WorkingTreeState != "normal" {
- return false, gui.createErrorPanel(gui.g, gui.Tr.SLocalize("CantPatchWhileRebasingError"))
- }
- return true, nil
-}
-
func (gui *Gui) handlePullPatchIntoWorkingTree() error {
if ok, err := gui.validateNormalWorkingTreeState(); !ok {
return err
}
+ if err := gui.returnFocusFromLineByLinePanelIfNecessary(); err != nil {
+ return err
+ }
+
return gui.WithWaitingStatus(gui.Tr.SLocalize("RebasingStatus"), func() error {
commitIndex := gui.getPatchCommitIndex()
err := gui.GitCommand.PullPatchIntoIndex(gui.State.Commits, commitIndex, gui.GitCommand.PatchManager)