From a90b6efded49abcfa2516db794d7875b0396f558 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Fri, 28 Jan 2022 20:44:36 +1100 Subject: start refactoring gui --- pkg/gui/patch_options_panel.go | 62 ++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 30 deletions(-) (limited to 'pkg/gui/patch_options_panel.go') diff --git a/pkg/gui/patch_options_panel.go b/pkg/gui/patch_options_panel.go index c9a3defce..915572c16 100644 --- a/pkg/gui/patch_options_panel.go +++ b/pkg/gui/patch_options_panel.go @@ -4,41 +4,43 @@ import ( "fmt" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" + "github.com/jesseduffield/lazygit/pkg/gui/popup" + "github.com/jesseduffield/lazygit/pkg/gui/types" ) func (gui *Gui) handleCreatePatchOptionsMenu() error { if !gui.Git.Patch.PatchManager.Active() { - return gui.createErrorPanel(gui.Tr.NoPatchError) + return gui.PopupHandler.ErrorMsg(gui.Tr.NoPatchError) } - menuItems := []*menuItem{ + menuItems := []*popup.MenuItem{ { - displayString: "reset patch", - onPress: gui.handleResetPatch, + DisplayString: "reset patch", + OnPress: gui.handleResetPatch, }, { - displayString: "apply patch", - onPress: func() error { return gui.handleApplyPatch(false) }, + DisplayString: "apply patch", + OnPress: func() error { return gui.handleApplyPatch(false) }, }, { - displayString: "apply patch in reverse", - onPress: func() error { return gui.handleApplyPatch(true) }, + DisplayString: "apply patch in reverse", + OnPress: func() error { return gui.handleApplyPatch(true) }, }, } if gui.Git.Patch.PatchManager.CanRebase && gui.Git.Status.WorkingTreeState() == enums.REBASE_MODE_NONE { - menuItems = append(menuItems, []*menuItem{ + menuItems = append(menuItems, []*popup.MenuItem{ { - displayString: fmt.Sprintf("remove patch from original commit (%s)", gui.Git.Patch.PatchManager.To), - onPress: gui.handleDeletePatchFromCommit, + DisplayString: fmt.Sprintf("remove patch from original commit (%s)", gui.Git.Patch.PatchManager.To), + OnPress: gui.handleDeletePatchFromCommit, }, { - displayString: "move patch out into index", - onPress: gui.handleMovePatchIntoWorkingTree, + DisplayString: "move patch out into index", + OnPress: gui.handleMovePatchIntoWorkingTree, }, { - displayString: "move patch into new commit", - onPress: gui.handlePullPatchIntoNewCommit, + DisplayString: "move patch into new commit", + OnPress: gui.handlePullPatchIntoNewCommit, }, }...) @@ -49,10 +51,10 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error { menuItems = append( menuItems[:1], append( - []*menuItem{ + []*popup.MenuItem{ { - displayString: fmt.Sprintf("move patch to selected commit (%s)", selectedCommit.Sha), - onPress: gui.handleMovePatchToSelectedCommit, + DisplayString: fmt.Sprintf("move patch to selected commit (%s)", selectedCommit.Sha), + OnPress: gui.handleMovePatchToSelectedCommit, }, }, menuItems[1:]..., )..., @@ -61,7 +63,7 @@ func (gui *Gui) handleCreatePatchOptionsMenu() error { } } - return gui.createMenu(gui.Tr.PatchOptionsTitle, menuItems, createMenuOptions{showCancel: true}) + return gui.PopupHandler.Menu(popup.CreateMenuOptions{Title: gui.Tr.PatchOptionsTitle, Items: menuItems}) } func (gui *Gui) getPatchCommitIndex() int { @@ -75,7 +77,7 @@ func (gui *Gui) getPatchCommitIndex() int { func (gui *Gui) validateNormalWorkingTreeState() (bool, error) { if gui.Git.Status.WorkingTreeState() != enums.REBASE_MODE_NONE { - return false, gui.createErrorPanel(gui.Tr.CantPatchWhileRebasingError) + return false, gui.PopupHandler.ErrorMsg(gui.Tr.CantPatchWhileRebasingError) } return true, nil } @@ -96,7 +98,7 @@ func (gui *Gui) handleDeletePatchFromCommit() error { return err } - return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error { + return gui.PopupHandler.WithWaitingStatus(gui.Tr.RebasingStatus, func() error { commitIndex := gui.getPatchCommitIndex() gui.logAction(gui.Tr.Actions.RemovePatchFromCommit) err := gui.Git.Patch.DeletePatchesFromCommit(gui.State.Commits, commitIndex) @@ -113,7 +115,7 @@ func (gui *Gui) handleMovePatchToSelectedCommit() error { return err } - return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error { + return gui.PopupHandler.WithWaitingStatus(gui.Tr.RebasingStatus, func() error { commitIndex := gui.getPatchCommitIndex() gui.logAction(gui.Tr.Actions.MovePatchToSelectedCommit) err := gui.Git.Patch.MovePatchToSelectedCommit(gui.State.Commits, commitIndex, gui.State.Panels.Commits.SelectedLineIdx) @@ -131,7 +133,7 @@ func (gui *Gui) handleMovePatchIntoWorkingTree() error { } pull := func(stash bool) error { - return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error { + return gui.PopupHandler.WithWaitingStatus(gui.Tr.RebasingStatus, func() error { commitIndex := gui.getPatchCommitIndex() gui.logAction(gui.Tr.Actions.MovePatchIntoIndex) err := gui.Git.Patch.MovePatchIntoIndex(gui.State.Commits, commitIndex, stash) @@ -140,10 +142,10 @@ func (gui *Gui) handleMovePatchIntoWorkingTree() error { } if len(gui.trackedFiles()) > 0 { - return gui.ask(askOpts{ - title: gui.Tr.MustStashTitle, - prompt: gui.Tr.MustStashWarning, - handleConfirm: func() error { + return gui.PopupHandler.Ask(popup.AskOpts{ + Title: gui.Tr.MustStashTitle, + Prompt: gui.Tr.MustStashWarning, + HandleConfirm: func() error { return pull(true) }, }) @@ -161,7 +163,7 @@ func (gui *Gui) handlePullPatchIntoNewCommit() error { return err } - return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error { + return gui.PopupHandler.WithWaitingStatus(gui.Tr.RebasingStatus, func() error { commitIndex := gui.getPatchCommitIndex() gui.logAction(gui.Tr.Actions.MovePatchIntoNewCommit) err := gui.Git.Patch.PullPatchIntoNewCommit(gui.State.Commits, commitIndex) @@ -180,9 +182,9 @@ func (gui *Gui) handleApplyPatch(reverse bool) error { } gui.logAction(action) if err := gui.Git.Patch.PatchManager.ApplyPatches(reverse); err != nil { - return gui.surfaceError(err) + return gui.PopupHandler.Error(err) } - return gui.refreshSidePanels(refreshOptions{mode: ASYNC}) + return gui.refreshSidePanels(types.RefreshOptions{Mode: types.ASYNC}) } func (gui *Gui) handleResetPatch() error { -- cgit v1.2.3