[PATCH] add ctx menu for tags, impl "remove tag" and "copy tag name"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Ulrich Hornung <hornunguli@xxxxxx>

Signed-off-by: Ulrich Hornung <hornunguli@xxxxxx>
---
    gitk: add ctx menu for tags, impl "remove tag" and "copy tag name"
    
    Hello,
    
    I'm currently using git gui and gitk quite strongly. It happens to me
    once in a while that I accidentially create a tag instead of a new
    branch when using the GUI of gitk for this. Sadly, in this situation I
    needed to go to the console to remove this tag again, because the latest
    version of gitk doesn't have a "remove tag" button.
    
    Lukily I was able to implement that button (and the copy name button) by
    myself. I would be happy if you could integrate the new feature into the
    official sources.
    
    Bildschirmfoto vom 2024-01-01 17-26-07
    [https://github.com/gitgitgadget/git/assets/252806/079c28dd-b4a0-486c-ad1e-27f7f2fde814]
    
    Thanks.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1629%2Fcre4ture%2Ffeature%2Ftag_ctx_menu_remove_tag-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1629/cre4ture/feature/tag_ctx_menu_remove_tag-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1629

 gitk-git/gitk | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 66 insertions(+), 1 deletion(-)

diff --git a/gitk-git/gitk b/gitk-git/gitk
index 7a087f123d7..7a70e1fba31 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -1894,6 +1894,21 @@ proc removehead {id name} {
     unset headids($name)
 }
 
+# update things when a tag has been removed
+proc removetag {id name} {
+    global tagids idtags
+
+    if {$idtags($id) eq $name} {
+        unset idtags($id)
+    } else {
+        set i [lsearch -exact $idtags($id) $name]
+        if {$i >= 0} {
+            set idtags($id) [lreplace $idtags($id) $i $i]
+        }
+    }
+    unset tagids($name)
+}
+
 proc ttk_toplevel {w args} {
     global use_ttk
     eval [linsert $args 0 ::toplevel $w]
@@ -2096,7 +2111,7 @@ proc makewindow {} {
     global uifgcolor uifgdisabledcolor
     global filesepbgcolor filesepfgcolor
     global mergecolors foundbgcolor currentsearchhitbgcolor
-    global headctxmenu progresscanv progressitem progresscoords statusw
+    global headctxmenu tagctxmenu progresscanv progressitem progresscoords statusw
     global fprogitem fprogcoord lastprogupdate progupdatepending
     global rprogitem rprogcoord rownumsel numcommits
     global have_tk85 use_ttk NS
@@ -2705,6 +2720,13 @@ proc makewindow {} {
     }
     $headctxmenu configure -tearoff 0
 
+    set tagctxmenu .tagctxmenu
+    makemenu $tagctxmenu {
+        {mc "Remove this tag" command rmtag}
+        {mc "Copy tag name" command {clipboard clear; clipboard append $tagmenutag}}
+    }
+    $tagctxmenu configure -tearoff 0
+
     global flist_menu
     set flist_menu .flistctxmenu
     makemenu $flist_menu {
@@ -6701,6 +6723,7 @@ proc drawtags {id x xt y1} {
                    -font $font -tags [list tag.$id text]]
         if {$ntags >= 0} {
             $canv bind $t <1> $tagclick
+            $canv bind $t $ctxbut [list tagmenu %X %Y $id $tag_quoted]
         } elseif {$nheads >= 0} {
             $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
         }
@@ -9938,6 +9961,20 @@ proc headmenu {x y id head} {
     tk_popup $headctxmenu $x $y
 }
 
+# context menu for a tag
+proc tagmenu {x y id head} {
+    global tagmenuid tagmenutag tagctxmenu
+
+    stopfinding
+    set tagmenuid $id
+    set tagmenutag $head
+    array set state {0 normal 1 normal}
+    foreach i {0 1} {
+        $tagctxmenu entryconfigure $i -state $state($i)
+    }
+    tk_popup $tagctxmenu $x $y
+}
+
 proc cobranch {} {
     global headmenuid headmenuhead headids
     global showlocalchanges
@@ -10042,6 +10079,27 @@ proc rmbranch {} {
     run refill_reflist
 }
 
+proc rmtag {} {
+    global tagmenuid tagmenutag
+
+    set tag $tagmenutag
+    set id $tagmenuid
+
+    nowbusy rmtag
+    update
+    if {[catch {exec git tag -d $tag} err]} {
+        notbusy rmtag
+        error_popup $err
+        return
+    }
+    removetag $id $tag
+    removedtag $id $tag
+    redrawtags $id
+    notbusy rmtag
+    dispneartags 0
+    run refill_reflist
+}
+
 # Display a list of tags and heads
 proc showrefs {} {
     global showrefstop bgcolor fgcolor selectbgcolor NS
@@ -11273,6 +11331,13 @@ proc removedhead {hid head} {
     unset -nocomplain cached_dheads
 }
 
+proc removedtag {hid head} {
+    global cached_dtags cached_atags
+
+    unset -nocomplain cached_dtags
+    unset -nocomplain cached_atags
+}
+
 proc movedhead {hid head} {
     global arcnos arcout cached_dheads
 

base-commit: a26002b62827b89a19b1084bd75d9371d565d03c
-- 
gitgitgadget




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux