]> git.ipfire.org Git - thirdparty/git.git/blame - gitk
gitk: Add a preferences dialog with some basic stuff
[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
495473c0 22 global ctext maincursor textcursor leftover gitencoding
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 32 set startmsecs [clock clicks -milliseconds]
2ed49d54 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 {}
495473c0 52 fconfigure $commfd -blocking 0 -translation lf -encoding $gitencoding
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 76 set err \
2ed49d54
JH
77 "Gitk: error reading commits: bad arguments to git-rev-list.\
78 (Note: arguments to gitk are passed to git-rev-list\
79 to 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]]
f6e2869f
PM
221 } else {
222 set headline $comment
232475d3
PM
223 }
224 if {!$listed} {
225 # git-rev-list indents the comment by 4 spaces;
226 # if we got this via git-cat-file, add the indentation
227 set newcomment {}
228 foreach line [split $comment "\n"] {
229 append newcomment " "
230 append newcomment $line
f6e2869f 231 append newcomment "\n"
232475d3
PM
232 }
233 set comment $newcomment
1db95b00
PM
234 }
235 if {$comdate != {}} {
cfb4563c 236 set cdate($id) $comdate
1db95b00 237 }
e5c2d856
PM
238 set commitinfo($id) [list $headline $auname $audate \
239 $comname $comdate $comment]
1db95b00
PM
240}
241
887fe3c4 242proc readrefs {} {
106288cb 243 global tagids idtags headids idheads tagcontents
36a7cad6 244 global otherrefids idotherrefs
106288cb 245
36a7cad6
JH
246 set refd [open [list | git-ls-remote [gitdir]] r]
247 while {0 <= [set n [gets $refd line]]} {
248 if {![regexp {^([0-9a-f]{40}) refs/([^^]*)$} $line \
249 match id path]} {
250 continue
c2f6a022 251 }
36a7cad6
JH
252 if {![regexp {^(tags|heads)/(.*)$} $path match type name]} {
253 set type others
254 set name $path
887fe3c4 255 }
36a7cad6
JH
256 if {$type == "tags"} {
257 set tagids($name) $id
258 lappend idtags($id) $name
259 set obj {}
260 set type {}
261 set tag {}
262 catch {
263 set commit [exec git-rev-parse "$id^0"]
264 if {"$commit" != "$id"} {
265 set tagids($name) $commit
266 lappend idtags($commit) $name
267 }
268 }
269 catch {
270 set tagcontents($name) [exec git-cat-file tag "$id"]
f1d83ba3 271 }
36a7cad6
JH
272 } elseif { $type == "heads" } {
273 set headids($name) $id
274 lappend idheads($id) $name
275 } else {
276 set otherrefids($name) $id
277 lappend idotherrefs($id) $name
f1d83ba3
PM
278 }
279 }
36a7cad6 280 close $refd
887fe3c4
PM
281}
282
df3d83b1
PM
283proc error_popup msg {
284 set w .error
285 toplevel $w
286 wm transient $w .
287 message $w.m -text $msg -justify center -aspect 400
288 pack $w.m -side top -fill x -padx 20 -pady 20
289 button $w.ok -text OK -command "destroy $w"
290 pack $w.ok -side bottom -fill x
291 bind $w <Visibility> "grab $w; focus $w"
292 tkwait window $w
293}
294
1db95b00 295proc makewindow {} {
e5c2d856 296 global canv canv2 canv3 linespc charspc ctext cflist textfont
b74fd579 297 global findtype findtypemenu findloc findstring fstring geometry
887fe3c4 298 global entries sha1entry sha1string sha1but
94a2eede 299 global maincursor textcursor curtextcursor
712fcc08 300 global rowctxmenu mergemax
9a40c50c
PM
301
302 menu .bar
303 .bar add cascade -label "File" -menu .bar.file
304 menu .bar.file
f1d83ba3 305 .bar.file add command -label "Reread references" -command rereadrefs
1d10f36d 306 .bar.file add command -label "Quit" -command doquit
712fcc08
PM
307 menu .bar.edit
308 .bar add cascade -label "Edit" -menu .bar.edit
309 .bar.edit add command -label "Preferences" -command doprefs
9a40c50c
PM
310 menu .bar.help
311 .bar add cascade -label "Help" -menu .bar.help
312 .bar.help add command -label "About gitk" -command about
313 . configure -menu .bar
314
0fba86b3 315 if {![info exists geometry(canv1)]} {
2ed49d54
JH
316 set geometry(canv1) [expr {45 * $charspc}]
317 set geometry(canv2) [expr {30 * $charspc}]
318 set geometry(canv3) [expr {15 * $charspc}]
319 set geometry(canvh) [expr {25 * $linespc + 4}]
0fba86b3
PM
320 set geometry(ctextw) 80
321 set geometry(ctexth) 30
322 set geometry(cflistw) 30
323 }
0327d27a 324 panedwindow .ctop -orient vertical
0fba86b3
PM
325 if {[info exists geometry(width)]} {
326 .ctop conf -width $geometry(width) -height $geometry(height)
17386066
PM
327 set texth [expr {$geometry(height) - $geometry(canvh) - 56}]
328 set geometry(ctexth) [expr {($texth - 8) /
329 [font metrics $textfont -linespace]}]
0fba86b3 330 }
98f350e5
PM
331 frame .ctop.top
332 frame .ctop.top.bar
333 pack .ctop.top.bar -side bottom -fill x
334 set cscroll .ctop.top.csb
335 scrollbar $cscroll -command {allcanvs yview} -highlightthickness 0
336 pack $cscroll -side right -fill y
337 panedwindow .ctop.top.clist -orient horizontal -sashpad 0 -handlesize 4
338 pack .ctop.top.clist -side top -fill both -expand 1
339 .ctop add .ctop.top
340 set canv .ctop.top.clist.canv
0fba86b3 341 canvas $canv -height $geometry(canvh) -width $geometry(canv1) \
b5721c72
PM
342 -bg white -bd 0 \
343 -yscrollincr $linespc -yscrollcommand "$cscroll set"
98f350e5
PM
344 .ctop.top.clist add $canv
345 set canv2 .ctop.top.clist.canv2
0fba86b3 346 canvas $canv2 -height $geometry(canvh) -width $geometry(canv2) \
b5721c72 347 -bg white -bd 0 -yscrollincr $linespc
98f350e5
PM
348 .ctop.top.clist add $canv2
349 set canv3 .ctop.top.clist.canv3
0fba86b3 350 canvas $canv3 -height $geometry(canvh) -width $geometry(canv3) \
b5721c72 351 -bg white -bd 0 -yscrollincr $linespc
98f350e5 352 .ctop.top.clist add $canv3
43bddeb4 353 bind .ctop.top.clist <Configure> {resizeclistpanes %W %w}
98f350e5
PM
354
355 set sha1entry .ctop.top.bar.sha1
887fe3c4
PM
356 set entries $sha1entry
357 set sha1but .ctop.top.bar.sha1label
358 button $sha1but -text "SHA1 ID: " -state disabled -relief flat \
359 -command gotocommit -width 8
360 $sha1but conf -disabledforeground [$sha1but cget -foreground]
98f350e5 361 pack .ctop.top.bar.sha1label -side left
887fe3c4
PM
362 entry $sha1entry -width 40 -font $textfont -textvariable sha1string
363 trace add variable sha1string write sha1change
98f350e5 364 pack $sha1entry -side left -pady 2
d698206c
PM
365
366 image create bitmap bm-left -data {
367 #define left_width 16
368 #define left_height 16
369 static unsigned char left_bits[] = {
370 0x00, 0x00, 0xc0, 0x01, 0xe0, 0x00, 0x70, 0x00, 0x38, 0x00, 0x1c, 0x00,
371 0x0e, 0x00, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x0e, 0x00, 0x1c, 0x00,
372 0x38, 0x00, 0x70, 0x00, 0xe0, 0x00, 0xc0, 0x01};
373 }
374 image create bitmap bm-right -data {
375 #define right_width 16
376 #define right_height 16
377 static unsigned char right_bits[] = {
378 0x00, 0x00, 0xc0, 0x01, 0x80, 0x03, 0x00, 0x07, 0x00, 0x0e, 0x00, 0x1c,
379 0x00, 0x38, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x00, 0x38, 0x00, 0x1c,
380 0x00, 0x0e, 0x00, 0x07, 0x80, 0x03, 0xc0, 0x01};
381 }
382 button .ctop.top.bar.leftbut -image bm-left -command goback \
383 -state disabled -width 26
384 pack .ctop.top.bar.leftbut -side left -fill y
385 button .ctop.top.bar.rightbut -image bm-right -command goforw \
386 -state disabled -width 26
387 pack .ctop.top.bar.rightbut -side left -fill y
388
98f350e5
PM
389 button .ctop.top.bar.findbut -text "Find" -command dofind
390 pack .ctop.top.bar.findbut -side left
391 set findstring {}
df3d83b1 392 set fstring .ctop.top.bar.findstring
887fe3c4 393 lappend entries $fstring
df3d83b1 394 entry $fstring -width 30 -font $textfont -textvariable findstring
df3d83b1 395 pack $fstring -side left -expand 1 -fill x
98f350e5 396 set findtype Exact
b74fd579
PM
397 set findtypemenu [tk_optionMenu .ctop.top.bar.findtype \
398 findtype Exact IgnCase Regexp]
98f350e5
PM
399 set findloc "All fields"
400 tk_optionMenu .ctop.top.bar.findloc findloc "All fields" Headline \
b74fd579 401 Comments Author Committer Files Pickaxe
98f350e5
PM
402 pack .ctop.top.bar.findloc -side right
403 pack .ctop.top.bar.findtype -side right
b74fd579
PM
404 # for making sure type==Exact whenever loc==Pickaxe
405 trace add variable findloc write findlocchange
b5721c72 406
5ad588de
PM
407 panedwindow .ctop.cdet -orient horizontal
408 .ctop add .ctop.cdet
d2610d11
PM
409 frame .ctop.cdet.left
410 set ctext .ctop.cdet.left.ctext
0fba86b3
PM
411 text $ctext -bg white -state disabled -font $textfont \
412 -width $geometry(ctextw) -height $geometry(ctexth) \
b1ba39e7 413 -yscrollcommand ".ctop.cdet.left.sb set" -wrap none
d2610d11
PM
414 scrollbar .ctop.cdet.left.sb -command "$ctext yview"
415 pack .ctop.cdet.left.sb -side right -fill y
416 pack $ctext -side left -fill both -expand 1
417 .ctop.cdet add .ctop.cdet.left
418
f0654861 419 $ctext tag conf filesep -font [concat $textfont bold] -back "#aaaaaa"
712fcc08
PM
420 $ctext tag conf hunksep -fore blue
421 $ctext tag conf d0 -fore red
422 $ctext tag conf d1 -fore "#00a000"
423 $ctext tag conf m0 -fore red
424 $ctext tag conf m1 -fore blue
425 $ctext tag conf m2 -fore green
426 $ctext tag conf m3 -fore purple
427 $ctext tag conf m4 -fore brown
428 $ctext tag conf mmax -fore darkgrey
429 set mergemax 5
430 $ctext tag conf mresult -font [concat $textfont bold]
431 $ctext tag conf msep -font [concat $textfont bold]
432 $ctext tag conf found -back yellow
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
712fcc08 533 global stuffsaved findmergefiles 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]
8d858d1a 543 puts $f [list set maxgraphpct $maxgraphpct]
04c13d38 544 puts $f [list set maxwidth $maxwidth]
0fba86b3
PM
545 puts $f "set geometry(width) [winfo width .ctop]"
546 puts $f "set geometry(height) [winfo height .ctop]"
2ed49d54
JH
547 puts $f "set geometry(canv1) [expr {[winfo width $canv]-2}]"
548 puts $f "set geometry(canv2) [expr {[winfo width $canv2]-2}]"
549 puts $f "set geometry(canv3) [expr {[winfo width $canv3]-2}]"
550 puts $f "set geometry(canvh) [expr {[winfo height $canv]-2}]"
0fba86b3
PM
551 set wid [expr {([winfo width $ctext] - 8) \
552 / [font measure $textfont "0"]}]
0fba86b3 553 puts $f "set geometry(ctextw) $wid"
0fba86b3
PM
554 set wid [expr {([winfo width $cflist] - 11) \
555 / [font measure [$cflist cget -font] "0"]}]
556 puts $f "set geometry(cflistw) $wid"
557 close $f
558 file rename -force "~/.gitk-new" "~/.gitk"
559 }
560 set stuffsaved 1
1db95b00
PM
561}
562
43bddeb4
PM
563proc resizeclistpanes {win w} {
564 global oldwidth
565 if [info exists oldwidth($win)] {
566 set s0 [$win sash coord 0]
567 set s1 [$win sash coord 1]
568 if {$w < 60} {
569 set sash0 [expr {int($w/2 - 2)}]
570 set sash1 [expr {int($w*5/6 - 2)}]
571 } else {
572 set factor [expr {1.0 * $w / $oldwidth($win)}]
573 set sash0 [expr {int($factor * [lindex $s0 0])}]
574 set sash1 [expr {int($factor * [lindex $s1 0])}]
575 if {$sash0 < 30} {
576 set sash0 30
577 }
578 if {$sash1 < $sash0 + 20} {
2ed49d54 579 set sash1 [expr {$sash0 + 20}]
43bddeb4
PM
580 }
581 if {$sash1 > $w - 10} {
2ed49d54 582 set sash1 [expr {$w - 10}]
43bddeb4 583 if {$sash0 > $sash1 - 20} {
2ed49d54 584 set sash0 [expr {$sash1 - 20}]
43bddeb4
PM
585 }
586 }
587 }
588 $win sash place 0 $sash0 [lindex $s0 1]
589 $win sash place 1 $sash1 [lindex $s1 1]
590 }
591 set oldwidth($win) $w
592}
593
594proc resizecdetpanes {win w} {
595 global oldwidth
596 if [info exists oldwidth($win)] {
597 set s0 [$win sash coord 0]
598 if {$w < 60} {
599 set sash0 [expr {int($w*3/4 - 2)}]
600 } else {
601 set factor [expr {1.0 * $w / $oldwidth($win)}]
602 set sash0 [expr {int($factor * [lindex $s0 0])}]
603 if {$sash0 < 45} {
604 set sash0 45
605 }
606 if {$sash0 > $w - 15} {
2ed49d54 607 set sash0 [expr {$w - 15}]
43bddeb4
PM
608 }
609 }
610 $win sash place 0 $sash0 [lindex $s0 1]
611 }
612 set oldwidth($win) $w
613}
614
b5721c72
PM
615proc allcanvs args {
616 global canv canv2 canv3
617 eval $canv $args
618 eval $canv2 $args
619 eval $canv3 $args
620}
621
622proc bindall {event action} {
623 global canv canv2 canv3
624 bind $canv $event $action
625 bind $canv2 $event $action
626 bind $canv3 $event $action
627}
628
9a40c50c
PM
629proc about {} {
630 set w .about
631 if {[winfo exists $w]} {
632 raise $w
633 return
634 }
635 toplevel $w
636 wm title $w "About gitk"
637 message $w.m -text {
c8dfbcf9 638Gitk version 1.2
9a40c50c
PM
639
640