Re: [PATCH 3/6] Add a tree view to the local branches, remote branches and tags, where / is treated as a directory seperator.
On Thu, Dec 15, 2016 at 09:58:44PM +1030, Pierre Dumuid wrote: > Signed-off-by: Pierre Dumuid> --- > gitk | 117 > +++ > 1 file changed, 117 insertions(+) Nice idea in general... a few comments below. Also, please don't put the entire commit message in the subject line. :) > diff --git a/gitk b/gitk > index 36cba49..a894f1d 100755 > --- a/gitk > +++ b/gitk > @@ -2089,6 +2089,10 @@ proc makewindow {} { > {mc "Reread re" command rereadrefs} > {mc " references" command showrefs -accelerator F2} > {xx "" separator} > + {mc "List Local Branches" command {show_tree_of_references_dialog > "localBranches"} -accelerator F6} > + {mc "List Remote Branches" command {show_tree_of_references_dialog > "remoteBranches"} -accelerator F7} > + {mc "List Tags"command {show_tree_of_references_dialog > "tags"} -accelerator F8} > + {xx "" separator} > {mc "Start git " command {exec git gui &}} > {xx "" separator} > {mc "" command doquit -accelerator Meta1-Q} > @@ -2601,6 +2605,9 @@ proc makewindow {} { > bind . updatecommits > bindmodfunctionkey Shift 5 reloadcommits > bind . showrefs > +bind . {show_tree_of_references_dialog "localBranches"} > +bind . {show_tree_of_references_dialog "remoteBranches"} > +bind . {show_tree_of_references_dialog "tags"} > bindmodfunctionkey Shift 4 {newview 0} > bind . edit_or_newview > bind . <$M1B-q> doquit > @@ -10146,6 +10153,116 @@ proc rmbranch {} { > run refill_reflist > } > > +# Display a tree view of local branches, remote branches, and tags according > to view_type. > +# > +# @param string view_type > +#Must be one of "localBranches", "remoteBranches", or "tags". > +# > +proc show_tree_of_references_dialog {view_type} { > +global NS > +global treefilelist > +global headids tagids > + > +switch -- $view_type { > + "localBranches" { > + set dialogName "Local Branches" > + set top .show_tree_of_local_branches > + set listOfReferences [lsort [array names headids -regexp > {^(?!remotes/)} ]] > + set truncateFrom 0 > + } > + "remoteBranches" { > + set dialogName "Remote Branches" > + set top .show_tree_of_remote_branches > + set listOfReferences [lsort [array names headids -regexp > {^remotes/} ]] > + set truncateFrom 8 > + } > + "tags" { > + set dialogName "Tags" > + set top .show_tree_of_tags > + set listOfReferences [lsort [array names tagids]] > + set truncateFrom 0 > + } > +} > + > +if {[winfo exists $top]} { > + raise $top > + return > +} > + > +ttk_toplevel $top > +wm title $top [mc "$dialogName: %s" [file tail [pwd]]] > +wm geometry $top "600x900" Do you really need to do this? A fixed size like this is inevitably going to be too big for some users and too small for others. > + > +make_transient $top . > + > +## See http://www.tkdocs.com/tutorial/tree.html > +ttk::treeview $top.referenceList -xscrollcommand > "$top.horizontalScrollBar set" -yscrollcommand "$top.verticalScrollBar set" We still have the option for people to run without ttk, in case someone is still using an old Tcl/Tk version or just doesn't like the ttk widgets. However, there isn't an equivalent of ttk::treeview in the older Tk widget set. It would be OK to omit the new menu entries or to disable them if $use_ttk is false, but I don't want to have menu entries that will always cause gitk to blow up when $use_ttk is false. We possibly should consider converting the file list view to use a ttk::treeview when $use_ttk is true. Paul.
[PATCH 3/6] Add a tree view to the local branches, remote branches and tags, where / is treated as a directory seperator.
Signed-off-by: Pierre Dumuid--- gitk | 117 +++ 1 file changed, 117 insertions(+) diff --git a/gitk b/gitk index 36cba49..a894f1d 100755 --- a/gitk +++ b/gitk @@ -2089,6 +2089,10 @@ proc makewindow {} { {mc "Reread re" command rereadrefs} {mc " references" command showrefs -accelerator F2} {xx "" separator} + {mc "List Local Branches" command {show_tree_of_references_dialog "localBranches"} -accelerator F6} + {mc "List Remote Branches" command {show_tree_of_references_dialog "remoteBranches"} -accelerator F7} + {mc "List Tags"command {show_tree_of_references_dialog "tags"} -accelerator F8} + {xx "" separator} {mc "Start git " command {exec git gui &}} {xx "" separator} {mc "" command doquit -accelerator Meta1-Q} @@ -2601,6 +2605,9 @@ proc makewindow {} { bind . updatecommits bindmodfunctionkey Shift 5 reloadcommits bind . showrefs +bind . {show_tree_of_references_dialog "localBranches"} +bind . {show_tree_of_references_dialog "remoteBranches"} +bind . {show_tree_of_references_dialog "tags"} bindmodfunctionkey Shift 4 {newview 0} bind . edit_or_newview bind . <$M1B-q> doquit @@ -10146,6 +10153,116 @@ proc rmbranch {} { run refill_reflist } +# Display a tree view of local branches, remote branches, and tags according to view_type. +# +# @param string view_type +#Must be one of "localBranches", "remoteBranches", or "tags". +# +proc show_tree_of_references_dialog {view_type} { +global NS +global treefilelist +global headids tagids + +switch -- $view_type { + "localBranches" { + set dialogName "Local Branches" + set top .show_tree_of_local_branches + set listOfReferences [lsort [array names headids -regexp {^(?!remotes/)} ]] + set truncateFrom 0 + } + "remoteBranches" { + set dialogName "Remote Branches" + set top .show_tree_of_remote_branches + set listOfReferences [lsort [array names headids -regexp {^remotes/} ]] + set truncateFrom 8 + } + "tags" { + set dialogName "Tags" + set top .show_tree_of_tags + set listOfReferences [lsort [array names tagids]] + set truncateFrom 0 + } +} + +if {[winfo exists $top]} { + raise $top + return +} + +ttk_toplevel $top +wm title $top [mc "$dialogName: %s" [file tail [pwd]]] +wm geometry $top "600x900" + +make_transient $top . + +## See http://www.tkdocs.com/tutorial/tree.html +ttk::treeview $top.referenceList -xscrollcommand "$top.horizontalScrollBar set" -yscrollcommand "$top.verticalScrollBar set" + +# Populate the dialog +foreach reference $listOfReferences { + # The display name omits some leading characters (such as "remotes/") + set referenceDisplayName [string range $reference $truncateFrom end] + + # Split the branch/tag by slashes, and incrementally ensure that each leaf in the treeview exists.. + # otherwise add it. + set treeLeaves [split $referenceDisplayName "/"] + for {set i 0} {$i < [llength $treeLeaves]} {} { + set leafReferenceId [join [lrange $treeLeaves 0 $i] "/"] + if {![$top.referenceList exists $leafReferenceId]} { + if {$i > 0} { + set parentLeafId [join [lrange $treeLeaves 0 $i-1] "/"] + } else { + set parentLeafId {} + } + $top.referenceList insert $parentLeafId end -id $leafReferenceId -text [lindex $treeLeaves $i] + } + incr i + } +} + +${NS}::scrollbar $top.verticalScrollBar -command "$top.referenceList yview" -orient vertical +${NS}::scrollbar $top.horizontalScrollBar -command "$top.referenceList xview" -orient horizontal + +grid $top.referenceList $top.verticalScrollBar -sticky nsew +grid $top.horizontalScrollBar x -sticky ew + +bind $top [list destroy $top] + +bind $top.referenceList <> {callback_tree_of_references_item_selected %W; break} + +grid columnconfigure $top 0 -weight 1 +grid rowconfigure$top 0 -weight 1 +} + +# Call back for selecting a branch / tag in the tree of references +# +# @param w +# +proc callback_tree_of_references_item_selected {w} { +global headids tagids + +set itemId [$w focus] +switch -- $w { + ".show_tree_of_local_branches.referenceList" { + if {[info exists headids($itemId)]} { + selbyid $headids($itemId) + } + } + ".show_tree_of_remote_branches.referenceList" { + set itemId "remotes/$itemId" + if {[info exists headids($itemId)]} { + selbyid $headids($itemId) + } + } +