Skip to content

Commit b246cdf

Browse files
committed
[RFC] 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. But now I may need a little help: after we successfully deleted or modified the tag,the content show on gitk has not changed, and I am stuck here. Signed-off-by: ZheNing Hu <[email protected]>
1 parent e636282 commit b246cdf

File tree

1 file changed

+149
-0
lines changed

1 file changed

+149
-0
lines changed

gitk-git/gitk

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

1877+
proc movetag {id name} {
1878+
global tagids idtags
1879+
1880+
removetag $tagids($name) $name
1881+
set tagids($name) $id
1882+
lappend idtags($id) $name
1883+
}
1884+
1885+
proc removetag {id name} {
1886+
global tagids idtags
1887+
1888+
if {$idtags($id) eq $name} {
1889+
unset idtags($id)
1890+
} else {
1891+
set i [lsearch -exact $idtags($id) $name]
1892+
if {$i >= 0} {
1893+
set idtags($id) [lreplace $idtags($id) $i $i]
1894+
}
1895+
}
1896+
unset tagids($name)
1897+
}
1898+
18771899
proc ttk_toplevel {w args} {
18781900
global use_ttk
18791901
eval [linsert $args 0 ::toplevel $w]
@@ -2077,6 +2099,7 @@ proc makewindow {} {
20772099
global filesepbgcolor filesepfgcolor
20782100
global mergecolors foundbgcolor currentsearchhitbgcolor
20792101
global headctxmenu progresscanv progressitem progresscoords statusw
2102+
global tagctxmenu
20802103
global fprogitem fprogcoord lastprogupdate progupdatepending
20812104
global rprogitem rprogcoord rownumsel numcommits
20822105
global have_tk85 use_ttk NS
@@ -2685,6 +2708,14 @@ proc makewindow {} {
26852708
}
26862709
$headctxmenu configure -tearoff 0
26872710

2711+
set tagctxmenu .tagctxmenu
2712+
makemenu $tagctxmenu {
2713+
{mc "Rename this tag" command mvtag}
2714+
{mc "Remove this tag" command rmtag}
2715+
{mc "Copy tag name" command {clipboard clear; clipboard append $tagmenutag}}
2716+
}
2717+
$tagctxmenu configure -tearoff 0
2718+
26882719
global flist_menu
26892720
set flist_menu .flistctxmenu
26902721
makemenu $flist_menu {
@@ -6581,6 +6612,7 @@ proc drawtags {id x xt y1} {
65816612

65826613
set marks {}
65836614
set ntags 0
6615+
set ntags_copy 0
65846616
set nheads 0
65856617
set singletag 0
65866618
set maxtags 3
@@ -6592,6 +6624,7 @@ proc drawtags {id x xt y1} {
65926624
if {[info exists idtags($id)]} {
65936625
set marks $idtags($id)
65946626
set ntags [llength $marks]
6627+
set ntags_copy $ntags
65956628
if {$ntags > $maxtags ||
65966629
[totalwidth $marks mainfont $extra] > $maxwidth} {
65976630
# show just a single "n tags..." tag
@@ -6678,6 +6711,9 @@ proc drawtags {id x xt y1} {
66786711
-font $font -tags [list tag.$id text]]
66796712
if {$ntags >= 0} {
66806713
$canv bind $t <1> $tagclick
6714+
if {$ntags_copy < $maxtags} {
6715+
$canv bind $t $ctxbut [list tagmenu %X %Y $id $tag_quoted]
6716+
}
66816717
} elseif {$nheads >= 0} {
66826718
$canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
66836719
}
@@ -9531,6 +9567,57 @@ proc mkbranch {} {
95319567
branchdia $top val ui
95329568
}
95339569

9570+
proc mvtag {} {
9571+
global NS
9572+
global tagmenuid tagmenutag
9573+
9574+
set top .tagdialog
9575+
9576+
set val(name) $tagmenutag
9577+
set val(id) $tagmenuid
9578+
set val(command) [list mvtago $top $tagmenutag]
9579+
9580+
set ui(title) [mc "Rename tag %s" $tagmenutag]
9581+
set ui(accept) [mc "Rename"]
9582+
9583+
tagdia $top val ui
9584+
}
9585+
9586+
proc tagdia {top valvar uivar} {
9587+
global NS commitinfo
9588+
upvar $valvar val $uivar ui
9589+
9590+
catch {destroy $top}
9591+
ttk_toplevel $top
9592+
make_transient $top .
9593+
${NS}::label $top.title -text $ui(title)
9594+
grid $top.title - -pady 10
9595+
${NS}::label $top.id -text [mc "ID:"]
9596+
${NS}::entry $top.sha1 -width 40
9597+
$top.sha1 insert 0 $val(id)
9598+
$top.sha1 conf -state readonly
9599+
grid $top.id $top.sha1 -sticky w
9600+
${NS}::entry $top.head -width 60
9601+
$top.head insert 0 [lindex $commitinfo($val(id)) 0]
9602+
$top.head conf -state readonly
9603+
grid x $top.head -sticky ew
9604+
grid columnconfigure $top 1 -weight 1
9605+
${NS}::label $top.nlab -text [mc "Name:"]
9606+
${NS}::entry $top.name -width 40
9607+
$top.name insert 0 $val(name)
9608+
grid $top.nlab $top.name -sticky w
9609+
${NS}::frame $top.buts
9610+
${NS}::button $top.buts.go -text $ui(accept) -command $val(command)
9611+
${NS}::button $top.buts.can -text [mc "Cancel"] -command "catch {destroy $top}"
9612+
bind $top <Key-Return> $val(command)
9613+
bind $top <Key-Escape> "catch {destroy $top}"
9614+
grid $top.buts.go $top.buts.can
9615+
grid columnconfigure $top.buts 0 -weight 1 -uniform a
9616+
grid columnconfigure $top.buts 1 -weight 1 -uniform a
9617+
grid $top.buts - -pady 10 -sticky ew
9618+
focus $top.name
9619+
}
9620+
95349621
proc mvbranch {} {
95359622
global NS
95369623
global headmenuid headmenuhead
@@ -9582,6 +9669,38 @@ proc branchdia {top valvar uivar} {
95829669
focus $top.name
95839670
}
95849671

9672+
proc mvtago {top prevname} {
9673+
global tagids idheads mainhead mainheadid
9674+
9675+
set name [$top.name get]
9676+
set id [$top.sha1 get]
9677+
if {$name eq $prevname} {
9678+
catch {destroy $top}
9679+
return
9680+
}
9681+
if {$name eq {}} {
9682+
error_popup [mc "Please specify a new name for the tag"] $top
9683+
return
9684+
}
9685+
catch {destroy $top}
9686+
nowbusy renametag
9687+
update
9688+
if {[catch {
9689+
eval exec "git tag $name $prevname"
9690+
eval exec "git tag -d $prevname"
9691+
} err]} {
9692+
notbusy renametag
9693+
error_popup $err
9694+
} else {
9695+
notbusy renametag
9696+
removetag $id $prevname
9697+
set tagids($name) $id
9698+
lappend idtags($id) $name
9699+
run refill_reflist
9700+
}
9701+
9702+
}
9703+
95859704
proc mkbrgo {top} {
95869705
global headids idheads
95879706

@@ -9915,6 +10034,17 @@ proc headmenu {x y id head} {
991510034
tk_popup $headctxmenu $x $y
991610035
}
991710036

10037+
# context menu for a tag
10038+
proc tagmenu {x y id tag} {
10039+
global tagmenuid tagmenutag tagctxmenu mainhead
10040+
10041+
stopfinding
10042+
set tagmenuid $id
10043+
set tagmenutag $tag
10044+
10045+
tk_popup $tagctxmenu $x $y
10046+
}
10047+
991810048
proc cobranch {} {
991910049
global headmenuid headmenuhead headids
992010050
global showlocalchanges
@@ -10019,6 +10149,25 @@ proc rmbranch {} {
1001910149
run refill_reflist
1002010150
}
1002110151

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

0 commit comments

Comments
 (0)