Skip to content

Commit c8b0dfa

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 temporarily only supports those labels independently displayed tag(s), and cannot work on label aggregated display "tag..." or "n tags...". Signed-off-by: ZheNing Hu <[email protected]>
1 parent e636282 commit c8b0dfa

File tree

1 file changed

+161
-3
lines changed

1 file changed

+161
-3
lines changed

gitk-git/gitk

+161-3
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
@@ -2679,12 +2694,20 @@ proc makewindow {} {
26792694
set headctxmenu .headctxmenu
26802695
makemenu $headctxmenu {
26812696
{mc "Check out this branch" command cobranch}
2682-
{mc "Rename this branch" command mvbranch}
2697+
{mc "Rename this branch..." command mvbranch}
26832698
{mc "Remove this branch" command rmbranch}
26842699
{mc "Copy branch name" command {clipboard clear; clipboard append $headmenuhead}}
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,8 +6616,9 @@ proc drawtags {id x xt y1} {
65926616
if {[info exists idtags($id)]} {
65936617
set marks $idtags($id)
65946618
set ntags [llength $marks]
6595-
if {$ntags > $maxtags ||
6596-
[totalwidth $marks mainfont $extra] > $maxwidth} {
6619+
set ntags_copy $ntags
6620+
set out_of_bounds [expr {[totalwidth $marks mainfont $extra] > $maxwidth}]
6621+
if {$ntags > $maxtags || $out_of_bounds} {
65976622
# show just a single "n tags..." tag
65986623
set singletag 1
65996624
if {$ntags == 1} {
@@ -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 && !$out_of_bounds} {
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,44 @@ 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+
removedtag $id $tag
9692+
set tagids($name) $id
9693+
lappend idtags($id) $name
9694+
addedtag $id
9695+
redrawtags $id
9696+
dispneartags 0
9697+
run refill_reflist
9698+
}
9699+
9700+
}
9701+
95859702
proc mkbrgo {top} {
95869703
global headids idheads
95879704

@@ -9915,6 +10032,17 @@ proc headmenu {x y id head} {
991510032
tk_popup $headctxmenu $x $y
991610033
}
991710034

10035+
# context menu for a tag
10036+
proc tagmenu {x y id tag} {
10037+
global tagmenuid tagmenutag tagctxmenu mainhead
10038+
10039+
stopfinding
10040+
set tagmenuid $id
10041+
set tagmenutag $tag
10042+
10043+
tk_popup $tagctxmenu $x $y
10044+
}
10045+
991810046
proc cobranch {} {
991910047
global headmenuid headmenuhead headids
992010048
global showlocalchanges
@@ -10019,6 +10147,28 @@ proc rmbranch {} {
1001910147
run refill_reflist
1002010148
}
1002110149

10150+
proc rmtag {} {
10151+
global tagmenuid tagmenutag
10152+
global idtags
10153+
10154+
set tag $tagmenutag
10155+
set id $tagmenuid
10156+
if {![confirm_popup [mc "Really delete tag %s?" $tag]]} return
10157+
nowbusy rmtag
10158+
update
10159+
if {[catch {exec git tag -d $tag} err]} {
10160+
notbusy rmtag
10161+
error_popup $err
10162+
return
10163+
}
10164+
removetag $id $tag
10165+
removedtag $id $tag
10166+
redrawtags $id
10167+
notbusy rmtag
10168+
dispneartags 0
10169+
run refill_reflist
10170+
}
10171+
1002210172
# Display a list of tags and heads
1002310173
proc showrefs {} {
1002410174
global showrefstop bgcolor fgcolor selectbgcolor NS
@@ -11228,6 +11378,14 @@ proc addedtag {id} {
1122811378
unset -nocomplain cached_atags
1122911379
}
1123011380

11381+
proc removedtag {id tag} {
11382+
global cached_dtags cached_atags cached_tagcontent
11383+
11384+
unset -nocomplain cached_tagcontent
11385+
unset -nocomplain cached_dtags
11386+
unset -nocomplain cached_atags
11387+
}
11388+
1123111389
proc addedhead {hid head} {
1123211390
global arcnos arcout cached_dheads
1123311391

0 commit comments

Comments
 (0)