From 826ff3e13bfd1e15503441a08facf58c79d181d9 Mon Sep 17 00:00:00 2001 From: Bert Wesarg Date: Wed, 25 May 2011 18:52:35 +0200 Subject: [PATCH] git-gui: have a context menu in the file lists which have also entries for guitools which needs a file Signed-off-by: Bert Wesarg --- git-gui.sh | 36 +++++++++++++++++++++-- lib/tools.tcl | 93 +++++++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 109 insertions(+), 20 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 3df7703..64e75cf 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -2519,6 +2519,22 @@ proc force_first_diff {after} { } } +proc popup_files_ctxm {m w x y X Y} { + global file_lists popup_path + + set ::cursorX $x + set ::cursorY $y + + set pos [split [$w index @$x,$y] .] + set lno [lindex $pos 0] + set col [lindex $pos 1] + set popup_path [lindex $file_lists($w) [expr {$lno - 1}]] + if {$popup_path eq {}} { + return + } + tk_popup $m $X $Y +} + proc toggle_or_diff {w x y} { global file_states file_lists current_diff_path ui_index ui_workdir global last_clicked selected_paths @@ -2962,9 +2978,8 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} { $tools_menubar add separator $tools_menubar add command -label [mc "Add..."] -command tools_add::dialog $tools_menubar add command -label [mc "Remove..."] -command tools_remove::dialog - set tools_tailcnt 3 if {[array names repo_config guitool.*.cmd] ne {}} { - tools_populate_all + tools_populate_all 3 } } @@ -3249,6 +3264,16 @@ foreach i [list $ui_index $ui_workdir] { } unset i +set files_ctxm .vpane.files.ctxm +menu $files_ctxm -tearoff 0 +$files_ctxm add separator +$files_ctxm add command -label [mc "Stage All Changed"] -command do_add_all +$files_ctxm add command -label [mc "Stage Selected"] -command do_add_selection +if {[array names repo_config guitool.*.cmd] ne {}} { + files_tools_populate_all 3 popup_path +} + + # -- Diff and Commit Area # if {$have_tk85} { @@ -3891,6 +3916,13 @@ foreach i [list $ui_index $ui_workdir] { bind $i <$M1B-Button-1> "add_one_to_selection $i %x %y; break" bind $i "add_range_to_selection $i %x %y; break" } +if {[$files_ctxm index end] == 1} { + # remove the separator, when we don't have user specified file tools + $files_ctxm delete 0 +} +bind_button3 $ui_index "popup_files_ctxm $files_ctxm $ui_index %x %y %X %Y; break" +bind_button3 $ui_workdir "popup_files_ctxm $files_ctxm $ui_workdir %x %y %X %Y; break" + unset i set file_lists($ui_index) [list] diff --git a/lib/tools.tcl b/lib/tools.tcl index 6ec9411..4cbbc1a 100644 --- a/lib/tools.tcl +++ b/lib/tools.tcl @@ -10,12 +10,11 @@ proc tools_list {} { return [lsort $names] } -proc tools_populate_all {} { +proc tools_populate_all {tailcnt} { global tools_menubar tools_menutbl - global tools_tailcnt set mbar_end [$tools_menubar index end] - set mbar_base [expr {$mbar_end - $tools_tailcnt}] + set mbar_base [expr {$mbar_end - $tailcnt}] if {$mbar_base >= 0} { $tools_menubar delete 0 $mbar_base } @@ -23,21 +22,20 @@ proc tools_populate_all {} { array unset tools_menutbl foreach fullname [tools_list] { - tools_populate_one $fullname + tools_populate_one $tailcnt $fullname } } -proc tools_create_item {parent args} { - global tools_menubar tools_tailcnt - if {$parent eq $tools_menubar} { - set pos [expr {[$parent index end]-$tools_tailcnt+1}] +proc tools_create_item {menu tailcnt parent args} { + if {$parent eq $menu} { + set pos [expr {[$parent index end]-$tailcnt+1}] eval [list $parent insert $pos] $args } else { eval [list $parent add] $args } } -proc tools_populate_one {fullname} { +proc tools_populate_one {tailcnt fullname} { global tools_menubar tools_menutbl tools_id if {![info exists tools_id]} { @@ -52,8 +50,10 @@ proc tools_populate_one {fullname} { set parent $tools_menutbl($subname) } else { set subid $parent.t$tools_id - tools_create_item $parent cascade \ - -label [lindex $names $i] -menu $subid + tools_create_item $tools_menubar $tailcnt \ + $parent cascade \ + -label [lindex $names $i] \ + -menu $subid menu $subid set tools_menutbl($subname) $subid set parent $subid @@ -61,17 +61,74 @@ proc tools_populate_one {fullname} { } } - tools_create_item $parent command \ - -label [lindex $names end] \ - -command [list tools_exec $fullname] + tools_create_item $tools_menubar $tailcnt \ + $parent command \ + -label [lindex $names end] \ + -command [list tools_exec $fullname] } -proc tools_exec {fullname} { +proc files_tools_populate_all {tailcnt {path_var {}}} { + global files_ctxm files_ctxmtbl + + set ctxm_end [$files_ctxm index end] + set ctxm_base [expr {$ctxm_end - $tailcnt}] + if {$ctxm_base >= 0} { + $files_ctxm delete 0 $ctxm_base + } + + array unset files_ctxmtbl + + foreach fullname [tools_list] { + if {[is_config_true "guitool.$fullname.needsfile"]} { + files_tools_populate_one $tailcnt $fullname $path_var + } + } +} + +proc files_tools_populate_one {tailcnt fullname {path_var {}}} { + global files_ctxm files_ctxmtbl files_tools_id + + if {![info exists files_tools_id]} { + set files_tools_id 0 + } + + set names [split $fullname '/'] + set parent $files_ctxm + for {set i 0} {$i < [llength $names]-1} {incr i} { + set subname [join [lrange $names 0 $i] '/'] + if {[info exists files_ctxmtbl($subname)]} { + set parent $files_ctxmtbl($subname) + } else { + set subid $parent.t$files_tools_id + tools_create_item $files_ctxm $tailcnt \ + $parent cascade \ + -label [lindex $names $i] \ + -menu $subid + menu $subid -tearoff 0 + set files_ctxmtbl($subname) $subid + set parent $subid + incr files_tools_id + } + } + + tools_create_item $files_ctxm $tailcnt \ + $parent command \ + -label [lindex $names end] \ + -command [list tools_exec $fullname $path_var] +} + +proc tools_exec {fullname {path_var {}}} { global repo_config env current_diff_path global current_branch is_detached + if {$path_var ne {}} { + upvar #0 $path_var path + } else { + set path $current_diff_path + } + if {[is_config_true "guitool.$fullname.needsfile"]} { - if {$current_diff_path eq {}} { + if {$path eq {}} { error_popup [mc "Running %s requires a selected file." $fullname] return } @@ -88,7 +145,7 @@ proc tools_exec {fullname} { } } elseif {[is_config_true "guitool.$fullname.confirm"]} { if {[is_config_true "guitool.$fullname.needsfile"]} { - if {[ask_popup [mc "Are you sure you want to run %1\$s on file \"%2\$s\"?" $fullname $current_diff_path]] ne {yes}} { + if {[ask_popup [mc "Are you sure you want to run %1\$s on file \"%2\$s\"?" $fullname $path]] ne {yes}} { return } } else { @@ -99,7 +156,7 @@ proc tools_exec {fullname} { } set env(GIT_GUITOOL) $fullname - set env(FILENAME) $current_diff_path + set env(FILENAME) $path if {$is_detached} { set env(CUR_BRANCH) "" } else { -- 2.11.4.GIT