]>
Commit | Line | Data |
---|---|---|
1db95b00 PM |
1 | #!/bin/sh |
2 | # Tcl ignores the next line -*- tcl -*- \ | |
9e026d39 | 3 | exec wish "$0" -- "$@" |
1db95b00 PM |
4 | |
5 | # Copyright (C) 2005 Paul Mackerras. All rights reserved. | |
6 | # This program is free software; it may be used, copied, modified | |
7 | # and distributed under the terms of the GNU General Public Licence, | |
8 | # either version 2, or (at your option) any later version. | |
9 | ||
73b6a6cb JH |
10 | proc gitdir {} { |
11 | global env | |
12 | if {[info exists env(GIT_DIR)]} { | |
13 | return $env(GIT_DIR) | |
14 | } else { | |
15 | return ".git" | |
16 | } | |
17 | } | |
18 | ||
b5c2f306 SV |
19 | proc parse_args {rargs} { |
20 | global parsed_args | |
21 | ||
22 | if [catch { | |
23 | set parse_args [concat --default HEAD $rargs] | |
24 | set parsed_args [split [eval exec git-rev-parse $parse_args] "\n"] | |
25 | }] { | |
26 | # if git-rev-parse failed for some reason... | |
27 | if {$rargs == {}} { | |
28 | set rargs HEAD | |
29 | } | |
30 | set parsed_args $rargs | |
31 | } | |
32 | return $parsed_args | |
33 | } | |
34 | ||
38ad0910 | 35 | proc start_rev_list {rlargs} { |
466e4fdd | 36 | global startmsecs nextupdate ncmupdate |
38ad0910 | 37 | global commfd leftover gitencoding |
9ccbdfbf | 38 | |
9ccbdfbf | 39 | set startmsecs [clock clicks -milliseconds] |
2ed49d54 | 40 | set nextupdate [expr {$startmsecs + 100}] |
b664550c | 41 | set ncmupdate 1 |
2efef4b9 | 42 | if [catch { |
38ad0910 PM |
43 | set commfd [open [concat | git-rev-list --header --topo-order \ |
44 | --parents $rlargs] r] | |
2efef4b9 | 45 | } err] { |
cfb4563c | 46 | puts stderr "Error executing git-rev-list: $err" |
1d10f36d PM |
47 | exit 1 |
48 | } | |
b490a991 | 49 | set leftover {} |
495473c0 | 50 | fconfigure $commfd -blocking 0 -translation lf -encoding $gitencoding |
466e4fdd | 51 | fileevent $commfd readable [list getcommitlines $commfd] |
38ad0910 PM |
52 | . config -cursor watch |
53 | settextcursor watch | |
54 | } | |
55 | ||
56 | proc getcommits {rargs} { | |
57 | global oldcommits commits phase canv mainfont env | |
58 | ||
59 | # check that we can find a .git directory somewhere... | |
60 | set gitdir [gitdir] | |
61 | if {![file isdirectory $gitdir]} { | |
62 | error_popup "Cannot find the git directory \"$gitdir\"." | |
63 | exit 1 | |
64 | } | |
65 | set oldcommits {} | |
66 | set commits {} | |
67 | set phase getcommits | |
68 | start_rev_list [parse_args $rargs] | |
1d10f36d PM |
69 | $canv delete all |
70 | $canv create text 3 3 -anchor nw -text "Reading commits..." \ | |
71 | -font $mainfont -tags textitems | |
72 | } | |
73 | ||
b490a991 | 74 | proc getcommitlines {commfd} { |
b5c2f306 | 75 | global oldcommits commits parents cdate children nchildren |
232475d3 | 76 | global commitlisted phase nextupdate |
b490a991 | 77 | global stopped redisplaying leftover |
b5c2f306 | 78 | global canv |
9ccbdfbf | 79 | |
b490a991 PM |
80 | set stuff [read $commfd] |
81 | if {$stuff == {}} { | |
1d10f36d | 82 | if {![eof $commfd]} return |
f0654861 | 83 | # set it blocking so we wait for the process to terminate |
df3d83b1 | 84 | fconfigure $commfd -blocking 1 |
1d10f36d | 85 | if {![catch {close $commfd} err]} { |
9ccbdfbf | 86 | after idle finishcommits |
1d10f36d PM |
87 | return |
88 | } | |
9a40c50c | 89 | if {[string range $err 0 4] == "usage"} { |
9ccbdfbf | 90 | set err \ |
2ed49d54 JH |
91 | "Gitk: error reading commits: bad arguments to git-rev-list.\ |
92 | (Note: arguments to gitk are passed to git-rev-list\ | |
93 | to allow selection of commits to be displayed.)" | |
9a40c50c | 94 | } else { |
df3d83b1 | 95 | set err "Error reading commits: $err" |
9a40c50c | 96 | } |
df3d83b1 | 97 | error_popup $err |
1d10f36d | 98 | exit 1 |
9a40c50c | 99 | } |
b490a991 PM |
100 | set start 0 |
101 | while 1 { | |
102 | set i [string first "\0" $stuff $start] | |
103 | if {$i < 0} { | |
7e952e79 | 104 | append leftover [string range $stuff $start end] |
b490a991 | 105 | return |
9ccbdfbf | 106 | } |
b490a991 PM |
107 | set cmit [string range $stuff $start [expr {$i - 1}]] |
108 | if {$start == 0} { | |
109 | set cmit "$leftover$cmit" | |
7e952e79 | 110 | set leftover {} |
b490a991 PM |
111 | } |
112 | set start [expr {$i + 1}] | |
e5ea701b PM |
113 | set j [string first "\n" $cmit] |
114 | set ok 0 | |
115 | if {$j >= 0} { | |
116 | set ids [string range $cmit 0 [expr {$j - 1}]] | |
117 | set ok 1 | |
118 | foreach id $ids { | |
119 | if {![regexp {^[0-9a-f]{40}$} $id]} { | |
120 | set ok 0 | |
121 | break | |
122 | } | |
123 | } | |
124 | } | |
125 | if {!$ok} { | |
7e952e79 PM |
126 | set shortcmit $cmit |
127 | if {[string length $shortcmit] > 80} { | |
128 | set shortcmit "[string range $shortcmit 0 80]..." | |
129 | } | |
130 | error_popup "Can't parse git-rev-list output: {$shortcmit}" | |
b490a991 PM |
131 | exit 1 |
132 | } | |
e5ea701b PM |
133 | set id [lindex $ids 0] |
134 | set olds [lrange $ids 1 end] | |
135 | set cmit [string range $cmit [expr {$j + 1}] end] | |
b490a991 PM |
136 | lappend commits $id |
137 | set commitlisted($id) 1 | |
e5ea701b | 138 | parsecommit $id $cmit 1 [lrange $ids 1 end] |
b5c2f306 | 139 | drawcommit $id 1 |
b664550c PM |
140 | if {[clock clicks -milliseconds] >= $nextupdate} { |
141 | doupdate 1 | |
b490a991 PM |
142 | } |
143 | while {$redisplaying} { | |
144 | set redisplaying 0 | |
145 | if {$stopped == 1} { | |
146 | set stopped 0 | |
147 | set phase "getcommits" | |
148 | foreach id $commits { | |
b5c2f306 | 149 | drawcommit $id 1 |
b490a991 | 150 | if {$stopped} break |
b664550c PM |
151 | if {[clock clicks -milliseconds] >= $nextupdate} { |
152 | doupdate 1 | |
b490a991 | 153 | } |
9ccbdfbf PM |
154 | } |
155 | } | |
156 | } | |
157 | } | |
158 | } | |
159 | ||
b664550c PM |
160 | proc doupdate {reading} { |
161 | global commfd nextupdate numcommits ncmupdate | |
9ccbdfbf | 162 | |
b664550c PM |
163 | if {$reading} { |
164 | fileevent $commfd readable {} | |
165 | } | |
9ccbdfbf | 166 | update |
b664550c PM |
167 | set nextupdate [expr {[clock clicks -milliseconds] + 100}] |
168 | if {$numcommits < 100} { | |
169 | set ncmupdate [expr {$numcommits + 1}] | |
170 | } elseif {$numcommits < 10000} { | |
171 | set ncmupdate [expr {$numcommits + 10}] | |
172 | } else { | |
173 | set ncmupdate [expr {$numcommits + 100}] | |
174 | } | |
175 | if {$reading} { | |
176 | fileevent $commfd readable [list getcommitlines $commfd] | |
177 | } | |
1db95b00 PM |
178 | } |
179 | ||
180 | proc readcommit {id} { | |
b490a991 | 181 | if [catch {set contents [exec git-cat-file commit $id]}] return |
e5ea701b | 182 | parsecommit $id $contents 0 {} |
b490a991 PM |
183 | } |
184 | ||
b5c2f306 SV |
185 | proc updatechildren {id olds} { |
186 | global children nchildren parents nparents ncleft | |
9ccbdfbf | 187 | |
cfb4563c PM |
188 | if {![info exists nchildren($id)]} { |
189 | set children($id) {} | |
190 | set nchildren($id) 0 | |
9ccbdfbf | 191 | set ncleft($id) 0 |
cfb4563c | 192 | } |
e5ea701b PM |
193 | set parents($id) $olds |
194 | set nparents($id) [llength $olds] | |
195 | foreach p $olds { | |
196 | if {![info exists nchildren($p)]} { | |
197 | set children($p) [list $id] | |
198 | set nchildren($p) 1 | |
199 | set ncleft($p) 1 | |
200 | } elseif {[lsearch -exact $children($p) $id] < 0} { | |
201 | lappend children($p) $id | |
202 | incr nchildren($p) | |
203 | incr ncleft($p) | |
244edd12 PM |
204 | } |
205 | } | |
b5c2f306 SV |
206 | } |
207 | ||
208 | proc parsecommit {id contents listed olds} { | |
209 | global commitinfo cdate | |
210 | ||
211 | set inhdr 1 | |
212 | set comment {} | |
213 | set headline {} | |
214 | set auname {} | |
215 | set audate {} | |
216 | set comname {} | |
217 | set comdate {} | |
218 | updatechildren $id $olds | |
232475d3 PM |
219 | set hdrend [string first "\n\n" $contents] |
220 | if {$hdrend < 0} { | |
221 | # should never happen... | |
222 | set hdrend [string length $contents] | |
223 | } | |
224 | set header [string range $contents 0 [expr {$hdrend - 1}]] | |
225 | set comment [string range $contents [expr {$hdrend + 2}] end] | |
226 | foreach line [split $header "\n"] { | |
227 | set tag [lindex $line 0] | |
228 | if {$tag == "author"} { | |
229 | set audate [lindex $line end-1] | |
230 | set auname [lrange $line 1 end-2] | |
231 | } elseif {$tag == "committer"} { | |
232 | set comdate [lindex $line end-1] | |
233 | set comname [lrange $line 1 end-2] | |
1db95b00 PM |
234 | } |
235 | } | |
232475d3 PM |
236 | set headline {} |
237 | # take the first line of the comment as the headline | |
238 | set i [string first "\n" $comment] | |
239 | if {$i >= 0} { | |
240 | set headline [string trim [string range $comment 0 $i]] | |
f6e2869f PM |
241 | } else { |
242 | set headline $comment | |
232475d3 PM |
243 | } |
244 | if {!$listed} { | |
245 | # git-rev-list indents the comment by 4 spaces; | |
246 | # if we got this via git-cat-file, add the indentation | |
247 | set newcomment {} | |
248 | foreach line [split $comment "\n"] { | |
249 | append newcomment " " | |
250 | append newcomment $line | |
f6e2869f | 251 | append newcomment "\n" |
232475d3 PM |
252 | } |
253 | set comment $newcomment | |
1db95b00 PM |
254 | } |
255 | if {$comdate != {}} { | |
cfb4563c | 256 | set cdate($id) $comdate |
1db95b00 | 257 | } |
e5c2d856 PM |
258 | set commitinfo($id) [list $headline $auname $audate \ |
259 | $comname $comdate $comment] | |
1db95b00 PM |
260 | } |
261 | ||
887fe3c4 | 262 | proc readrefs {} { |
106288cb | 263 | global tagids idtags headids idheads tagcontents |
36a7cad6 | 264 | global otherrefids idotherrefs |
106288cb | 265 | |
b5c2f306 SV |
266 | foreach v {tagids idtags headids idheads otherrefids idotherrefs} { |
267 | catch {unset $v} | |
268 | } | |
36a7cad6 JH |
269 | set refd [open [list | git-ls-remote [gitdir]] r] |
270 | while {0 <= [set n [gets $refd line]]} { | |
271 | if {![regexp {^([0-9a-f]{40}) refs/([^^]*)$} $line \ | |
272 | match id path]} { | |
273 | continue | |
c2f6a022 | 274 | } |
36a7cad6 JH |
275 | if {![regexp {^(tags|heads)/(.*)$} $path match type name]} { |
276 | set type others | |
277 | set name $path | |
887fe3c4 | 278 | } |
36a7cad6 JH |
279 | if {$type == "tags"} { |
280 | set tagids($name) $id | |
281 | lappend idtags($id) $name | |
282 | set obj {} | |
283 | set type {} | |
284 | set tag {} | |
285 | catch { | |
286 | set commit [exec git-rev-parse "$id^0"] | |
287 | if {"$commit" != "$id"} { | |
288 | set tagids($name) $commit | |
289 | lappend idtags($commit) $name | |
290 | } | |
291 | } | |
292 | catch { | |
293 | set tagcontents($name) [exec git-cat-file tag "$id"] | |
f1d83ba3 | 294 | } |
36a7cad6 JH |
295 | } elseif { $type == "heads" } { |
296 | set headids($name) $id | |
297 | lappend idheads($id) $name | |
298 | } else { | |
299 | set otherrefids($name) $id | |
300 | lappend idotherrefs($id) $name | |
f1d83ba3 PM |
301 | } |
302 | } | |
36a7cad6 | 303 | close $refd |
887fe3c4 PM |
304 | } |
305 | ||
df3d83b1 PM |
306 | proc error_popup msg { |
307 | set w .error | |
308 | toplevel $w | |
309 | wm transient $w . | |
310 | message $w.m -text $msg -justify center -aspect 400 | |
311 | pack $w.m -side top -fill x -padx 20 -pady 20 | |
312 | button $w.ok -text OK -command "destroy $w" | |
313 | pack $w.ok -side bottom -fill x | |
314 | bind $w <Visibility> "grab $w; focus $w" | |
315 | tkwait window $w | |
316 | } | |
317 | ||
b5c2f306 | 318 | proc makewindow {rargs} { |
e5c2d856 | 319 | global canv canv2 canv3 linespc charspc ctext cflist textfont |
b74fd579 | 320 | global findtype findtypemenu findloc findstring fstring geometry |
887fe3c4 | 321 | global entries sha1entry sha1string sha1but |
94a2eede | 322 | global maincursor textcursor curtextcursor |
712fcc08 | 323 | global rowctxmenu mergemax |
9a40c50c PM |
324 | |
325 | menu .bar | |
326 | .bar add cascade -label "File" -menu .bar.file | |
327 | menu .bar.file | |
b5c2f306 | 328 | .bar.file add command -label "Update" -command [list updatecommits $rargs] |
f1d83ba3 | 329 | .bar.file add command -label "Reread references" -command rereadrefs |
1d10f36d | 330 | .bar.file add command -label "Quit" -command doquit |
712fcc08 PM |
331 | menu .bar.edit |
332 | .bar add cascade -label "Edit" -menu .bar.edit | |
333 | .bar.edit add command -label "Preferences" -command doprefs | |
9a40c50c PM |
334 | menu .bar.help |
335 | .bar add cascade -label "Help" -menu .bar.help | |
336 | .bar.help add command -label "About gitk" -command about | |
337 | . configure -menu .bar | |
338 | ||
0fba86b3 | 339 | if {![info exists geometry(canv1)]} { |
2ed49d54 JH |
340 | set geometry(canv1) [expr {45 * $charspc}] |
341 | set geometry(canv2) [expr {30 * $charspc}] | |
342 | set geometry(canv3) [expr {15 * $charspc}] | |
343 | set geometry(canvh) [expr {25 * $linespc + 4}] | |
0fba86b3 PM |
344 | set geometry(ctextw) 80 |
345 | set geometry(ctexth) 30 | |
346 | set geometry(cflistw) 30 | |
347 | } | |
0327d27a | 348 | panedwindow .ctop -orient vertical |
0fba86b3 PM |
349 | if {[info exists geometry(width)]} { |
350 | .ctop conf -width $geometry(width) -height $geometry(height) | |
17386066 PM |
351 | set texth [expr {$geometry(height) - $geometry(canvh) - 56}] |
352 | set geometry(ctexth) [expr {($texth - 8) / | |
353 | [font metrics $textfont -linespace]}] | |
0fba86b3 | 354 | } |
98f350e5 PM |
355 | frame .ctop.top |
356 | frame .ctop.top.bar | |
357 | pack .ctop.top.bar -side bottom -fill x | |
358 | set cscroll .ctop.top.csb | |
359 | scrollbar $cscroll -command {allcanvs yview} -highlightthickness 0 | |
360 | pack $cscroll -side right -fill y | |
361 | panedwindow .ctop.top.clist -orient horizontal -sashpad 0 -handlesize 4 | |
362 | pack .ctop.top.clist -side top -fill both -expand 1 | |
363 | .ctop add .ctop.top | |
364 | set canv .ctop.top.clist.canv | |
0fba86b3 | 365 | canvas $canv -height $geometry(canvh) -width $geometry(canv1) \ |
b5721c72 PM |
366 | -bg white -bd 0 \ |
367 | -yscrollincr $linespc -yscrollcommand "$cscroll set" | |
98f350e5 PM |
368 | .ctop.top.clist add $canv |
369 | set canv2 .ctop.top.clist.canv2 | |
0fba86b3 | 370 | canvas $canv2 -height $geometry(canvh) -width $geometry(canv2) \ |
b5721c72 | 371 | -bg white -bd 0 -yscrollincr $linespc |
98f350e5 PM |
372 | .ctop.top.clist add $canv2 |
373 | set canv3 .ctop.top.clist.canv3 | |
0fba86b3 | 374 | canvas $canv3 -height $geometry(canvh) -width $geometry(canv3) \ |
b5721c72 | 375 | -bg white -bd 0 -yscrollincr $linespc |
98f350e5 | 376 | .ctop.top.clist add $canv3 |
43bddeb4 | 377 | bind .ctop.top.clist <Configure> {resizeclistpanes %W %w} |
98f350e5 PM |
378 | |
379 | set sha1entry .ctop.top.bar.sha1 | |
887fe3c4 PM |
380 | set entries $sha1entry |
381 | set sha1but .ctop.top.bar.sha1label | |
382 | button $sha1but -text "SHA1 ID: " -state disabled -relief flat \ | |
383 | -command gotocommit -width 8 | |
384 | $sha1but conf -disabledforeground [$sha1but cget -foreground] | |
98f350e5 | 385 | pack .ctop.top.bar.sha1label -side left |
887fe3c4 PM |
386 | entry $sha1entry -width 40 -font $textfont -textvariable sha1string |
387 | trace add variable sha1string write sha1change | |
98f350e5 | 388 | pack $sha1entry -side left -pady 2 |
d698206c PM |
389 | |
390 | image create bitmap bm-left -data { | |
391 | #define left_width 16 | |
392 | #define left_height 16 | |
393 | static unsigned char left_bits[] = { | |
394 | 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00, | |
395 | 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00, | |
396 | 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01}; | |
397 | } | |
398 | image create bitmap bm-right -data { | |
399 | #define right_width 16 | |
400 | #define right_height 16 | |
401 | static unsigned char right_bits[] = { | |
402 | 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c, | |
403 | 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c, | |
404 | 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01}; | |
405 | } | |
406 | button .ctop.top.bar.leftbut -image bm-left -command goback \ | |
407 | -state disabled -width 26 | |
408 | pack .ctop.top.bar.leftbut -side left -fill y | |
409 | button .ctop.top.bar.rightbut -image bm-right -command goforw \ | |
410 | -state disabled -width 26 | |
411 | pack .ctop.top.bar.rightbut -side left -fill y | |
412 | ||
98f350e5 PM |
413 | button .ctop.top.bar.findbut -text "Find" -command dofind |
414 | pack .ctop.top.bar.findbut -side left | |
415 | set findstring {} | |
df3d83b1 | 416 | set fstring .ctop.top.bar.findstring |
887fe3c4 | 417 | lappend entries $fstring |
df3d83b1 | 418 | entry $fstring -width 30 -font $textfont -textvariable findstring |
df3d83b1 | 419 | pack $fstring -side left -expand 1 -fill x |
98f350e5 | 420 | set findtype Exact |
b74fd579 PM |
421 | set findtypemenu [tk_optionMenu .ctop.top.bar.findtype \ |
422 | findtype Exact IgnCase Regexp] | |
98f350e5 PM |
423 | set findloc "All fields" |
424 | tk_optionMenu .ctop.top.bar.findloc findloc "All fields" Headline \ | |
b74fd579 | 425 | Comments Author Committer Files Pickaxe |
98f350e5 PM |
426 | pack .ctop.top.bar.findloc -side right |
427 | pack .ctop.top.bar.findtype -side right | |
b74fd579 PM |
428 | # for making sure type==Exact whenever loc==Pickaxe |
429 | trace add variable findloc write findlocchange | |
b5721c72 | 430 | |
5ad588de PM |
431 | panedwindow .ctop.cdet -orient horizontal |
432 | .ctop add .ctop.cdet | |
d2610d11 PM |
433 | frame .ctop.cdet.left |
434 | set ctext .ctop.cdet.left.ctext | |
0fba86b3 PM |
435 | text $ctext -bg white -state disabled -font $textfont \ |
436 | -width $geometry(ctextw) -height $geometry(ctexth) \ | |
b1ba39e7 | 437 | -yscrollcommand ".ctop.cdet.left.sb set" -wrap none |
d2610d11 PM |
438 | scrollbar .ctop.cdet.left.sb -command "$ctext yview" |
439 | pack .ctop.cdet.left.sb -side right -fill y | |
440 | pack $ctext -side left -fill both -expand 1 | |
441 | .ctop.cdet add .ctop.cdet.left | |
442 | ||
f0654861 | 443 | $ctext tag conf filesep -font [concat $textfont bold] -back "#aaaaaa" |
712fcc08 PM |
444 | $ctext tag conf hunksep -fore blue |
445 | $ctext tag conf d0 -fore red | |
446 | $ctext tag conf d1 -fore "#00a000" | |
447 | $ctext tag conf m0 -fore red | |
448 | $ctext tag conf m1 -fore blue | |
449 | $ctext tag conf m2 -fore green | |
450 | $ctext tag conf m3 -fore purple | |
451 | $ctext tag conf m4 -fore brown | |
452 | $ctext tag conf mmax -fore darkgrey | |
453 | set mergemax 5 | |
454 | $ctext tag conf mresult -font [concat $textfont bold] | |
455 | $ctext tag conf msep -font [concat $textfont bold] | |
456 | $ctext tag conf found -back yellow | |
e5c2d856 | 457 | |
d2610d11 PM |
458 | frame .ctop.cdet.right |
459 | set cflist .ctop.cdet.right.cfiles | |
17386066 | 460 | listbox $cflist -bg white -selectmode extended -width $geometry(cflistw) \ |
d2610d11 PM |
461 | -yscrollcommand ".ctop.cdet.right.sb set" |
462 | scrollbar .ctop.cdet.right.sb -command "$cflist yview" | |
463 | pack .ctop.cdet.right.sb -side right -fill y | |
464 | pack $cflist -side left -fill both -expand 1 | |
465 | .ctop.cdet add .ctop.cdet.right | |
0fba86b3 | 466 | bind .ctop.cdet <Configure> {resizecdetpanes %W %w} |
d2610d11 | 467 | |
0327d27a | 468 | pack .ctop -side top -fill both -expand 1 |
1db95b00 | 469 | |
c8dfbcf9 PM |
470 | bindall <1> {selcanvline %W %x %y} |
471 | #bindall <B1-Motion> {selcanvline %W %x %y} | |
cfb4563c PM |
472 | bindall <ButtonRelease-4> "allcanvs yview scroll -5 units" |
473 | bindall <ButtonRelease-5> "allcanvs yview scroll 5 units" | |
b5721c72 PM |
474 | bindall <2> "allcanvs scan mark 0 %y" |
475 | bindall <B2-Motion> "allcanvs scan dragto 0 %y" | |
17386066 PM |
476 | bind . <Key-Up> "selnextline -1" |
477 | bind . <Key-Down> "selnextline 1" | |
6e2dda35 RS |
478 | bind . <Key-Right> "goforw" |
479 | bind . <Key-Left> "goback" | |
cfb4563c PM |
480 | bind . <Key-Prior> "allcanvs yview scroll -1 pages" |
481 | bind . <Key-Next> "allcanvs yview scroll 1 pages" | |
482 | bindkey <Key-Delete> "$ctext yview scroll -1 pages" | |
483 | bindkey <Key-BackSpace> "$ctext yview scroll -1 pages" | |
484 | bindkey <Key-space> "$ctext yview scroll 1 pages" | |
df3d83b1 PM |
485 | bindkey p "selnextline -1" |
486 | bindkey n "selnextline 1" | |
6e2dda35 RS |
487 | bindkey z "goback" |
488 | bindkey x "goforw" | |
489 | bindkey i "selnextline -1" | |
490 | bindkey k "selnextline 1" | |
491 | bindkey j "goback" | |
492 | bindkey l "goforw" | |
cfb4563c PM |
493 | bindkey b "$ctext yview scroll -1 pages" |
494 | bindkey d "$ctext yview scroll 18 units" | |
495 | bindkey u "$ctext yview scroll -18 units" | |
b74fd579 PM |
496 | bindkey / {findnext 1} |
497 | bindkey <Key-Return> {findnext 0} | |
df3d83b1 | 498 | bindkey ? findprev |
39ad8570 | 499 | bindkey f nextfile |
1d10f36d | 500 | bind . <Control-q> doquit |
98f350e5 | 501 | bind . <Control-f> dofind |
b74fd579 | 502 | bind . <Control-g> {findnext 0} |
98f350e5 | 503 | bind . <Control-r> findprev |
1d10f36d PM |
504 | bind . <Control-equal> {incrfont 1} |
505 | bind . <Control-KP_Add> {incrfont 1} | |
506 | bind . <Control-minus> {incrfont -1} | |
507 | bind . <Control-KP_Subtract> {incrfont -1} | |
e5c2d856 | 508 | bind $cflist <<ListboxSelect>> listboxsel |
0fba86b3 | 509 | bind . <Destroy> {savestuff %W} |
df3d83b1 | 510 | bind . <Button-1> "click %W" |
17386066 | 511 | bind $fstring <Key-Return> dofind |
887fe3c4 | 512 | bind $sha1entry <Key-Return> gotocommit |
ee3dc72e | 513 | bind $sha1entry <<PasteSelection>> clearsha1 |
ea13cba1 PM |
514 | |
515 | set maincursor [. cget -cursor] | |
516 | set textcursor [$ctext cget -cursor] | |
94a2eede | 517 | set curtextcursor $textcursor |
84ba7345 | 518 | |
c8dfbcf9 PM |
519 | set rowctxmenu .rowctxmenu |
520 | menu $rowctxmenu -tearoff 0 | |
521 | $rowctxmenu add command -label "Diff this -> selected" \ | |
522 | -command {diffvssel 0} | |
523 | $rowctxmenu add command -label "Diff selected -> this" \ | |
524 | -command {diffvssel 1} | |
74daedb6 | 525 | $rowctxmenu add command -label "Make patch" -command mkpatch |
bdbfbe3d | 526 | $rowctxmenu add command -label "Create tag" -command mktag |
4a2139f5 | 527 | $rowctxmenu add command -label "Write commit to file" -command writecommit |
df3d83b1 PM |
528 | } |
529 | ||
530 | # when we make a key binding for the toplevel, make sure | |
531 | # it doesn't get triggered when that key is pressed in the | |
532 | # find string entry widget. | |
533 | proc bindkey {ev script} { | |
887fe3c4 | 534 | global entries |
df3d83b1 PM |
535 | bind . $ev $script |
536 | set escript [bind Entry $ev] | |
537 | if {$escript == {}} { | |
538 | set escript [bind Entry <Key>] | |
539 | } | |
887fe3c4 PM |
540 | foreach e $entries { |
541 | bind $e $ev "$escript; break" | |
542 | } | |
df3d83b1 PM |
543 | } |
544 | ||
545 | # set the focus back to the toplevel for any click outside | |
887fe3c4 | 546 | # the entry widgets |
df3d83b1 | 547 | proc click {w} { |
887fe3c4 PM |
548 | global entries |
549 | foreach e $entries { | |
550 | if {$w == $e} return | |
df3d83b1 | 551 | } |
887fe3c4 | 552 | focus . |
0fba86b3 PM |
553 | } |
554 | ||
555 | proc savestuff {w} { | |
556 | global canv canv2 canv3 ctext cflist mainfont textfont | |
712fcc08 | 557 | global stuffsaved findmergefiles maxgraphpct |
04c13d38 | 558 | global maxwidth |
4ef17537 | 559 | |
0fba86b3 | 560 | if {$stuffsaved} return |
df3d83b1 | 561 | if {![winfo viewable .]} return |
0fba86b3 PM |
562 | catch { |
563 | set f [open "~/.gitk-new" w] | |
f0654861 PM |
564 | puts $f [list set mainfont $mainfont] |
565 | puts $f [list set textfont $textfont] | |
566 | puts $f [list set findmergefiles $findmergefiles] | |
8d858d1a | 567 | puts $f [list set maxgraphpct $maxgraphpct] |
04c13d38 | 568 | puts $f [list set maxwidth $maxwidth] |
0fba86b3 PM |
569 | puts $f "set geometry(width) [winfo width .ctop]" |
570 | puts $f "set geometry(height) [winfo height .ctop]" | |
2ed49d54 JH |
571 | puts $f "set geometry(canv1) [expr {[winfo width $canv]-2}]" |
572 | puts $f "set geometry(canv2) [expr {[winfo width $canv2]-2}]" | |
573 | puts $f "set geometry(canv3) [expr {[winfo width $canv3]-2}]" | |
574 | puts $f "set geometry(canvh) [expr {[winfo height $canv]-2}]" | |
0fba86b3 PM |
575 | set wid [expr {([winfo width $ctext] - 8) \ |
576 | / [font measure $textfont "0"]}] | |
0fba86b3 | 577 | puts $f "set geometry(ctextw) $wid" |
0fba86b3 PM |
578 | set wid [expr {([winfo width $cflist] - 11) \ |
579 | / [font measure [$cflist cget -font] "0"]}] | |
580 | puts $f "set geometry(cflistw) $wid" | |
581 | close $f | |
582 | file rename -force "~/.gitk-new" "~/.gitk" | |
583 | } | |
584 | set stuffsaved 1 | |
1db95b00 PM |
585 | } |
586 | ||
43bddeb4 PM |
587 | proc resizeclistpanes {win w} { |
588 | global oldwidth | |
589 | if [info exists oldwidth($win)] { | |
590 | set s0 [$win sash coord 0] | |
591 | set s1 [$win sash coord 1] | |
592 | if {$w < 60} { | |
593 | set sash0 [expr {int($w/2 - 2)}] | |
594 | set sash1 [expr {int($w*5/6 - 2)}] | |
595 | } else { | |
596 | set factor [expr {1.0 * $w / $oldwidth($win)}] | |
597 | set sash0 [expr {int($factor * [lindex $s0 0])}] | |
598 | set sash1 [expr {int($factor * [lindex $s1 0])}] | |
599 | if {$sash0 < 30} { | |
600 | set sash0 30 | |
601 | } | |
602 | if {$sash1 < $sash0 + 20} { | |
2ed49d54 | 603 | set sash1 [expr {$sash0 + 20}] |
43bddeb4 PM |
604 | } |
605 | if {$sash1 > $w - 10} { | |
2ed49d54 | 606 | set sash1 [expr {$w - 10}] |
43bddeb4 | 607 | if {$sash0 > $sash1 - 20} { |
2ed49d54 | 608 | set sash0 [expr {$sash1 - 20}] |
43bddeb4 PM |
609 | } |
610 | } | |
611 | } | |
612 | $win sash place 0 $sash0 [lindex $s0 1] | |
613 | $win sash place 1 $sash1 [lindex $s1 1] | |
614 | } | |
615 | set oldwidth($win) $w | |
616 | } | |
617 | ||
618 | proc resizecdetpanes {win w} { | |
619 | global oldwidth | |
620 | if [info exists oldwidth($win)] { | |
621 | set s0 [$win sash coord 0] | |
622 | if {$w < 60} { | |
623 | set sash0 [expr {int($w*3/4 - 2)}] | |
624 | } else { | |
625 | set factor [expr {1.0 * $w / $oldwidth($win)}] | |
626 | set sash0 [expr {int($factor * [lindex $s0 0])}] | |
627 | if {$sash0 < 45} { | |
628 | set sash0 45 | |
629 | } | |
630 | if {$sash0 > $w - 15} { | |
2ed49d54 | 631 | set sash0 [expr {$w - 15}] |
43bddeb4 PM |
632 | } |
633 | } | |
634 | $win sash place 0 $sash0 [lindex $s0 1] | |
635 | } | |
636 | set oldwidth($win) $w | |
637 | } | |
638 | ||
b5721c72 PM |
639 | proc allcanvs args { |
640 | global canv canv2 canv3 | |
641 | eval $canv $args | |
642 | eval $canv2 $args | |
643 | eval $canv3 $args | |
644 | } | |
645 | ||
646 | proc bindall {event action} { | |
647 | global canv canv2 canv3 | |
648 | bind $canv $event $action | |
649 | bind $canv2 $event $action | |
650 | bind $canv3 $event $action | |
651 | } | |
652 | ||
9a40c50c PM |
653 | proc about {} { |
654 | set w .about | |
655 | if {[winfo exists $w]} { | |
656 | raise $w | |
657 | return | |
658 | } | |
659 | toplevel $w | |
660 | wm title $w "About gitk" | |
661 | message $w.m -text { | |
c8dfbcf9 | 662 | Gitk version 1.2 |
9a40c50c PM |
663 | |
664 |