summaryrefslogtreecommitdiffstats
path: root/pkg/gui/tags_panel.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-01-16 14:46:53 +1100
committerJesse Duffield <jessedduffield@gmail.com>2022-03-17 19:13:40 +1100
commit1dd7307fde033dae5fececac15810a99e26c3d91 (patch)
tree4e851c9e3229a6fe3b4191f6311d05d7a9142960 /pkg/gui/tags_panel.go
parenta90b6efded49abcfa2516db794d7875b0396f558 (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/tags_panel.go')
-rw-r--r--pkg/gui/tags_panel.go106
1 files changed, 13 insertions, 93 deletions
diff --git a/pkg/gui/tags_panel.go b/pkg/gui/tags_panel.go
index 9f516a006..9e00dd122 100644
--- a/pkg/gui/tags_panel.go
+++ b/pkg/gui/tags_panel.go
@@ -2,36 +2,28 @@ package gui
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
- "github.com/jesseduffield/lazygit/pkg/gui/popup"
- "github.com/jesseduffield/lazygit/pkg/gui/types"
- "github.com/jesseduffield/lazygit/pkg/utils"
)
-func (gui *Gui) getSelectedTag() *models.Tag {
- selectedLine := gui.State.Panels.Tags.SelectedLineIdx
- if selectedLine == -1 || len(gui.State.Tags) == 0 {
+func (self *Gui) getSelectedTag() *models.Tag {
+ selectedLine := self.State.Panels.Tags.SelectedLineIdx
+ if selectedLine == -1 || len(self.State.Tags) == 0 {
return nil
}
- return gui.State.Tags[selectedLine]
+ return self.State.Tags[selectedLine]
}
-func (gui *Gui) handleCreateTag() error {
- // leaving commit SHA blank so that we're just creating the tag for the current commit
- return gui.createTagMenu("")
-}
-
-func (gui *Gui) tagsRenderToMain() error {
+func (self *Gui) tagsRenderToMain() error {
var task updateTask
- tag := gui.getSelectedTag()
+ tag := self.getSelectedTag()
if tag == nil {
task = NewRenderStringTask("No tags")
} else {
- cmdObj := gui.Git.Branch.GetGraphCmdObj(tag.Name)
+ cmdObj := self.git.Branch.GetGraphCmdObj(tag.Name)
task = NewRunCommandTask(cmdObj.GetCmd())
}
- return gui.refreshMainViews(refreshMainOpts{
+ return self.refreshMainViews(refreshMainOpts{
main: &viewUpdateOpts{
title: "Tag",
task: task,
@@ -40,85 +32,13 @@ func (gui *Gui) tagsRenderToMain() error {
}
// this is a controller: it can't access tags directly. Or can it? It should be able to get but not set. But that's exactly what I'm doing here, setting it. but through a mutator which encapsulates the event.
-func (gui *Gui) refreshTags() error {
- tags, err := gui.Git.Loaders.Tags.GetTags()
+func (self *Gui) refreshTags() error {
+ tags, err := self.git.Loaders.Tags.GetTags()
if err != nil {
- return gui.PopupHandler.Error(err)
+ return self.c.Error(err)
}
- gui.State.Tags = tags
-
- return gui.postRefreshUpdate(gui.State.Contexts.Tags)
-}
-
-func (gui *Gui) withSelectedTag(f func(tag *models.Tag) error) func() error {
- return func() error {
- tag := gui.getSelectedTag()
- if tag == nil {
- return nil
- }
-
- return f(tag)
- }
-}
-
-// tag-specific handlers
-
-func (gui *Gui) handleCheckoutTag(tag *models.Tag) error {
- gui.logAction(gui.Tr.Actions.CheckoutTag)
- if err := gui.handleCheckoutRef(tag.Name, handleCheckoutRefOptions{}); err != nil {
- return err
- }
- return gui.pushContext(gui.State.Contexts.Branches)
-}
-
-func (gui *Gui) handleDeleteTag(tag *models.Tag) error {
- prompt := utils.ResolvePlaceholderString(
- gui.Tr.DeleteTagPrompt,
- map[string]string{
- "tagName": tag.Name,
- },
- )
-
- return gui.PopupHandler.Ask(popup.AskOpts{
- Title: gui.Tr.DeleteTagTitle,
- Prompt: prompt,
- HandleConfirm: func() error {
- gui.logAction(gui.Tr.Actions.DeleteTag)
- if err := gui.Git.Tag.Delete(tag.Name); err != nil {
- return gui.PopupHandler.Error(err)
- }
- return gui.refreshSidePanels(types.RefreshOptions{Mode: types.ASYNC, Scope: []types.RefreshableView{types.COMMITS, types.TAGS}})
- },
- })
-}
-
-func (gui *Gui) handlePushTag(tag *models.Tag) error {
- title := utils.ResolvePlaceholderString(
- gui.Tr.PushTagTitle,
- map[string]string{
- "tagName": tag.Name,
- },
- )
-
- return gui.PopupHandler.Prompt(popup.PromptOpts{
- Title: title,
- InitialContent: "origin",
- FindSuggestionsFunc: gui.getRemoteSuggestionsFunc(),
- HandleConfirm: func(response string) error {
- return gui.PopupHandler.WithWaitingStatus(gui.Tr.PushingTagStatus, func() error {
- gui.logAction(gui.Tr.Actions.PushTag)
- err := gui.Git.Tag.Push(response, tag.Name)
- if err != nil {
- _ = gui.PopupHandler.Error(err)
- }
-
- return nil
- })
- },
- })
-}
+ self.State.Tags = tags
-func (gui *Gui) handleCreateResetToTagMenu(tag *models.Tag) error {
- return gui.createResetMenu(tag.Name)
+ return self.postRefreshUpdate(self.State.Contexts.Tags)
}