1 # git-gui options editor
2 # Copyright (C) 2006, 2007 Shawn Pearce
4 proc config_check_encodings
{} {
5 global repo_config_new global_config_new
7 set enc
$global_config_new(gui.
encoding)
9 set global_config_new
(gui.
encoding) [encoding system
]
10 } elseif
{[tcl_encoding
$enc] eq
{}} {
11 error_popup
[mc
"Invalid global encoding '%s'" $enc]
15 set enc
$repo_config_new(gui.
encoding)
17 set repo_config_new
(gui.
encoding) [encoding system
]
18 } elseif
{[tcl_encoding
$enc] eq
{}} {
19 error_popup
[mc
"Invalid repo encoding '%s'" $enc]
27 global default_config font_descs
28 global repo_config global_config system_config
29 global repo_config_new global_config_new
32 foreach option $font_descs {
33 set name
[lindex $option 0]
34 set font [lindex $option 1]
35 font configure
$font \
36 -family $global_config_new(gui.
$font^^family
) \
37 -size $global_config_new(gui.
$font^^size
)
38 font configure
${font}bold
\
39 -family $global_config_new(gui.
$font^^family
) \
40 -size $global_config_new(gui.
$font^^size
)
41 font configure
${font}italic
\
42 -family $global_config_new(gui.
$font^^family
) \
43 -size $global_config_new(gui.
$font^^size
)
44 set global_config_new
(gui.
$name) [font configure
$font]
45 unset global_config_new
(gui.
$font^^family
)
46 unset global_config_new
(gui.
$font^^size
)
49 foreach name
[array names default_config
] {
50 set value
$global_config_new($name)
51 if {$value ne
$global_config($name)} {
52 if {$value eq
$system_config($name)} {
53 catch {git config
--global --unset $name}
55 regsub -all "\[{}\]" $value {"} value
56 git config --global $name $value
58 set global_config($name) $value
59 if {$value eq $repo_config($name)} {
60 catch {git config --unset $name}
61 set repo_config($name) $value
66 foreach name [array names default_config] {
67 set value $repo_config_new($name)
68 if {$value ne $repo_config($name)} {
69 if {$value eq $global_config($name)} {
70 catch {git config --unset $name}
72 regsub -all "\[{}\]" $value {"} value
73 git config
$name $value
75 set repo_config
($name) $value
79 if {[info exists repo_config
(gui.spellingdictionary
)]} {
80 set value
$repo_config(gui.spellingdictionary
)
81 if {$value eq
{none
}} {
82 if {[info exists ui_comm_spell
]} {
85 } elseif
{[info exists ui_comm_spell
]} {
86 $ui_comm_spell lang
$value
92 global repo_config global_config font_descs
93 global repo_config_new global_config_new
94 global ui_comm_spell use_ttk NS
96 array unset repo_config_new
97 array unset global_config_new
98 foreach name
[array names repo_config
] {
99 set repo_config_new
($name) $repo_config($name)
102 foreach name
[array names repo_config
] {
104 gui.diffcontext
{continue}
106 set repo_config_new
($name) $repo_config($name)
108 foreach name
[array names global_config
] {
109 set global_config_new
($name) $global_config($name)
112 set w .options_editor
115 wm transient
$w [winfo parent
$w]
116 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
118 ${NS
}::frame $w.buttons
119 ${NS
}::button $w.buttons.restore
-text [mc
"Restore Defaults"] \
121 -command do_restore_defaults
122 pack $w.buttons.restore
-side left
123 ${NS
}::button $w.buttons.save
-text [mc Save
] \
125 -command [list do_save_config
$w]
126 pack $w.buttons.save
-side right
127 ${NS
}::button $w.buttons.cancel
-text [mc
"Cancel"] \
129 -command [list destroy $w]
130 pack $w.buttons.cancel
-side right
-padx 5
131 pack $w.buttons
-side bottom
-fill x
-pady 10 -padx 10
133 ${NS
}::labelframe $w.repo
-text [mc
"%s Repository" [reponame
]]
134 ${NS
}::labelframe $w.
global -text [mc
"Global (All Repositories)"]
135 pack $w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
136 pack $w.
global -side right
-fill both
-expand 1 -pady 5 -padx 5
140 {t user.name
{mc
"User Name"}}
141 {t user.email
{mc
"Email Address"}}
143 {b merge.summary
{mc
"Summarize Merge Commits"}}
144 {i-1.
.5 merge.verbosity
{mc
"Merge Verbosity"}}
145 {b merge.diffstat
{mc
"Show Diffstat After Merge"}}
146 {t merge.tool
{mc
"Use Merge Tool"}}
148 {b gui.trustmtime
{mc
"Trust File Modification Timestamps"}}
149 {b gui.pruneduringfetch
{mc
"Prune Tracking Branches During Fetch"}}
150 {b gui.matchtrackingbranch
{mc
"Match Tracking Branches"}}
151 {b gui.textconv
{mc
"Use Textconv For Diffs and Blames"}}
152 {b gui.fastcopyblame
{mc
"Blame Copy Only On Changed Files"}}
153 {i-20.
.200 gui.copyblamethreshold
{mc
"Minimum Letters To Blame Copy On"}}
154 {i-0.
.300 gui.blamehistoryctx
{mc
"Blame History Context Radius (days)"}}
155 {i-1.
.99 gui.diffcontext
{mc
"Number of Diff Context Lines"}}
156 {t gui.diffopts
{mc
"Additional Diff Parameters"}}
157 {i-0.
.99 gui.commitmsgwidth
{mc
"Commit Message Text Width"}}
158 {t gui.newbranchtemplate
{mc
"New Branch Name Template"}}
159 {c gui.
encoding {mc
"Default File Contents Encoding"}}
160 {s gui.stageuntracked
{mc
"Staging of untracked files"} {list "yes" "no" "ask"}}
162 set type
[lindex $option 0]
163 set name
[lindex $option 1]
164 set text [eval [lindex $option 2]]
166 foreach f
{repo
global} {
167 switch -glob -- $type {
169 ${NS
}::checkbutton $w.
$f.
$optid -text $text \
170 -variable ${f
}_config_new
($name) \
173 pack $w.
$f.
$optid -side top
-anchor w
176 regexp -- {-(\d
+)\.
\.
(\d
+)$} $type _junk min max
177 ${NS
}::frame $w.
$f.
$optid
178 ${NS
}::label $w.
$f.
$optid.l
-text "$text:"
179 pack $w.
$f.
$optid.l
-side left
-anchor w
-fill x
180 tspinbox
$w.
$f.
$optid.v
\
181 -textvariable ${f
}_config_new
($name) \
185 -width [expr {1 + [string length
$max]}]
186 bind $w.
$f.
$optid.v
<FocusIn
> {%W
selection range
0 end
}
187 pack $w.
$f.
$optid.v
-side right
-anchor e
-padx 5
188 pack $w.
$f.
$optid -side top
-anchor w
-fill x
192 ${NS
}::frame $w.
$f.
$optid
193 ${NS
}::label $w.
$f.
$optid.l
-text "$text:"
194 ${NS
}::entry $w.
$f.
$optid.v
\
196 -textvariable ${f
}_config_new
($name)
197 pack $w.
$f.
$optid.l
-side left
-anchor w
198 pack $w.
$f.
$optid.v
-side left
-anchor w
\
203 build_encoding_menu
$w.
$f.
$optid.m
\
204 [list set ${f
}_config_new
($name)] 1
205 ${NS
}::button $w.
$f.
$optid.b
\
206 -text [mc
"Change"] \
207 -command [list popup_btn_menu
\
208 $w.
$f.
$optid.m
$w.
$f.
$optid.b
]
209 pack $w.
$f.
$optid.b
-side left
-anchor w
211 pack $w.
$f.
$optid -side top
-anchor w
-fill x
214 set opts
[eval [lindex $option 3]]
215 ${NS
}::frame $w.
$f.
$optid
216 ${NS
}::label $w.
$f.
$optid.l
-text "$text:"
218 ttk
::combobox $w.
$f.
$optid.v
\
219 -textvariable ${f
}_config_new
($name) \
220 -values $opts -state readonly
222 eval tk_optionMenu $w.
$f.
$optid.v
\
223 ${f
}_config_new
($name) \
226 pack $w.
$f.
$optid.l
-side left
-anchor w
-fill x
227 pack $w.
$f.
$optid.v
-side right
-anchor e
-padx 5
228 pack $w.
$f.
$optid -side top
-anchor w
-fill x
234 set all_dicts
[linsert \
235 [spellcheck
::available_langs] \
239 foreach f
{repo
global} {
240 if {![info exists
${f
}_config_new
(gui.spellingdictionary
)]} {
241 if {[info exists ui_comm_spell
]} {
242 set value
[$ui_comm_spell lang
]
246 set ${f
}_config_new
(gui.spellingdictionary
) $value
249 ${NS
}::frame $w.
$f.
$optid
250 ${NS
}::label $w.
$f.
$optid.l
-text [mc
"Spelling Dictionary:"]
252 ttk
::combobox $w.
$f.
$optid.v
\
253 -textvariable ${f
}_config_new
(gui.spellingdictionary
) \
254 -values $all_dicts -state readonly
256 eval tk_optionMenu $w.
$f.
$optid.v
\
257 ${f
}_config_new
(gui.spellingdictionary
) \
260 pack $w.
$f.
$optid.l
-side left
-anchor w
-fill x
261 pack $w.
$f.
$optid.v
-side right
-anchor e
-padx 5
262 pack $w.
$f.
$optid -side top
-anchor w
-fill x
266 set all_fonts
[lsort [font families
]]
267 foreach option $font_descs {
268 set name
[lindex $option 0]
269 set font [lindex $option 1]
270 set text [eval [lindex $option 2]]
272 set global_config_new
(gui.
$font^^family
) \
273 [font configure
$font -family]
274 set global_config_new
(gui.
$font^^size
) \
275 [font configure
$font -size]
277 ${NS
}::frame $w.
global.
$name
278 ${NS
}::label $w.
global.
$name.l
-text "$text:"
279 ${NS
}::button $w.
global.
$name.b
\
280 -text [mc
"Change Font"] \
284 [mc
"Choose %s" $text] \
285 global_config_new
(gui.
$font^^family
) \
286 global_config_new
(gui.
$font^^size
) \
288 ${NS
}::label $w.
global.
$name.f
-textvariable global_config_new
(gui.
$font^^family
)
289 ${NS
}::label $w.
global.
$name.s
-textvariable global_config_new
(gui.
$font^^size
)
290 ${NS
}::label $w.
global.
$name.pt
-text [mc
"pt."]
291 pack $w.
global.
$name.l
-side left
-anchor w
292 pack $w.
global.
$name.b
-side right
-anchor e
293 pack $w.
global.
$name.pt
-side right
-anchor w
294 pack $w.
global.
$name.s
-side right
-anchor w
295 pack $w.
global.
$name.f
-side right
-anchor w
296 pack $w.
global.
$name -side top
-anchor w
-fill x
299 bind $w <Visibility
> "grab $w; focus $w.buttons.save"
300 bind $w <Key-Escape
> "destroy $w"
301 bind $w <Key-Return
> [list do_save_config
$w]
304 set t
[mc
"Preferences"]
308 wm title
$w "[appname] ([reponame]): $t"
313 proc do_restore_defaults
{} {
314 global font_descs default_config repo_config system_config
315 global repo_config_new global_config_new
317 foreach name
[array names default_config
] {
318 set repo_config_new
($name) $system_config($name)
319 set global_config_new
($name) $system_config($name)
322 foreach option $font_descs {
323 set name
[lindex $option 0]
324 set repo_config
(gui.
$name) $system_config(gui.
$name)
328 foreach option $font_descs {
329 set name
[lindex $option 0]
330 set font [lindex $option 1]
331 set global_config_new
(gui.
$font^^family
) \
332 [font configure
$font -family]
333 set global_config_new
(gui.
$font^^size
) \
334 [font configure
$font -size]
338 proc do_save_config
{w
} {
339 if {![config_check_encodings
]} return
340 if {[catch {save_config
} err
]} {
341 error_popup
[strcat
[mc
"Failed to completely save options:"] "\n\n$err"]