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