From 75aed98c3599afcb5791ec4a37319fe04db56736 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 5 Sep 2023 21:56:20 +0200 Subject: [PATCH] Use DisabledReason when deleting branches is not possible Two cases: trying to delete the currently checked-out branch, or deleting the upstream of a branch that doesn't have one. --- pkg/gui/controllers/branches_controller.go | 30 ++++++++-------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index 1dc1f77e8..e60e5c410 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -468,7 +468,6 @@ func (self *BranchesController) forceDelete(branch *models.Branch) error { } func (self *BranchesController) delete(branch *models.Branch) error { - menuItems := []*types.MenuItem{} checkedOutBranch := self.c.Helpers().Refs.GetCheckedOutRef() localDeleteItem := &types.MenuItem{ @@ -479,25 +478,18 @@ func (self *BranchesController) delete(branch *models.Branch) error { }, } if checkedOutBranch.Name == branch.Name { - localDeleteItem = &types.MenuItem{ - Label: self.c.Tr.DeleteLocalBranch, - Key: 'c', - Tooltip: self.c.Tr.CantDeleteCheckOutBranch, - OnPress: func() error { - return self.c.ErrorMsg(self.c.Tr.CantDeleteCheckOutBranch) - }, - } + localDeleteItem.DisabledReason = self.c.Tr.CantDeleteCheckOutBranch } - menuItems = append(menuItems, localDeleteItem) - if branch.IsTrackingRemote() && !branch.UpstreamGone { - menuItems = append(menuItems, &types.MenuItem{ - Label: self.c.Tr.DeleteRemoteBranch, - Key: 'r', - OnPress: func() error { - return self.remoteDelete(branch) - }, - }) + remoteDeleteItem := &types.MenuItem{ + Label: self.c.Tr.DeleteRemoteBranch, + Key: 'r', + OnPress: func() error { + return self.remoteDelete(branch) + }, + } + if !branch.IsTrackingRemote() || branch.UpstreamGone { + remoteDeleteItem.DisabledReason = self.c.Tr.UpstreamNotSetError } menuTitle := utils.ResolvePlaceholderString( @@ -509,7 +501,7 @@ func (self *BranchesController) delete(branch *models.Branch) error { return self.c.Menu(types.CreateMenuOptions{ Title: menuTitle, - Items: menuItems, + Items: []*types.MenuItem{localDeleteItem, remoteDeleteItem}, }) }