@matheusbsbs / matheus-bagliano / commits / d0b741dc08
Fork 0

git-gui: Allow the user to control the blame/commit split point

At one point I tried to present the blame viewer to an audience of people on a 640 by 480 pixel LCD projector. This did not work at all as the top area (the file data) was taking up all of the screen realestate and the split point was not adjustable by the user. In general locking the user into a specific ratio of display is just not user friendly. So we now place a split pane control into the middle of our blame window, so the user can adjust it to their current needs. If the window increases (or decreases) in height we assign the difference to the file data area, as that is generally the area of the window that users are trying to see more of when they grow the window. Unfortunately there appears to be a bug in the "pack" layout manager in Tcl/Tk 8.4.1. The status bar and the lower commit pane was being squashed if the window decreased in height. I think the pack manager was just not decreasing the size of the panedwindow slave properly if the main window shrank. Switching to the "grid" layout manager fixes the problem, but is slightly uglier setup code. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jun 1, 2007 at 17:55 UTC d0b741dc08d1c036e0fbf68c72dda02545c39b85
1 file changed +79 -25
lib/blame.tcl
+79 -25
@@ -13,6 +13,7 @@ field w_load
13 field w_file
14 field w_cmit
15 field status
16 +field old_height
17
18 field highlight_line -1 ; # current line selected
19 field highlight_commit {} ; # sha1 of commit selected
@@ -59,10 +60,22 @@ constructor new {i_commit i_path} {
60 -borderwidth 1 \
61 -relief sunken \
62 -font font_uibold
62 - pack $w.path -side top -fill x
63
64 - frame $w.out
65 - set w_load $w.out.loaded_t
64 + panedwindow $w.file_pane -orient vertical
65 + frame $w.file_pane.out
66 + frame $w.file_pane.cm
67 + $w.file_pane add $w.file_pane.out \
68 + -sticky nsew \
69 + -minsize 100 \
70 + -height 100 \
71 + -width 100
72 + $w.file_pane add $w.file_pane.cm \
73 + -sticky nsew \
74 + -minsize 25 \
75 + -height 25 \
76 + -width 100
77 +
78 + set w_load $w.file_pane.out.loaded_t
79 text $w_load \
80 -background white -borderwidth 0 \
81 -state disabled \
@@ -72,7 +85,7 @@ constructor new {i_commit i_path} {
85 -font font_diff
86 $w_load tag conf annotated -background grey
87
75 - set w_line $w.out.linenumber_t
88 + set w_line $w.file_pane.out.linenumber_t
89 text $w_line \
90 -background white -borderwidth 0 \
91 -state disabled \
@@ -82,7 +95,7 @@ constructor new {i_commit i_path} {
95 -font font_diff
96 $w_line tag conf linenumber -justify right
97
85 - set w_cgrp $w.out.commit_t
98 + set w_cgrp $w.file_pane.out.commit_t
99 text $w_cgrp \
100 -background white -borderwidth 0 \
101 -state disabled \
@@ -91,18 +104,21 @@ constructor new {i_commit i_path} {
104 -width 4 \
105 -font font_diff
106
94 - set w_file $w.out.file_t
107 + set w_file $w.file_pane.out.file_t
108 text $w_file \
109 -background white -borderwidth 0 \
110 -state disabled \
111 -wrap none \
112 -height 40 \
113 -width 80 \
101 - -xscrollcommand [list $w.out.sbx set] \
114 + -xscrollcommand [list $w.file_pane.out.sbx set] \
115 -font font_diff
116
104 - scrollbar $w.out.sbx -orient h -command [list $w_file xview]
105 - scrollbar $w.out.sby -orient v \
117 + scrollbar $w.file_pane.out.sbx \
118 + -orient h \
119 + -command [list $w_file xview]
120 + scrollbar $w.file_pane.out.sby \
121 + -orient v \
122 -command [list scrollbar2many [list \
123 $w_load \
124 $w_line \
@@ -114,12 +130,11 @@ constructor new {i_commit i_path} {
130 $w_line \
131 $w_load \
132 $w_file \
117 - $w.out.sby \
133 + $w.file_pane.out.sby \
134 -sticky nsew
119 - grid conf $w.out.sbx -column 3 -sticky we
120 - grid columnconfigure $w.out 3 -weight 1
121 - grid rowconfigure $w.out 0 -weight 1
122 - pack $w.out -fill both -expand 1
135 + grid conf $w.file_pane.out.sbx -column 3 -sticky we
136 + grid columnconfigure $w.file_pane.out 3 -weight 1
137 + grid rowconfigure $w.file_pane.out 0 -weight 1
138
139 label $w.status \
140 -textvariable @status \
@@ -127,18 +142,16 @@ constructor new {i_commit i_path} {
142 -justify left \
143 -borderwidth 1 \
144 -relief sunken
130 - pack $w.status -side bottom -fill x
145
132 - frame $w.cm
133 - set w_cmit $w.cm.t
146 + set w_cmit $w.file_pane.cm.t
147 text $w_cmit \
148 -background white -borderwidth 0 \
149 -state disabled \
150 -wrap none \
151 -height 10 \
152 -width 80 \
140 - -xscrollcommand [list $w.cm.sbx set] \
141 - -yscrollcommand [list $w.cm.sby set] \
153 + -xscrollcommand [list $w.file_pane.cm.sbx set] \
154 + -yscrollcommand [list $w.file_pane.cm.sby set] \
155 -font font_diff
156 $w_cmit tag conf header_key \
157 -tabs {3c} \
@@ -148,12 +161,15 @@ constructor new {i_commit i_path} {
161 -background $active_color \
162 -font font_ui
163 $w_cmit tag raise sel
151 - scrollbar $w.cm.sbx -orient h -command [list $w_cmit xview]
152 - scrollbar $w.cm.sby -orient v -command [list $w_cmit yview]
153 - pack $w.cm.sby -side right -fill y
154 - pack $w.cm.sbx -side bottom -fill x
164 + scrollbar $w.file_pane.cm.sbx \
165 + -orient h \
166 + -command [list $w_cmit xview]
167 + scrollbar $w.file_pane.cm.sby \
168 + -orient v \
169 + -command [list $w_cmit yview]
170 + pack $w.file_pane.cm.sby -side right -fill y
171 + pack $w.file_pane.cm.sbx -side bottom -fill x
172 pack $w_cmit -expand 1 -fill both
156 - pack $w.cm -side bottom -fill x
173
174 menu $w.ctxm -tearoff 0
175 $w.ctxm add command \
@@ -172,7 +188,7 @@ constructor new {i_commit i_path} {
188 $w_load \
189 $w_line \
190 $w_file \
175 - ] yview $w.out.sby]
191 + ] yview $w.file_pane.out.sby]
192 bind $i <Button-1> "
193 [cb _hide_tooltip]
194 [cb _click $i @%x,%y]
@@ -212,6 +228,29 @@ constructor new {i_commit i_path} {
228 bind $top <Visibility> [list focus $top]
229 bind $top <Destroy> [list delete_this $this]
230
231 + grid configure $w.path -sticky ew
232 + grid configure $w.file_pane -sticky nsew
233 + grid configure $w.status -sticky ew
234 + grid columnconfigure $top 0 -weight 1
235 + grid rowconfigure $top 0 -weight 0
236 + grid rowconfigure $top 1 -weight 1
237 + grid rowconfigure $top 2 -weight 0
238 +
239 + set req_w [winfo reqwidth $top]
240 + set req_h [winfo reqheight $top]
241 + if {$req_w < 600} {set req_w 600}
242 + if {$req_h < 400} {set req_h 400}
243 + set g "${req_w}x${req_h}"
244 + wm geometry $top $g
245 + update
246 +
247 + set old_height [winfo height $w.file_pane]
248 + $w.file_pane sash place 0 \
249 + [lindex [$w.file_pane sash coord 0] 0] \
250 + [expr {int($old_height * 0.70)}]
251 + bind $w.file_pane <Configure> \
252 + "if {{$w.file_pane} eq {%W}} {[cb _resize %h]}"
253 +
254 if {$commit eq {}} {
255 set fd [open $path r]
256 } else {
@@ -633,4 +672,19 @@ method _hide_tooltip {} {
672 }
673 }
674
675 +method _resize {new_height} {
676 + set diff [expr {$new_height - $old_height}]
677 + if {$diff == 0} return
678 +
679 + set my [expr {[winfo height $w.file_pane] - 25}]
680 + set o [$w.file_pane sash coord 0]
681 + set ox [lindex $o 0]
682 + set oy [expr {[lindex $o 1] + $diff}]
683 + if {$oy < 0} {set oy 0}
684 + if {$oy > $my} {set oy $my}
685 + $w.file_pane sash place 0 $ox $oy
686 +
687 + set old_height $new_height
688 +}
689 +
690 }