gitk: Add a preferences dialog with some basic stuff
There is a lot more that could be put in, such as a selector for the font family etc., but this is a start. Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
Nov 30, 2005 at 09:28 UTC
712fcc08c7a2d338f9480033597ad62223c657ec
1 file changed
+88
-54
gitk
+88
-54
@@ -297,13 +297,16 @@ proc makewindow {} {
297
global findtype findtypemenu findloc findstring fstring geometry
298
global entries sha1entry sha1string sha1but
299
global maincursor textcursor curtextcursor
300
- global rowctxmenu gaudydiff mergemax
300
+ global rowctxmenu mergemax
301
302
menu .bar
303
.bar add cascade -label "File" -menu .bar.file
304
menu .bar.file
305
.bar.file add command -label "Reread references" -command rereadrefs
306
.bar.file add command -label "Quit" -command doquit
307
+ menu .bar.edit
308
+ .bar add cascade -label "Edit" -menu .bar.edit
309
+ .bar.edit add command -label "Preferences" -command doprefs
310
menu .bar.help
311
.bar add cascade -label "Help" -menu .bar.help
312
.bar.help add command -label "About gitk" -command about
@@ -414,25 +417,19 @@ proc makewindow {} {
417
.ctop.cdet add .ctop.cdet.left
418
419
$ctext tag conf filesep -font [concat $textfont bold] -back "#aaaaaa"
417
- if {$gaudydiff} {
418
- $ctext tag conf hunksep -back blue -fore white
419
- $ctext tag conf d0 -back "#ff8080"
420
- $ctext tag conf d1 -back green
421
- } else {
422
- $ctext tag conf hunksep -fore blue
423
- $ctext tag conf d0 -fore red
424
- $ctext tag conf d1 -fore "#00a000"
425
- $ctext tag conf m0 -fore red
426
- $ctext tag conf m1 -fore blue
427
- $ctext tag conf m2 -fore green
428
- $ctext tag conf m3 -fore purple
429
- $ctext tag conf m4 -fore brown
430
- $ctext tag conf mmax -fore darkgrey
431
- set mergemax 5
432
- $ctext tag conf mresult -font [concat $textfont bold]
433
- $ctext tag conf msep -font [concat $textfont bold]
434
- $ctext tag conf found -back yellow
435
- }
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
433
434
frame .ctop.cdet.right
435
set cflist .ctop.cdet.right.cfiles
@@ -533,7 +530,7 @@ proc click {w} {
530
531
proc savestuff {w} {
532
global canv canv2 canv3 ctext cflist mainfont textfont
536
- global stuffsaved findmergefiles gaudydiff maxgraphpct
533
+ global stuffsaved findmergefiles maxgraphpct
534
global maxwidth
535
536
if {$stuffsaved} return
@@ -543,7 +540,6 @@ proc savestuff {w} {
540
puts $f [list set mainfont $mainfont]
541
puts $f [list set textfont $textfont]
542
puts $f [list set findmergefiles $findmergefiles]
546
- puts $f [list set gaudydiff $gaudydiff]
543
puts $f [list set maxgraphpct $maxgraphpct]
544
puts $f [list set maxwidth $maxwidth]
545
puts $f "set geometry(width) [winfo width .ctop]"
@@ -2841,7 +2837,6 @@ proc getblobdiffline {bdf ids} {
2837
global diffids blobdifffd ctext curdifftag curtagstart
2838
global diffnexthead diffnextnote difffilestart
2839
global nextupdate diffinhdr treediffs
2844
- global gaudydiff
2840
2841
set n [gets $bdf line]
2842
if {$n < 0} {
@@ -2890,26 +2885,14 @@ proc getblobdiffline {bdf ids} {
2885
set diffinhdr 0
2886
} elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
2887
$line match f1l f1c f2l f2c rest]} {
2893
- if {$gaudydiff} {
2894
- $ctext insert end "\t" hunksep
2895
- $ctext insert end " $f1l " d0 " $f2l " d1
2896
- $ctext insert end " $rest \n" hunksep
2897
- } else {
2898
- $ctext insert end "$line\n" hunksep
2899
- }
2888
+ $ctext insert end "$line\n" hunksep
2889
set diffinhdr 0
2890
} else {
2891
set x [string range $line 0 0]
2892
if {$x == "-" || $x == "+"} {
2893
set tag [expr {$x == "+"}]
2905
- if {$gaudydiff} {
2906
- set line [string range $line 1 end]
2907
- }
2894
$ctext insert end "$line\n" d$tag
2895
} elseif {$x == " "} {
2910
- if {$gaudydiff} {
2911
- set line [string range $line 1 end]
2912
- }
2896
$ctext insert end "$line\n"
2897
} elseif {$diffinhdr || $x == "\\"} {
2898
# e.g. "\ No newline at end of file"
@@ -3634,26 +3617,80 @@ proc doquit {} {
3617
destroy .
3618
}
3619
3637
-proc formatdate {d} {
3638
- global hours nhours tfd fastdate
3620
+proc doprefs {} {
3621
+ global maxwidth maxgraphpct diffopts findmergefiles
3622
+ global oldprefs prefstop
3623
3640
- if {!$fastdate} {
3641
- return [clock format $d -format "%Y-%m-%d %H:%M:%S"]
3624
+ set top .gitkprefs
3625
+ set prefstop $top
3626
+ if {[winfo exists $top]} {
3627
+ raise $top
3628
+ return
3629
}
3643
- set hr [expr {$d / 3600}]
3644
- set ms [expr {$d % 3600}]
3645
- if {![info exists hours($hr)]} {
3646
- set hours($hr) [clock format $d -format "%Y-%m-%d %H"]
3647
- set nhours($hr) 0
3630
+ foreach v {maxwidth maxgraphpct diffopts findmergefiles} {
3631
+ set oldprefs($v) [set $v]
3632
}
3649
- incr nhours($hr)
3650
- set minsec [format "%.2d:%.2d" [expr {$ms/60}] [expr {$ms%60}]]
3651
- return "$hours($hr):$minsec"
3633
+ toplevel $top
3634
+ wm title $top "Gitk preferences"
3635
+ label $top.ldisp -text "Commit list display options"
3636
+ grid $top.ldisp - -sticky w -pady 10
3637
+ label $top.spacer -text " "
3638
+ label $top.maxwidthl -text "Maximum graph width (lines)" \
3639
+ -font optionfont
3640
+ spinbox $top.maxwidth -from 0 -to 100 -width 4 -textvariable maxwidth
3641
+ grid $top.spacer $top.maxwidthl $top.maxwidth -sticky w
3642
+ label $top.maxpctl -text "Maximum graph width (% of pane)" \
3643
+ -font optionfont
3644
+ spinbox $top.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
3645
+ grid x $top.maxpctl $top.maxpct -sticky w
3646
+ checkbutton $top.findm -variable findmergefiles
3647
+ label $top.findml -text "Include merges for \"Find\" in \"Files\"" \
3648
+ -font optionfont
3649
+ grid $top.findm $top.findml - -sticky w
3650
+ label $top.ddisp -text "Diff display options"
3651
+ grid $top.ddisp - -sticky w -pady 10
3652
+ label $top.diffoptl -text "Options for diff program" \
3653
+ -font optionfont
3654
+ entry $top.diffopt -width 20 -textvariable diffopts
3655
+ grid x $top.diffoptl $top.diffopt -sticky w
3656
+ frame $top.buts
3657
+ button $top.buts.ok -text "OK" -command prefsok
3658
+ button $top.buts.can -text "Cancel" -command prefscan
3659
+ grid $top.buts.ok $top.buts.can
3660
+ grid columnconfigure $top.buts 0 -weight 1 -uniform a
3661
+ grid columnconfigure $top.buts 1 -weight 1 -uniform a
3662
+ grid $top.buts - - -pady 10 -sticky ew
3663
+}
3664
+
3665
+proc prefscan {} {
3666
+ global maxwidth maxgraphpct diffopts findmergefiles
3667
+ global oldprefs prefstop
3668
+
3669
+ foreach v {maxwidth maxgraphpct diffopts findmergefiles} {
3670
+ set $v $oldprefs($v)
3671
+ }
3672
+ catch {destroy $prefstop}
3673
+ unset prefstop
3674
+}
3675
+
3676
+proc prefsok {} {
3677
+ global maxwidth maxgraphpct
3678
+ global oldprefs prefstop
3679
+
3680
+ catch {destroy $prefstop}
3681
+ unset prefstop
3682
+ if {$maxwidth != $oldprefs(maxwidth)
3683
+ || $maxgraphpct != $oldprefs(maxgraphpct)} {
3684
+ redisplay
3685
+ }
3686
+}
3687
+
3688
+proc formatdate {d} {
3689
+ return [clock format $d -format "%Y-%m-%d %H:%M:%S"]
3690
}
3691
3692
# defaults...
3693
set datemode 0
3656
-set boldnames 0
3694
set diffopts "-U 5 -p"
3695
set wrcomcmd "git-diff-tree --stdin -p --pretty"
3696
@@ -3668,7 +3705,6 @@ if {$gitencoding == ""} {
3705
set mainfont {Helvetica 9}
3706
set textfont {Courier 9}
3707
set findmergefiles 0
3671
-set gaudydiff 0
3708
set maxgraphpct 50
3709
set maxwidth 16
3710
set revlistorder 0
@@ -3679,15 +3715,13 @@ set colors {green red blue magenta darkgrey brown orange}
3715
catch {source ~/.gitk}
3716
3717
set namefont $mainfont
3682
-if {$boldnames} {
3683
- lappend namefont bold
3684
-}
3718
+
3719
+font create optionfont -family sans-serif -size -12
3720
3721
set revtreeargs {}
3722
foreach arg $argv {
3723
switch -regexp -- $arg {
3724
"^$" { }
3690
- "^-b" { set boldnames 1 }
3725
"^-d" { set datemode 1 }
3726
"^-r" { set revlistorder 1 }
3727
default {