Skip to content

Commit f3a5d7d

Browse files
committed
gitk: tag add right click options
In gitk, we can right-click on the icon of the branch, and a directory will pop up to provide us with functions such as "Checkout this branch", "Rename this branch"..., but we found that the right-click tag icon does not have such a function , So I learned how to write the branch icon, and added the following functions "Rename this tag","Remove this tag", "Copy tag name" to right-click the tag icon. This function is temporarily supported work on the branch with <=3 tags. Signed-off-by: ZheNing Hu <[email protected]>
1 parent e636282 commit f3a5d7d

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed

gitk-git/gitk

+147
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,20 @@ proc removehead {id name} {
18741874
unset headids($name)
18751875
}
18761876

1877+
proc removetag {id name} {
1878+
global tagids idtags
1879+
1880+
if {$idtags($id) eq $name} {
1881+
unset idtags($id)
1882+
} else {
1883+
set i [lsearch -exact $idtags($id) $name]
1884+
if {$i >= 0} {
1885+
set idtags($id) [lreplace $idtags($id) $i $i]
1886+
}
1887+
}
1888+
unset tagids($name)
1889+
}
1890+
18771891
proc ttk_toplevel {w args} {
18781892
global use_ttk
18791893
eval [linsert $args 0 ::toplevel $w]
@@ -2077,6 +2091,7 @@ proc makewindow {} {
20772091
global filesepbgcolor filesepfgcolor
20782092
global mergecolors foundbgcolor currentsearchhitbgcolor
20792093
global headctxmenu progresscanv progressitem progresscoords statusw
2094+
global tagctxmenu
20802095
global fprogitem fprogcoord lastprogupdate progupdatepending
20812096
global rprogitem rprogcoord rownumsel numcommits
20822097
global have_tk85 use_ttk NS
@@ -2685,6 +2700,14 @@ proc makewindow {} {
26852700
}
26862701
$headctxmenu configure -tearoff 0
26872702

2703+
set tagctxmenu .tagctxmenu
2704+
makemenu $tagctxmenu {
2705+
{mc "Rename this tag" command mvtag}
2706+
{mc "Remove this tag" command rmtag}
2707+
{mc "Copy tag name" command {clipboard clear; clipboard append $tagmenutag}}
2708+
}
2709+
$tagctxmenu configure -tearoff 0
2710+
26882711
global flist_menu
26892712
set flist_menu .flistctxmenu
26902713
makemenu $flist_menu {
@@ -6581,6 +6604,7 @@ proc drawtags {id x xt y1} {
65816604

65826605
set marks {}
65836606
set ntags 0
6607+
set ntags_copy 0
65846608
set nheads 0
65856609
set singletag 0
65866610
set maxtags 3
@@ -6592,6 +6616,7 @@ proc drawtags {id x xt y1} {
65926616
if {[info exists idtags($id)]} {
65936617
set marks $idtags($id)
65946618
set ntags [llength $marks]
6619+
set ntags_copy $ntags
65956620
if {$ntags > $maxtags ||
65966621
[totalwidth $marks mainfont $extra] > $maxwidth} {
65976622
# show just a single "n tags..." tag
@@ -6678,6 +6703,9 @@ proc drawtags {id x xt y1} {
66786703
-font $font -tags [list tag.$id text]]
66796704
if {$ntags >= 0} {
66806705
$canv bind $t <1> $tagclick
6706+
if {$ntags_copy < $maxtags} {
6707+
$canv bind $t $ctxbut [list tagmenu %X %Y $id $tag_quoted]
6708+
}
66816709
} elseif {$nheads >= 0} {
66826710
$canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
66836711
}
@@ -9531,6 +9559,57 @@ proc mkbranch {} {
95319559
branchdia $top val ui
95329560
}
95339561

9562+
proc mvtag {} {
9563+
global NS
9564+
global tagmenuid tagmenutag
9565+
9566+
set top .tagdialog
9567+
9568+
set val(name) $tagmenutag
9569+
set val(id) $tagmenuid
9570+
set val(command) [list mvtaggo $top $tagmenutag]
9571+
9572+
set ui(title) [mc "Rename tag %s" $tagmenutag]
9573+
set ui(accept) [mc "Rename"]
9574+
9575+
tagdia $top val ui
9576+
}
9577+
9578+
proc tagdia {top valvar uivar} {
9579+
global NS commitinfo
9580+
upvar $valvar val $uivar ui
9581+
9582+
catch {destroy $top}
9583+
ttk_toplevel $top
9584+
make_transient $top .
9585+
${NS}::label $top.title -text $ui(title)
9586+
grid $top.title - -pady 10
9587+
${NS}::label $top.id -text [mc "ID:"]
9588+
${NS}::entry $top.sha1 -width 40
9589+
$top.sha1 insert 0 $val(id)
9590+
$top.sha1 conf -state readonly
9591+
grid $top.id $top.sha1 -sticky w
9592+
${NS}::entry $top.head -width 60
9593+
$top.head insert 0 [lindex $commitinfo($val(id)) 0]
9594+
$top.head conf -state readonly
9595+
grid x $top.head -sticky ew
9596+
grid columnconfigure $top 1 -weight 1
9597+
${NS}::label $top.nlab -text [mc "Name:"]
9598+
${NS}::entry $top.name -width 40
9599+
$top.name insert 0 $val(name)
9600+
grid $top.nlab $top.name -sticky w
9601+
${NS}::frame $top.buts
9602+
${NS}::button $top.buts.go -text $ui(accept) -command $val(command)
9603+
${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
9604+
bind $top <Key-Return> $val(command)
9605+
bind $top <Key-Escape> "catch {destroy $top}"
9606+
grid $top.buts.go $top.buts.can
9607+
grid columnconfigure $top.buts 0 -weight 1 -uniform a
9608+
grid columnconfigure $top.buts 1 -weight 1 -uniform a
9609+
grid $top.buts - -pady 10 -sticky ew
9610+
focus $top.name
9611+
}
9612+
95349613
proc mvbranch {} {
95359614
global NS
95369615
global headmenuid headmenuhead
@@ -9582,6 +9661,43 @@ proc branchdia {top valvar uivar} {
95829661
focus $top.name
95839662
}
95849663

9664+
proc mvtaggo {top prevname} {
9665+
global tagids idtags idheads mainhead mainheadid
9666+
9667+
set name [$top.name get]
9668+
set id [$top.sha1 get]
9669+
if {$name eq $prevname} {
9670+
catch {destroy $top}
9671+
return
9672+
}
9673+
if {$name eq {}} {
9674+
error_popup [mc "Please specify a new name for the tag"] $top
9675+
return
9676+
}
9677+
catch {destroy $top}
9678+
nowbusy renametag
9679+
update
9680+
if {[catch {
9681+
# NOTE: for an annotated tag, the new tag points to the old tag object
9682+
# where the old primary tag name is still recorded inside. Acceptable.
9683+
eval exec "git tag $name $prevname"
9684+
eval exec "git tag -d $prevname"
9685+
} err]} {
9686+
notbusy renametag
9687+
error_popup $err
9688+
} else {
9689+
notbusy renametag
9690+
removetag $id $prevname
9691+
set tagids($name) $id
9692+
lappend idtags($id) $name
9693+
redrawtags $id
9694+
addedtag $id
9695+
dispneartags 0
9696+
run refill_reflist
9697+
}
9698+
9699+
}
9700+
95859701
proc mkbrgo {top} {
95869702
global headids idheads
95879703

@@ -9915,6 +10031,17 @@ proc headmenu {x y id head} {
991510031
tk_popup $headctxmenu $x $y
991610032
}
991710033

10034+
# context menu for a tag
10035+
proc tagmenu {x y id tag} {
10036+
global tagmenuid tagmenutag tagctxmenu mainhead
10037+
10038+
stopfinding
10039+
set tagmenuid $id
10040+
set tagmenutag $tag
10041+
10042+
tk_popup $tagctxmenu $x $y
10043+
}
10044+
991810045
proc cobranch {} {
991910046
global headmenuid headmenuhead headids
992010047
global showlocalchanges
@@ -10019,6 +10146,26 @@ proc rmbranch {} {
1001910146
run refill_reflist
1002010147
}
1002110148

10149+
proc rmtag {} {
10150+
global tagmenuid tagmenutag
10151+
global idtags
10152+
10153+
set tag $tagmenutag
10154+
set id $tagmenuid
10155+
10156+
nowbusy rmtag
10157+
update
10158+
if {[catch {exec git tag -d $tag} err]} {
10159+
notbusy rmtag
10160+
error_popup $err
10161+
return
10162+
}
10163+
removetag $id $tag
10164+
redrawtags $id
10165+
notbusy rmtag
10166+
run refill_reflist
10167+
}
10168+
1002210169
# Display a list of tags and heads
1002310170
proc showrefs {} {
1002410171
global showrefstop bgcolor fgcolor selectbgcolor NS

0 commit comments

Comments
 (0)