1 # git-gui options editor
2 # Copyright (C) 2006, 2007 Shawn Pearce
5 global default_config font_descs
6 global repo_config global_config
7 global repo_config_new global_config_new
10 foreach option $font_descs {
11 set name [lindex $option 0]
12 set font [lindex $option 1]
13 font configure $font \
14 -family $global_config_new(gui.$font^^family) \
15 -size $global_config_new(gui.$font^^size)
16 font configure ${font}bold \
17 -family $global_config_new(gui.$font^^family) \
18 -size $global_config_new(gui.$font^^size)
19 font configure ${font}italic \
20 -family $global_config_new(gui.$font^^family) \
21 -size $global_config_new(gui.$font^^size)
22 set global_config_new(gui.$name) [font configure $font]
23 unset global_config_new(gui.$font^^family)
24 unset global_config_new(gui.$font^^size)
27 foreach name [array names default_config] {
28 set value $global_config_new($name)
29 if {$value ne $global_config($name)} {
30 if {$value eq $default_config($name)} {
31 catch {git config --global --unset $name}
33 regsub -all "\[{}\]" $value {"} value
34 git config --global $name $value
36 set global_config($name) $value
37 if {$value eq $repo_config($name)} {
38 catch {git config --unset $name}
39 set repo_config($name) $value
44 foreach name [array names default_config] {
45 set value $repo_config_new($name)
46 if {$value ne $repo_config($name)} {
47 if {$value eq $global_config($name)} {
48 catch {git config --unset $name}
50 regsub -all "\[{}\]" $value {"} value
51 git config $name $value
53 set repo_config($name) $value
57 if {[info exists repo_config(gui.spellingdictionary)]} {
58 set value $repo_config(gui.spellingdictionary)
59 if {$value eq {none}} {
60 if {[info exists ui_comm_spell]} {
63 } elseif {[info exists ui_comm_spell]} {
64 $ui_comm_spell lang $value
70 global repo_config global_config font_descs
71 global repo_config_new global_config_new
74 array unset repo_config_new
75 array unset global_config_new
76 foreach name [array names repo_config] {
77 set repo_config_new($name) $repo_config($name)
80 foreach name [array names repo_config] {
82 gui.diffcontext {continue}
84 set repo_config_new($name) $repo_config($name)
86 foreach name [array names global_config] {
87 set global_config_new($name) $global_config($name)
92 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
95 button $w.buttons.restore -text [mc "Restore Defaults"] \
97 -command do_restore_defaults
98 pack $w.buttons.restore -side left
99 button $w.buttons.save -text [mc Save] \
101 -command [list do_save_config $w]
102 pack $w.buttons.save -side right
103 button $w.buttons.cancel -text [mc "Cancel"] \
105 -command [list destroy $w]
106 pack $w.buttons.cancel -side right -padx 5
107 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
109 labelframe $w.repo -text [mc "%s Repository" [reponame]]
110 labelframe $w.global -text [mc "Global (All Repositories)"]
111 pack $w.repo -side left -fill both -expand 1 -pady 5 -padx 5
112 pack $w.global -side right -fill both -expand 1 -pady 5 -padx 5
116 {t user.name {mc "User Name"}}
117 {t user.email {mc "Email Address"}}
119 {b merge.summary {mc "Summarize Merge Commits"}}
120 {i-1..5 merge.verbosity {mc "Merge Verbosity"}}
121 {b merge.diffstat {mc "Show Diffstat After Merge"}}
123 {b gui.trustmtime {mc "Trust File Modification Timestamps"}}
124 {b gui.pruneduringfetch {mc "Prune Tracking Branches During Fetch"}}
125 {b gui.matchtrackingbranch {mc "Match Tracking Branches"}}
126 {i-0..99 gui.diffcontext {mc "Number of Diff Context Lines"}}
127 {i-0..99 gui.commitmsgwidth {mc "Commit Message Text Width"}}
128 {t gui.newbranchtemplate {mc "New Branch Name Template"}}
130 set type [lindex $option 0]
131 set name [lindex $option 1]
132 set text [eval [lindex $option 2]]
134 foreach f {repo global} {
135 switch -glob -- $type {
137 checkbutton $w.$f.$optid -text $text \
138 -variable ${f}_config_new($name) \
141 pack $w.$f.$optid -side top -anchor w
144 regexp -- {-(\d+)\.\.(\d+)$} $type _junk min max
146 label $w.$f.$optid.l -text "$text:"
147 pack $w.$f.$optid.l -side left -anchor w -fill x
148 spinbox $w.$f.$optid.v \
149 -textvariable ${f}_config_new($name) \
153 -width [expr {1 + [string length $max]}]
154 bind $w.$f.$optid.v <FocusIn> {%W selection range 0 end}
155 pack $w.$f.$optid.v -side right -anchor e -padx 5
156 pack $w.$f.$optid -side top -anchor w -fill x
160 label $w.$f.$optid.l -text "$text:"
161 entry $w.$f.$optid.v \
165 -textvariable ${f}_config_new($name)
166 pack $w.$f.$optid.l -side left -anchor w
167 pack $w.$f.$optid.v -side left -anchor w \
170 pack $w.$f.$optid -side top -anchor w -fill x
176 set all_dicts [linsert \
177 [spellcheck::available_langs] \
181 foreach f {repo global} {
182 if {![info exists ${f}_config_new(gui.spellingdictionary)]} {
183 if {[info exists ui_comm_spell]} {
184 set value [$ui_comm_spell lang]
188 set ${f}_config_new(gui.spellingdictionary) $value
192 label $w.$f.$optid.l -text [mc "Spelling Dictionary:"]
193 eval tk_optionMenu $w.$f.$optid.v \
194 ${f}_config_new(gui.spellingdictionary) \
196 pack $w.$f.$optid.l -side left -anchor w -fill x
197 pack $w.$f.$optid.v -side right -anchor e -padx 5
198 pack $w.$f.$optid -side top -anchor w -fill x
202 set all_fonts [lsort [font families]]
203 foreach option $font_descs {
204 set name [lindex $option 0]
205 set font [lindex $option 1]
206 set text [eval [lindex $option 2]]
208 set global_config_new(gui.$font^^family) \
209 [font configure $font -family]
210 set global_config_new(gui.$font^^size) \
211 [font configure $font -size]
213 frame $w.global.$name
214 label $w.global.$name.l -text "$text:"
215 button $w.global.$name.b \
216 -text [mc "Change Font"] \
220 [mc "Choose %s" $text] \
221 global_config_new(gui.$font^^family) \
222 global_config_new(gui.$font^^size) \
224 label $w.global.$name.f -textvariable global_config_new(gui.$font^^family)
225 label $w.global.$name.s -textvariable global_config_new(gui.$font^^size)
226 label $w.global.$name.pt -text [mc "pt."]
227 pack $w.global.$name.l -side left -anchor w
228 pack $w.global.$name.b -side right -anchor e
229 pack $w.global.$name.pt -side right -anchor w
230 pack $w.global.$name.s -side right -anchor w
231 pack $w.global.$name.f -side right -anchor w
232 pack $w.global.$name -side top -anchor w -fill x
235 bind $w <Visibility> "grab $w; focus $w.buttons.save"
236 bind $w <Key-Escape> "destroy $w"
237 bind $w <Key-Return> [list do_save_config $w]
240 set t [mc "Preferences"]
244 wm title $w "[appname] ([reponame]): $t"
248 proc do_restore_defaults {} {
249 global font_descs default_config repo_config
250 global repo_config_new global_config_new
252 foreach name [array names default_config] {
253 set repo_config_new($name) $default_config($name)
254 set global_config_new($name) $default_config($name)
257 foreach option $font_descs {
258 set name [lindex $option 0]
259 set repo_config(gui.$name) $default_config(gui.$name)
263 foreach option $font_descs {
264 set name [lindex $option 0]
265 set font [lindex $option 1]
266 set global_config_new(gui.$font^^family) \
267 [font configure $font -family]
268 set global_config_new(gui.$font^^size) \
269 [font configure $font -size]
273 proc do_save_config {w} {
274 if {[catch {save_config} err]} {
275 error_popup [strcat [mc "Failed to completely save options:"] "\n\n$err"]