@matheusbsbs / matheus-bagliano / commits / b4946930fa
Fork 0

git-gui: Make use of the Tk font system rather than faking it.

The native Tk font system is actually quite powerful and has the nice property that modifications to a named font are immediately reflected throughout all widgets currently displayed. This really saves us from needing to write all of the reconfigure code as part of our font display. I also fixed the way we detect and apply the system font on the main UI widgets as although it worked on a Windows 2000 system it does not work at all on my Mac OS 10.4 system. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Nov 12, 2006 at 00:40 UTC b4946930fa0f7aa538e33f1d799beffb7e10e7a9
1 file changed +92 -100
git-gui
+92 -100
@@ -39,7 +39,6 @@ proc load_repo_config {} {
39 proc save_my_config {} {
40 global repo_config
41 global cfg_trust_mtime
42 - global font_diff
42
43 if {[catch {set rc_trustMTime $repo_config(gui.trustmtime)}]} {
44 set rc_trustMTime [list false]
@@ -49,14 +48,6 @@ proc save_my_config {} {
48 set repo_config(gui.trustmtime) [list $cfg_trust_mtime]
49 }
50
52 - if {[catch {set rc_fontdiff $repo_config(gui.fontdiff)}]} {
53 - set rc_fontdiff [list {Courier 10}]
54 - }
55 - if {$font_diff != [lindex $rc_fontdiff 0]} {
56 - exec git repo-config --global gui.fontDiff $font_diff
57 - set repo_config(gui.fontdiff) [list $font_diff]
58 - }
59 -
51 set cfg_geometry [wm geometry .]
52 append cfg_geometry " [lindex [.vpane sash coord 0] 1]"
53 append cfg_geometry " [lindex [.vpane.files sash coord 0] 0]"
@@ -1134,17 +1125,17 @@ proc load_all_remotes {} {
1125 }
1126
1127 proc populate_remote_menu {m pfx op} {
1137 - global all_remotes font_ui
1128 + global all_remotes
1129
1130 foreach remote $all_remotes {
1131 $m add command -label "$pfx $remote..." \
1132 -command [list $op $remote] \
1142 - -font $font_ui
1133 + -font font_ui
1134 }
1135 }
1136
1137 proc populate_pull_menu {m} {
1147 - global gitdir repo_config all_remotes font_ui disable_on_lock
1138 + global gitdir repo_config all_remotes disable_on_lock
1139
1140 foreach remote $all_remotes {
1141 set rb {}
@@ -1172,7 +1163,7 @@ proc populate_pull_menu {m} {
1163 $m add command \
1164 -label "Branch $rb_short from $remote..." \
1165 -command [list pull_remote $remote $rb] \
1175 - -font $font_ui
1166 + -font font_ui
1167 lappend disable_on_lock \
1168 [list $m entryconf [$m index last] -state]
1169 }
@@ -1294,8 +1285,15 @@ unset filemask i
1285 ##
1286 ## util
1287
1288 +proc incr_font_size {font {amt 1}} {
1289 + set sz [font configure $font -size]
1290 + incr sz $amt
1291 + font configure $font -size $sz
1292 + font configure ${font}bold -size $sz
1293 +}
1294 +
1295 proc hook_failed_popup {hook msg} {
1298 - global gitdir font_ui font_diff appname
1296 + global gitdir appname
1297
1298 set w .hookfail
1299 toplevel $w
@@ -1305,18 +1303,18 @@ proc hook_failed_popup {hook msg} {
1303 label $w.m.l1 -text "$hook hook failed:" \
1304 -anchor w \
1305 -justify left \
1308 - -font [concat $font_ui bold]
1306 + -font font_uibold
1307 text $w.m.t \
1308 -background white -borderwidth 1 \
1309 -relief sunken \
1310 -width 80 -height 10 \
1313 - -font $font_diff \
1311 + -font font_diff \
1312 -yscrollcommand [list $w.m.sby set]
1313 label $w.m.l2 \
1314 -text {You must correct the above errors before committing.} \
1315 -anchor w \
1316 -justify left \
1319 - -font [concat $font_ui bold]
1317 + -font font_uibold
1318 scrollbar $w.m.sby -command [list $w.m.t yview]
1319 pack $w.m.l1 -side top -fill x
1320 pack $w.m.l2 -side bottom -fill x
@@ -1329,7 +1327,7 @@ proc hook_failed_popup {hook msg} {
1327
1328 button $w.ok -text OK \
1329 -width 15 \
1332 - -font $font_ui \
1330 + -font font_ui \
1331 -command "destroy $w"
1332 pack $w.ok -side bottom
1333
@@ -1352,7 +1350,7 @@ proc new_console {short_title long_title} {
1350
1351 proc console_init {w} {
1352 global console_cr console_data
1355 - global gitdir appname font_ui font_diff M1B
1353 + global gitdir appname M1B
1354
1355 set console_cr($w) 1.0
1356 toplevel $w
@@ -1360,17 +1358,17 @@ proc console_init {w} {
1358 label $w.m.l1 -text "[lindex $console_data($w) 1]:" \
1359 -anchor w \
1360 -justify left \
1363 - -font [concat $font_ui bold]
1361 + -font font_uibold
1362 text $w.m.t \
1363 -background white -borderwidth 1 \
1364 -relief sunken \
1365 -width 80 -height 10 \
1368 - -font $font_diff \
1366 + -font font_diff \
1367 -state disabled \
1368 -yscrollcommand [list $w.m.sby set]
1369 label $w.m.s -anchor w \
1370 -justify left \
1373 - -font [concat $font_ui bold]
1371 + -font font_uibold
1372 scrollbar $w.m.sby -command [list $w.m.t yview]
1373 pack $w.m.l1 -side top -fill x
1374 pack $w.m.s -side bottom -fill x
@@ -1380,13 +1378,13 @@ proc console_init {w} {
1378
1379 menu $w.ctxm -tearoff 0
1380 $w.ctxm add command -label "Copy" \
1383 - -font $font_ui \
1381 + -font font_ui \
1382 -command "tk_textCopy $w.m.t"
1383 $w.ctxm add command -label "Select All" \
1386 - -font $font_ui \
1384 + -font font_ui \
1385 -command "$w.m.t tag add sel 0.0 end"
1386 $w.ctxm add command -label "Copy All" \
1389 - -font $font_ui \
1387 + -font font_ui \
1388 -command "
1389 $w.m.t tag add sel 0.0 end
1390 tk_textCopy $w.m.t
@@ -1395,7 +1393,7 @@ proc console_init {w} {
1393
1394 button $w.ok -text {Running...} \
1395 -width 15 \
1398 - -font $font_ui \
1396 + -font font_ui \
1397 -state disabled \
1398 -command "destroy $w"
1399 pack $w.ok -side bottom
@@ -1643,16 +1641,19 @@ proc unclick {w x y} {
1641 ##
1642 ## ui init
1643
1646 -set font_ui {}
1647 -set font_diff {}
1648 -set cursor_ptr {}
1649 -menu .mbar -tearoff 0
1650 -catch {set font_ui [lindex $repo_config(gui.fontui) 0]}
1651 -catch {set font_diff [lindex $repo_config(gui.fontdiff) 0]}
1652 -if {$font_ui == {}} {catch {set font_ui [.mbar cget -font]}}
1653 -if {$font_ui == {}} {set font_ui {Helvetica 10}}
1654 -if {$font_diff == {}} {set font_diff {Courier 10}}
1655 -if {$cursor_ptr == {}} {set cursor_ptr left_ptr}
1644 +set cursor_ptr left_ptr
1645 +font create font_diff -family Courier -size 10
1646 +font create font_ui
1647 +catch {
1648 + label .dummy
1649 + eval font configure font_ui [font actual [.dummy cget -font]]
1650 + destroy .dummy
1651 +}
1652 +
1653 +eval font create font_uibold [font configure font_ui]
1654 +font configure font_uibold -weight bold
1655 +eval font create font_diffbold [font configure font_diff]
1656 +font configure font_diffbold -weight bold
1657
1658 switch -glob -- "$tcl_platform(platform),$tcl_platform(os)" {
1659 windows,* {set M1B Control; set M1T Ctrl}
@@ -1661,6 +1662,7 @@ unix,Darwin {set M1B M1; set M1T Cmd}
1662 }
1663
1664 # -- Menu Bar
1665 +menu .mbar -tearoff 0
1666 .mbar add cascade -label Project -menu .mbar.project
1667 .mbar add cascade -label Edit -menu .mbar.edit
1668 .mbar add cascade -label Commit -menu .mbar.commit
@@ -1674,14 +1676,14 @@ unix,Darwin {set M1B M1; set M1T Cmd}
1676 menu .mbar.project
1677 .mbar.project add command -label Visualize \
1678 -command do_gitk \
1677 - -font $font_ui
1679 + -font font_ui
1680 .mbar.project add command -label {Repack Database} \
1681 -command do_repack \
1680 - -font $font_ui
1682 + -font font_ui
1683 .mbar.project add command -label Quit \
1684 -command do_quit \
1685 -accelerator $M1T-Q \
1684 - -font $font_ui
1686 + -font font_ui
1687
1688 # -- Edit Menu
1689 #
@@ -1689,61 +1691,61 @@ menu .mbar.edit
1691 .mbar.edit add command -label Undo \
1692 -command {catch {[focus] edit undo}} \
1693 -accelerator $M1T-Z \
1692 - -font $font_ui
1694 + -font font_ui
1695 .mbar.edit add command -label Redo \
1696 -command {catch {[focus] edit redo}} \
1697 -accelerator $M1T-Y \
1696 - -font $font_ui
1698 + -font font_ui
1699 .mbar.edit add separator
1700 .mbar.edit add command -label Cut \
1701 -command {catch {tk_textCut [focus]}} \
1702 -accelerator $M1T-X \
1701 - -font $font_ui
1703 + -font font_ui
1704 .mbar.edit add command -label Copy \
1705 -command {catch {tk_textCopy [focus]}} \
1706 -accelerator $M1T-C \
1705 - -font $font_ui
1707 + -font font_ui
1708 .mbar.edit add command -label Paste \
1709 -command {catch {tk_textPaste [focus]; [focus] see insert}} \
1710 -accelerator $M1T-V \
1709 - -font $font_ui
1711 + -font font_ui
1712 .mbar.edit add command -label Delete \
1713 -command {catch {[focus] delete sel.first sel.last}} \
1714 -accelerator Del \
1713 - -font $font_ui
1715 + -font font_ui
1716 .mbar.edit add separator
1717 .mbar.edit add command -label {Select All} \
1718 -command {catch {[focus] tag add sel 0.0 end}} \
1719 -accelerator $M1T-A \
1718 - -font $font_ui
1720 + -font font_ui
1721
1722 # -- Commit Menu
1723 menu .mbar.commit
1724 .mbar.commit add command -label Rescan \
1725 -command do_rescan \
1726 -accelerator F5 \
1725 - -font $font_ui
1727 + -font font_ui
1728 lappend disable_on_lock \
1729 [list .mbar.commit entryconf [.mbar.commit index last] -state]
1730 .mbar.commit add command -label {Amend Last Commit} \
1731 -command do_amend_last \
1730 - -font $font_ui
1732 + -font font_ui
1733 lappend disable_on_lock \
1734 [list .mbar.commit entryconf [.mbar.commit index last] -state]
1735 .mbar.commit add command -label {Include All Files} \
1736 -command do_include_all \
1737 -accelerator $M1T-I \
1736 - -font $font_ui
1738 + -font font_ui
1739 lappend disable_on_lock \
1740 [list .mbar.commit entryconf [.mbar.commit index last] -state]
1741 .mbar.commit add command -label {Sign Off} \
1742 -command do_signoff \
1743 -accelerator $M1T-S \
1742 - -font $font_ui
1744 + -font font_ui
1745 .mbar.commit add command -label Commit \
1746 -command do_commit \
1747 -accelerator $M1T-Return \
1746 - -font $font_ui
1748 + -font font_ui
1749 lappend disable_on_lock \
1750 [list .mbar.commit entryconf [.mbar.commit index last] -state]
1751
@@ -1760,7 +1762,7 @@ menu .mbar.push
1762 menu .mbar.options
1763 .mbar.options add checkbutton \
1764 -label {Trust File Modification Timestamps} \
1763 - -font $font_ui \
1765 + -font font_ui \
1766 -offvalue false \
1767 -onvalue true \
1768 -variable cfg_trust_mtime
@@ -1775,10 +1777,10 @@ pack .vpane -anchor n -side top -fill both -expand 1
1777 frame .vpane.files.index -height 100 -width 400
1778 label .vpane.files.index.title -text {Modified Files} \
1779 -background green \
1778 - -font $font_ui
1780 + -font font_ui
1781 text $ui_index -background white -borderwidth 0 \
1782 -width 40 -height 10 \
1781 - -font $font_ui \
1783 + -font font_ui \
1784 -cursor $cursor_ptr \
1785 -yscrollcommand {.vpane.files.index.sb set} \
1786 -state disabled
@@ -1792,10 +1794,10 @@ pack $ui_index -side left -fill both -expand 1
1794 frame .vpane.files.other -height 100 -width 100
1795 label .vpane.files.other.title -text {Untracked Files} \
1796 -background red \
1795 - -font $font_ui
1797 + -font font_ui
1798 text $ui_other -background white -borderwidth 0 \
1799 -width 40 -height 10 \
1798 - -font $font_ui \
1800 + -font font_ui \
1801 -cursor $cursor_ptr \
1802 -yscrollcommand {.vpane.files.other.sb set} \
1803 -state disabled
@@ -1805,8 +1807,8 @@ pack .vpane.files.other.sb -side right -fill y
1807 pack $ui_other -side left -fill both -expand 1
1808 .vpane.files add .vpane.files.other -sticky nsew
1809
1808 -$ui_index tag conf in_diff -font [concat $font_ui bold]
1809 -$ui_other tag conf in_diff -font [concat $font_ui bold]
1810 +$ui_index tag conf in_diff -font font_uibold
1811 +$ui_other tag conf in_diff -font font_uibold
1812
1813 # -- Diff and Commit Area
1814 frame .vpane.lower -height 400 -width 400
@@ -1821,39 +1823,39 @@ frame .vpane.lower.commarea.buttons
1823 label .vpane.lower.commarea.buttons.l -text {} \
1824 -anchor w \
1825 -justify left \
1824 - -font $font_ui
1826 + -font font_ui
1827 pack .vpane.lower.commarea.buttons.l -side top -fill x
1828 pack .vpane.lower.commarea.buttons -side left -fill y
1829
1830 button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
1831 -command do_rescan \
1830 - -font $font_ui
1832 + -font font_ui
1833 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
1834 lappend disable_on_lock \
1835 {.vpane.lower.commarea.buttons.rescan conf -state}
1836
1837 button .vpane.lower.commarea.buttons.amend -text {Amend Last} \
1838 -command do_amend_last \
1837 - -font $font_ui
1839 + -font font_ui
1840 pack .vpane.lower.commarea.buttons.amend -side top -fill x
1841 lappend disable_on_lock \
1842 {.vpane.lower.commarea.buttons.amend conf -state}
1843
1844 button .vpane.lower.commarea.buttons.incall -text {Include All} \
1845 -command do_include_all \
1844 - -font $font_ui
1846 + -font font_ui
1847 pack .vpane.lower.commarea.buttons.incall -side top -fill x
1848 lappend disable_on_lock \
1849 {.vpane.lower.commarea.buttons.incall conf -state}
1850
1851 button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
1852 -command do_signoff \
1851 - -font $font_ui
1853 + -font font_ui
1854 pack .vpane.lower.commarea.buttons.signoff -side top -fill x
1855
1856 button .vpane.lower.commarea.buttons.commit -text {Commit} \
1857 -command do_commit \
1856 - -font $font_ui
1858 + -font font_ui
1859 pack .vpane.lower.commarea.buttons.commit -side top -fill x
1860 lappend disable_on_lock \
1861 {.vpane.lower.commarea.buttons.commit conf -state}
@@ -1865,7 +1867,7 @@ set ui_coml .vpane.lower.commarea.buffer.l
1867 label $ui_coml -text {Commit Message:} \
1868 -anchor w \
1869 -justify left \
1868 - -font $font_ui
1870 + -font font_ui
1871 trace add variable commit_type write {uplevel #0 {
1872 switch -glob $commit_type \
1873 initial {$ui_coml conf -text {Initial Commit Message:}} \
@@ -1879,7 +1881,7 @@ text $ui_comm -background white -borderwidth 1 \
1881 -autoseparators true \
1882 -relief sunken \
1883 -width 75 -height 9 -wrap none \
1882 - -font $font_diff \
1884 + -font font_diff \
1885 -yscrollcommand {.vpane.lower.commarea.buffer.sby set}
1886 scrollbar .vpane.lower.commarea.buffer.sby \
1887 -command [list $ui_comm yview]
@@ -1892,23 +1894,23 @@ pack .vpane.lower.commarea.buffer -side left -fill y
1894 #
1895 menu $ui_comm.ctxm -tearoff 0
1896 $ui_comm.ctxm add command -label "Cut" \
1895 - -font $font_ui \
1897 + -font font_ui \
1898 -command "tk_textCut $ui_comm"
1899 $ui_comm.ctxm add command -label "Copy" \
1898 - -font $font_ui \
1900 + -font font_ui \
1901 -command "tk_textCopy $ui_comm"
1902 $ui_comm.ctxm add command -label "Paste" \
1901 - -font $font_ui \
1903 + -font font_ui \
1904 -command "tk_textPaste $ui_comm"
1905 $ui_comm.ctxm add command -label "Delete" \
1904 - -font $font_ui \
1906 + -font font_ui \
1907 -command "$ui_comm delete sel.first sel.last"
1908 $ui_comm.ctxm add separator
1909 $ui_comm.ctxm add command -label "Select All" \
1908 - -font $font_ui \
1910 + -font font_ui \
1911 -command "$ui_comm tag add sel 0.0 end"
1912 $ui_comm.ctxm add command -label "Copy All" \
1911 - -font $font_ui \
1913 + -font font_ui \
1914 -command "
1915 $ui_comm tag add sel 0.0 end
1916 tk_textCopy $ui_comm
@@ -1916,7 +1918,7 @@ $ui_comm.ctxm add command -label "Copy All" \
1918 "
1919 $ui_comm.ctxm add separator
1920 $ui_comm.ctxm add command -label "Sign Off" \
1919 - -font $font_ui \
1921 + -font font_ui \
1922 -command do_signoff
1923 bind $ui_comm <Any-Button-3> "tk_popup $ui_comm.ctxm %X %Y"
1924
@@ -1926,21 +1928,21 @@ set ui_fstatus_value {}
1928 frame .vpane.lower.diff.header -background orange
1929 label .vpane.lower.diff.header.l1 -text {File:} \
1930 -background orange \
1929 - -font $font_ui
1931 + -font font_ui
1932 label .vpane.lower.diff.header.l2 -textvariable ui_fname_value \
1933 -background orange \
1934 -anchor w \
1935 -justify left \
1934 - -font $font_ui
1936 + -font font_ui
1937 label .vpane.lower.diff.header.l3 -text {Status:} \
1938 -background orange \
1937 - -font $font_ui
1939 + -font font_ui
1940 label .vpane.lower.diff.header.l4 -textvariable ui_fstatus_value \
1941 -background orange \
1942 -width $max_status_desc \
1943 -anchor w \
1944 -justify left \
1943 - -font $font_ui
1945 + -font font_ui
1946 pack .vpane.lower.diff.header.l1 -side left
1947 pack .vpane.lower.diff.header.l2 -side left -fill x
1948 pack .vpane.lower.diff.header.l4 -side right
@@ -1951,7 +1953,7 @@ frame .vpane.lower.diff.body
1953 set ui_diff .vpane.lower.diff.body.t
1954 text $ui_diff -background white -borderwidth 0 \
1955 -width 80 -height 15 -wrap none \
1954 - -font $font_diff \
1956 + -font font_diff \
1957 -xscrollcommand {.vpane.lower.diff.body.sbx set} \
1958 -yscrollcommand {.vpane.lower.diff.body.sby set} \
1959 -state disabled
@@ -1967,22 +1969,22 @@ pack .vpane.lower.diff.body -side bottom -fill both -expand 1
1969
1970 $ui_diff tag conf dm -foreground red
1971 $ui_diff tag conf dp -foreground blue
1970 -$ui_diff tag conf di -foreground "#00a000"
1971 -$ui_diff tag conf dni -foreground "#a000a0"
1972 -$ui_diff tag conf da -font [concat $font_diff bold]
1973 -$ui_diff tag conf bold -font [concat $font_diff bold]
1972 +$ui_diff tag conf di -foreground {#00a000}
1973 +$ui_diff tag conf dni -foreground {#a000a0}
1974 +$ui_diff tag conf da -font font_diffbold
1975 +$ui_diff tag conf bold -font font_diffbold
1976
1977 # -- Diff Body Context Menu
1978 #
1979 menu $ui_diff.ctxm -tearoff 0
1980 $ui_diff.ctxm add command -label "Copy" \
1979 - -font $font_ui \
1981 + -font font_ui \
1982 -command "tk_textCopy $ui_diff"
1983 $ui_diff.ctxm add command -label "Select All" \
1982 - -font $font_ui \
1984 + -font font_ui \
1985 -command "$ui_diff tag add sel 0.0 end"
1986 $ui_diff.ctxm add command -label "Copy All" \
1985 - -font $font_ui \
1987 + -font font_ui \
1988 -command "
1989 $ui_diff tag add sel 0.0 end
1990 tk_textCopy $ui_diff
@@ -1990,21 +1992,11 @@ $ui_diff.ctxm add command -label "Copy All" \
1992 "
1993 $ui_diff.ctxm add separator
1994 $ui_diff.ctxm add command -label "Decrease Font Size" \
1993 - -font $font_ui \
1994 - -command {
1995 - lset font_diff 1 [expr [lindex $font_diff 1] - 1]
1996 - $ui_diff configure -font $font_diff
1997 - $ui_diff tag conf da -font [concat $font_diff bold]
1998 - $ui_diff tag conf bold -font [concat $font_diff bold]
1999 - }
1995 + -font font_ui \
1996 + -command {incr_font_size font_diff -1}
1997 $ui_diff.ctxm add command -label "Increase Font Size" \
2001 - -font $font_ui \
2002 - -command {
2003 - lset font_diff 1 [expr [lindex $font_diff 1] + 1]
2004 - $ui_diff configure -font $font_diff
2005 - $ui_diff tag conf da -font [concat $font_diff bold]
2006 - $ui_diff tag conf bold -font [concat $font_diff bold]
2007 - }
1998 + -font font_ui \
1999 + -command {incr_font_size font_diff 1}
2000 bind $ui_diff <Any-Button-3> "tk_popup $ui_diff.ctxm %X %Y"
2001
2002 # -- Status Bar
@@ -2014,7 +2006,7 @@ label .status -textvariable ui_status_value \
2006 -justify left \
2007 -borderwidth 1 \
2008 -relief sunken \
2017 - -font $font_ui
2009 + -font font_ui
2010 pack .status -anchor w -side bottom -fill x
2011
2012 # -- Load geometry