git-gui: Reimplement and enhance auto-selection of diffs.
[git/mingw/4msysgit.git] / lib / option.tcl
blob9b865f6a754aeb0933e1696ae1c9ffaee899e936
1 # git-gui options editor
2 # Copyright (C) 2006, 2007 Shawn Pearce
4 proc save_config {} {
5 global default_config font_descs
6 global repo_config global_config
7 global repo_config_new global_config_new
8 global ui_comm_spell
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}
32 } else {
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}
49 } else {
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]} {
61 $ui_comm_spell stop
63 } elseif {[info exists ui_comm_spell]} {
64 $ui_comm_spell lang $value
69 proc do_options {} {
70 global repo_config global_config font_descs
71 global repo_config_new global_config_new
72 global ui_comm_spell
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)
79 load_config 1
80 foreach name [array names repo_config] {
81 switch -- $name {
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)
90 set w .options_editor
91 toplevel $w
92 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
94 frame $w.buttons
95 button $w.buttons.restore -text [mc "Restore Defaults"] \
96 -default normal \
97 -command do_restore_defaults
98 pack $w.buttons.restore -side left
99 button $w.buttons.save -text [mc Save] \
100 -default active \
101 -command [list do_save_config $w]
102 pack $w.buttons.save -side right
103 button $w.buttons.cancel -text [mc "Cancel"] \
104 -default normal \
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
114 set optid 0
115 foreach option {
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"}}
122 {t merge.tool {mc "Use Merge Tool"}}
124 {b gui.trustmtime {mc "Trust File Modification Timestamps"}}
125 {b gui.pruneduringfetch {mc "Prune Tracking Branches During Fetch"}}
126 {b gui.matchtrackingbranch {mc "Match Tracking Branches"}}
127 {b gui.fastcopyblame {mc "Blame Copy Only On Changed Files"}}
128 {i-20..200 gui.copyblamethreshold {mc "Minimum Letters To Blame Copy On"}}
129 {i-0..300 gui.blamehistoryctx {mc "Blame History Context Radius (days)"}}
130 {i-1..99 gui.diffcontext {mc "Number of Diff Context Lines"}}
131 {i-0..99 gui.commitmsgwidth {mc "Commit Message Text Width"}}
132 {t gui.newbranchtemplate {mc "New Branch Name Template"}}
134 set type [lindex $option 0]
135 set name [lindex $option 1]
136 set text [eval [lindex $option 2]]
137 incr optid
138 foreach f {repo global} {
139 switch -glob -- $type {
141 checkbutton $w.$f.$optid -text $text \
142 -variable ${f}_config_new($name) \
143 -onvalue true \
144 -offvalue false
145 pack $w.$f.$optid -side top -anchor w
147 i-* {
148 regexp -- {-(\d+)\.\.(\d+)$} $type _junk min max
149 frame $w.$f.$optid
150 label $w.$f.$optid.l -text "$text:"
151 pack $w.$f.$optid.l -side left -anchor w -fill x
152 spinbox $w.$f.$optid.v \
153 -textvariable ${f}_config_new($name) \
154 -from $min \
155 -to $max \
156 -increment 1 \
157 -width [expr {1 + [string length $max]}]
158 bind $w.$f.$optid.v <FocusIn> {%W selection range 0 end}
159 pack $w.$f.$optid.v -side right -anchor e -padx 5
160 pack $w.$f.$optid -side top -anchor w -fill x
163 frame $w.$f.$optid
164 label $w.$f.$optid.l -text "$text:"
165 entry $w.$f.$optid.v \
166 -borderwidth 1 \
167 -relief sunken \
168 -width 20 \
169 -textvariable ${f}_config_new($name)
170 pack $w.$f.$optid.l -side left -anchor w
171 pack $w.$f.$optid.v -side left -anchor w \
172 -fill x -expand 1 \
173 -padx 5
174 pack $w.$f.$optid -side top -anchor w -fill x
180 set all_dicts [linsert \
181 [spellcheck::available_langs] \
183 none]
184 incr optid
185 foreach f {repo global} {
186 if {![info exists ${f}_config_new(gui.spellingdictionary)]} {
187 if {[info exists ui_comm_spell]} {
188 set value [$ui_comm_spell lang]
189 } else {
190 set value none
192 set ${f}_config_new(gui.spellingdictionary) $value
195 frame $w.$f.$optid
196 label $w.$f.$optid.l -text [mc "Spelling Dictionary:"]
197 eval tk_optionMenu $w.$f.$optid.v \
198 ${f}_config_new(gui.spellingdictionary) \
199 $all_dicts
200 pack $w.$f.$optid.l -side left -anchor w -fill x
201 pack $w.$f.$optid.v -side right -anchor e -padx 5
202 pack $w.$f.$optid -side top -anchor w -fill x
204 unset all_dicts
206 set all_fonts [lsort [font families]]
207 foreach option $font_descs {
208 set name [lindex $option 0]
209 set font [lindex $option 1]
210 set text [eval [lindex $option 2]]
212 set global_config_new(gui.$font^^family) \
213 [font configure $font -family]
214 set global_config_new(gui.$font^^size) \
215 [font configure $font -size]
217 frame $w.global.$name
218 label $w.global.$name.l -text "$text:"
219 button $w.global.$name.b \
220 -text [mc "Change Font"] \
221 -command [list \
222 choose_font::pick \
223 $w \
224 [mc "Choose %s" $text] \
225 global_config_new(gui.$font^^family) \
226 global_config_new(gui.$font^^size) \
228 label $w.global.$name.f -textvariable global_config_new(gui.$font^^family)
229 label $w.global.$name.s -textvariable global_config_new(gui.$font^^size)
230 label $w.global.$name.pt -text [mc "pt."]
231 pack $w.global.$name.l -side left -anchor w
232 pack $w.global.$name.b -side right -anchor e
233 pack $w.global.$name.pt -side right -anchor w
234 pack $w.global.$name.s -side right -anchor w
235 pack $w.global.$name.f -side right -anchor w
236 pack $w.global.$name -side top -anchor w -fill x
239 bind $w <Visibility> "grab $w; focus $w.buttons.save"
240 bind $w <Key-Escape> "destroy $w"
241 bind $w <Key-Return> [list do_save_config $w]
243 if {[is_MacOSX]} {
244 set t [mc "Preferences"]
245 } else {
246 set t [mc "Options"]
248 wm title $w "[appname] ([reponame]): $t"
249 tkwait window $w
252 proc do_restore_defaults {} {
253 global font_descs default_config repo_config
254 global repo_config_new global_config_new
256 foreach name [array names default_config] {
257 set repo_config_new($name) $default_config($name)
258 set global_config_new($name) $default_config($name)
261 foreach option $font_descs {
262 set name [lindex $option 0]
263 set repo_config(gui.$name) $default_config(gui.$name)
265 apply_config
267 foreach option $font_descs {
268 set name [lindex $option 0]
269 set font [lindex $option 1]
270 set global_config_new(gui.$font^^family) \
271 [font configure $font -family]
272 set global_config_new(gui.$font^^size) \
273 [font configure $font -size]
277 proc do_save_config {w} {
278 if {[catch {save_config} err]} {
279 error_popup [strcat [mc "Failed to completely save options:"] "\n\n$err"]
281 reshow_diff
282 destroy $w