git-gui: Allow the user to manipulate the fonts from the options panel.
This turned out to take a lot more time than I thought it would take; but now users can edit the main UI font and the diff/fixed with font by changing both the family name and/or the point size of the text. We save the complete Tk font specification to the user's ~/.gitconfig file upon saving options. This is probably more verbose than it needs to be as there are many useless options recorded (e.g. -overstrike 0) that a user won't really want to use in this application. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Nov 12, 2006 at 05:27 UTC
92148d8091d148e219b88e4d555a386ffa78f575
1 file changed
+124
-16
git-gui
+124
-16
@@ -14,8 +14,6 @@ set gitdir {}
14
##
15
## config
16
17
-set default_config(gui.trustmtime) false
18
-
17
proc is_many_config {name} {
18
switch -glob -- $name {
19
remote.*.fetch -
@@ -69,10 +67,25 @@ proc load_config {} {
67
}
68
69
proc save_config {} {
72
- global repo_config global_config default_config
70
+ global default_config font_descs
71
+ global repo_config global_config
72
global repo_config_new global_config_new
73
75
- foreach name [array names global_config_new] {
74
+ foreach option $font_descs {
75
+ set name [lindex $option 0]
76
+ set font [lindex $option 1]
77
+ font configure $font \
78
+ -family $global_config_new(gui.$font^^family) \
79
+ -size $global_config_new(gui.$font^^size)
80
+ font configure ${font}bold \
81
+ -family $global_config_new(gui.$font^^family) \
82
+ -size $global_config_new(gui.$font^^size)
83
+ set global_config_new(gui.$name) [font configure $font]
84
+ unset global_config_new(gui.$font^^family)
85
+ unset global_config_new(gui.$font^^size)
86
+ }
87
+
88
+ foreach name [array names default_config] {
89
set value $global_config_new($name)
90
if {$value != $global_config($name)} {
91
if {$value == $default_config($name)} {
@@ -88,7 +101,7 @@ proc save_config {} {
101
}
102
}
103
91
- foreach name [array names repo_config_new] {
104
+ foreach name [array names default_config] {
105
set value $repo_config_new($name)
106
if {$value != $repo_config($name)} {
107
if {$value == $global_config($name)} {
@@ -158,8 +171,6 @@ if {$appname == {git-citool}} {
171
set single_commit 1
172
}
173
161
-load_config
162
-
174
######################################################################
175
##
176
## task management
@@ -1680,7 +1691,7 @@ proc do_commit {} {
1691
}
1692
1693
proc do_options {} {
1683
- global appname gitdir
1694
+ global appname gitdir font_descs
1695
global repo_config global_config
1696
global repo_config_new global_config_new
1697
@@ -1702,19 +1713,25 @@ proc do_options {} {
1713
pack $w.header -side top -fill x
1714
1715
frame $w.buttons
1716
+ button $w.buttons.restore -text {Restore Defaults} \
1717
+ -font font_ui \
1718
+ -command do_restore_defaults
1719
+ pack $w.buttons.restore -side left
1720
button $w.buttons.save -text Save \
1721
-font font_ui \
1707
- -command "save_config; destroy $w"
1722
+ -command [list do_save_config $w]
1723
pack $w.buttons.save -side right
1724
button $w.buttons.cancel -text {Cancel} \
1725
-font font_ui \
1711
- -command "destroy $w"
1726
+ -command [list destroy $w]
1727
pack $w.buttons.cancel -side right
1713
- pack $w.buttons -side bottom -anchor e -pady 10 -padx 10
1728
+ pack $w.buttons -side bottom -fill x -pady 10 -padx 10
1729
1730
labelframe $w.repo -text {This Repository} \
1731
+ -font font_ui \
1732
-relief raised -borderwidth 2
1733
labelframe $w.global -text {Global (All Repositories)} \
1734
+ -font font_ui \
1735
-relief raised -borderwidth 2
1736
pack $w.repo -side left -fill both -expand 1 -pady 5 -padx 5
1737
pack $w.global -side right -fill both -expand 1 -pady 5 -padx 5
@@ -1734,6 +1751,33 @@ proc do_options {} {
1751
}
1752
}
1753
1754
+ set all_fonts [lsort [font families]]
1755
+ foreach option $font_descs {
1756
+ set name [lindex $option 0]
1757
+ set font [lindex $option 1]
1758
+ set text [lindex $option 2]
1759
+
1760
+ set global_config_new(gui.$font^^family) \
1761
+ [font configure $font -family]
1762
+ set global_config_new(gui.$font^^size) \
1763
+ [font configure $font -size]
1764
+
1765
+ frame $w.global.$name
1766
+ label $w.global.$name.l -text "$text:" -font font_ui
1767
+ pack $w.global.$name.l -side left -anchor w -fill x
1768
+ eval tk_optionMenu $w.global.$name.family \
1769
+ global_config_new(gui.$font^^family) \
1770
+ $all_fonts
1771
+ spinbox $w.global.$name.size \
1772
+ -textvariable global_config_new(gui.$font^^size) \
1773
+ -from 2 -to 80 -increment 1 \
1774
+ -width 3 \
1775
+ -font font_ui
1776
+ pack $w.global.$name.size -side right -anchor e
1777
+ pack $w.global.$name.family -side right -anchor e
1778
+ pack $w.global.$name -side top -anchor w -fill x
1779
+ }
1780
+
1781
bind $w <Visibility> "grab $w; focus $w"
1782
bind $w <Key-Escape> "destroy $w"
1783
wm title $w "$appname ([lindex [file split \
@@ -1742,6 +1786,38 @@ proc do_options {} {
1786
tkwait window $w
1787
}
1788
1789
+proc do_restore_defaults {} {
1790
+ global font_descs default_config
1791
+ global repo_config_new global_config_new
1792
+
1793
+ foreach name [array names default_config] {
1794
+ set repo_config_new($name) $default_config($name)
1795
+ set global_config_new($name) $default_config($name)
1796
+ }
1797
+
1798
+ foreach option $font_descs {
1799
+ set name [lindex $option 0]
1800
+ set repo_config($name) $default_config(gui.$name)
1801
+ }
1802
+ apply_config
1803
+
1804
+ foreach option $font_descs {
1805
+ set name [lindex $option 0]
1806
+ set font [lindex $option 1]
1807
+ set global_config_new(gui.$font^^family) \
1808
+ [font configure $font -family]
1809
+ set global_config_new(gui.$font^^size) \
1810
+ [font configure $font -size]
1811
+ }
1812
+}
1813
+
1814
+proc do_save_config {w} {
1815
+ if {[catch {save_config} err]} {
1816
+ error_popup "Failed to completely save options:\n\n$err"
1817
+ }
1818
+ destroy $w
1819
+}
1820
+
1821
# shift == 1: left click
1822
# 3: right click
1823
proc click {w x y shift wx wy} {
@@ -1774,7 +1850,7 @@ proc unclick {w x y} {
1850
1851
######################################################################
1852
##
1777
-## ui init
1853
+## config defaults
1854
1855
set cursor_ptr arrow
1856
font create font_diff -family Courier -size 10
@@ -1785,10 +1861,8 @@ catch {
1861
destroy .dummy
1862
}
1863
1788
-eval font create font_uibold [font configure font_ui]
1789
-font configure font_uibold -weight bold
1790
-eval font create font_diffbold [font configure font_diff]
1791
-font configure font_diffbold -weight bold
1864
+font create font_uibold
1865
+font create font_diffbold
1866
1867
set M1B M1
1868
set M1T M1
@@ -1800,6 +1874,40 @@ if {$tcl_platform(platform) == {windows}} {
1874
set M1T Cmd
1875
}
1876
1877
+proc apply_config {} {
1878
+ global repo_config font_descs
1879
+
1880
+ foreach option $font_descs {
1881
+ set name [lindex $option 0]
1882
+ set font [lindex $option 1]
1883
+ if {[catch {
1884
+ foreach {cn cv} $repo_config(gui.$name) {
1885
+ font configure $font $cn $cv
1886
+ }
1887
+ } err]} {
1888
+ error_popup "Invalid font specified in gui.$name:\n\n$err"
1889
+ }
1890
+ foreach {cn cv} [font configure $font] {
1891
+ font configure ${font}bold $cn $cv
1892
+ }
1893
+ font configure ${font}bold -weight bold
1894
+ }
1895
+}
1896
+
1897
+set default_config(gui.trustmtime) false
1898
+set default_config(gui.fontui) [font configure font_ui]
1899
+set default_config(gui.fontdiff) [font configure font_diff]
1900
+set font_descs {
1901
+ {fontui font_ui {Main Font}}
1902
+ {fontdiff font_diff {Diff/Console Font}}
1903
+}
1904
+load_config
1905
+apply_config
1906
+
1907
+######################################################################
1908
+##
1909
+## ui construction
1910
+
1911
# -- Menu Bar
1912
menu .mbar -tearoff 0
1913
.mbar add cascade -label Project -menu .mbar.project