send-pack: respect '+' on wildcard refspecs
[git/dscho.git] / git-gui / lib / option.tcl
blob063f5df6f7cd709e25a8f9c0ede263a3d10f5d8d
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
9 foreach option $font_descs {
10 set name [lindex $option 0]
11 set font [lindex $option 1]
12 font configure $font \
13 -family $global_config_new(gui.$font^^family) \
14 -size $global_config_new(gui.$font^^size)
15 font configure ${font}bold \
16 -family $global_config_new(gui.$font^^family) \
17 -size $global_config_new(gui.$font^^size)
18 font configure ${font}italic \
19 -family $global_config_new(gui.$font^^family) \
20 -size $global_config_new(gui.$font^^size)
21 set global_config_new(gui.$name) [font configure $font]
22 unset global_config_new(gui.$font^^family)
23 unset global_config_new(gui.$font^^size)
26 foreach name [array names default_config] {
27 set value $global_config_new($name)
28 if {$value ne $global_config($name)} {
29 if {$value eq $default_config($name)} {
30 catch {git config --global --unset $name}
31 } else {
32 regsub -all "\[{}\]" $value {"} value
33 git config --global $name $value
35 set global_config($name) $value
36 if {$value eq $repo_config($name)} {
37 catch {git config --unset $name}
38 set repo_config($name) $value
43 foreach name [array names default_config] {
44 set value $repo_config_new($name)
45 if {$value ne $repo_config($name)} {
46 if {$value eq $global_config($name)} {
47 catch {git config --unset $name}
48 } else {
49 regsub -all "\[{}\]" $value {"} value
50 git config $name $value
52 set repo_config($name) $value
57 proc do_about {} {
58 global appvers copyright oguilib
59 global tcl_patchLevel tk_patchLevel
61 set w .about_dialog
62 toplevel $w
63 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
65 label $w.header -text "About [appname]" \
66 -font font_uibold
67 pack $w.header -side top -fill x
69 frame $w.buttons
70 button $w.buttons.close -text {Close} \
71 -default active \
72 -command [list destroy $w]
73 pack $w.buttons.close -side right
74 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
76 label $w.desc \
77 -text "git-gui - a graphical user interface for Git.
78 $copyright" \
79 -padx 5 -pady 5 \
80 -justify left \
81 -anchor w \
82 -borderwidth 1 \
83 -relief solid
84 pack $w.desc -side top -fill x -padx 5 -pady 5
86 set v {}
87 append v "git-gui version $appvers\n"
88 append v "[git version]\n"
89 append v "\n"
90 if {$tcl_patchLevel eq $tk_patchLevel} {
91 append v "Tcl/Tk version $tcl_patchLevel"
92 } else {
93 append v "Tcl version $tcl_patchLevel"
94 append v ", Tk version $tk_patchLevel"
97 set d {}
98 append d "git wrapper: $::_git\n"
99 append d "git exec dir: [gitexec]\n"
100 append d "git-gui lib: $oguilib"
102 label $w.vers \
103 -text $v \
104 -padx 5 -pady 5 \
105 -justify left \
106 -anchor w \
107 -borderwidth 1 \
108 -relief solid
109 pack $w.vers -side top -fill x -padx 5 -pady 5
111 label $w.dirs \
112 -text $d \
113 -padx 5 -pady 5 \
114 -justify left \
115 -anchor w \
116 -borderwidth 1 \
117 -relief solid
118 pack $w.dirs -side top -fill x -padx 5 -pady 5
120 menu $w.ctxm -tearoff 0
121 $w.ctxm add command \
122 -label {Copy} \
123 -command "
124 clipboard clear
125 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
128 bind $w <Visibility> "grab $w; focus $w.buttons.close"
129 bind $w <Key-Escape> "destroy $w"
130 bind $w <Key-Return> "destroy $w"
131 bind_button3 $w.vers "tk_popup $w.ctxm %X %Y; grab $w; focus $w"
132 wm title $w "About [appname]"
133 tkwait window $w
136 proc do_options {} {
137 global repo_config global_config font_descs
138 global repo_config_new global_config_new
140 array unset repo_config_new
141 array unset global_config_new
142 foreach name [array names repo_config] {
143 set repo_config_new($name) $repo_config($name)
145 load_config 1
146 foreach name [array names repo_config] {
147 switch -- $name {
148 gui.diffcontext {continue}
150 set repo_config_new($name) $repo_config($name)
152 foreach name [array names global_config] {
153 set global_config_new($name) $global_config($name)
156 set w .options_editor
157 toplevel $w
158 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
160 label $w.header -text "Options" \
161 -font font_uibold
162 pack $w.header -side top -fill x
164 frame $w.buttons
165 button $w.buttons.restore -text {Restore Defaults} \
166 -default normal \
167 -command do_restore_defaults
168 pack $w.buttons.restore -side left
169 button $w.buttons.save -text Save \
170 -default active \
171 -command [list do_save_config $w]
172 pack $w.buttons.save -side right
173 button $w.buttons.cancel -text {Cancel} \
174 -default normal \
175 -command [list destroy $w]
176 pack $w.buttons.cancel -side right -padx 5
177 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
179 labelframe $w.repo -text "[reponame] Repository"
180 labelframe $w.global -text {Global (All Repositories)}
181 pack $w.repo -side left -fill both -expand 1 -pady 5 -padx 5
182 pack $w.global -side right -fill both -expand 1 -pady 5 -padx 5
184 set optid 0
185 foreach option {
186 {t user.name {User Name}}
187 {t user.email {Email Address}}
189 {b merge.summary {Summarize Merge Commits}}
190 {i-1..5 merge.verbosity {Merge Verbosity}}
191 {b merge.diffstat {Show Diffstat After Merge}}
193 {b gui.trustmtime {Trust File Modification Timestamps}}
194 {b gui.pruneduringfetch {Prune Tracking Branches During Fetch}}
195 {b gui.matchtrackingbranch {Match Tracking Branches}}
196 {i-0..99 gui.diffcontext {Number of Diff Context Lines}}
197 {t gui.newbranchtemplate {New Branch Name Template}}
199 set type [lindex $option 0]
200 set name [lindex $option 1]
201 set text [lindex $option 2]
202 incr optid
203 foreach f {repo global} {
204 switch -glob -- $type {
206 checkbutton $w.$f.$optid -text $text \
207 -variable ${f}_config_new($name) \
208 -onvalue true \
209 -offvalue false
210 pack $w.$f.$optid -side top -anchor w
212 i-* {
213 regexp -- {-(\d+)\.\.(\d+)$} $type _junk min max
214 frame $w.$f.$optid
215 label $w.$f.$optid.l -text "$text:"
216 pack $w.$f.$optid.l -side left -anchor w -fill x
217 spinbox $w.$f.$optid.v \
218 -textvariable ${f}_config_new($name) \
219 -from $min \
220 -to $max \
221 -increment 1 \
222 -width [expr {1 + [string length $max]}]
223 bind $w.$f.$optid.v <FocusIn> {%W selection range 0 end}
224 pack $w.$f.$optid.v -side right -anchor e -padx 5
225 pack $w.$f.$optid -side top -anchor w -fill x
228 frame $w.$f.$optid
229 label $w.$f.$optid.l -text "$text:"
230 entry $w.$f.$optid.v \
231 -borderwidth 1 \
232 -relief sunken \
233 -width 20 \
234 -textvariable ${f}_config_new($name)
235 pack $w.$f.$optid.l -side left -anchor w
236 pack $w.$f.$optid.v -side left -anchor w \
237 -fill x -expand 1 \
238 -padx 5
239 pack $w.$f.$optid -side top -anchor w -fill x
245 set all_fonts [lsort [font families]]
246 foreach option $font_descs {
247 set name [lindex $option 0]
248 set font [lindex $option 1]
249 set text [lindex $option 2]
251 set global_config_new(gui.$font^^family) \
252 [font configure $font -family]
253 set global_config_new(gui.$font^^size) \
254 [font configure $font -size]
256 frame $w.global.$name
257 label $w.global.$name.l -text "$text:"
258 button $w.global.$name.b \
259 -text [mc "Change Font"] \
260 -command [list \
261 choose_font::pick \
262 $w \
263 [mc "Choose %s" $text] \
264 global_config_new(gui.$font^^family) \
265 global_config_new(gui.$font^^size) \
267 label $w.global.$name.f -textvariable global_config_new(gui.$font^^family)
268 label $w.global.$name.s -textvariable global_config_new(gui.$font^^size)
269 label $w.global.$name.pt -text [mc "pt."]
270 pack $w.global.$name.l -side left -anchor w
271 pack $w.global.$name.b -side right -anchor e
272 pack $w.global.$name.pt -side right -anchor w
273 pack $w.global.$name.s -side right -anchor w
274 pack $w.global.$name.f -side right -anchor w
275 pack $w.global.$name -side top -anchor w -fill x
278 bind $w <Visibility> "grab $w; focus $w.buttons.save"
279 bind $w <Key-Escape> "destroy $w"
280 bind $w <Key-Return> [list do_save_config $w]
281 wm title $w "[appname] ([reponame]): Options"
282 tkwait window $w
285 proc do_restore_defaults {} {
286 global font_descs default_config repo_config
287 global repo_config_new global_config_new
289 foreach name [array names default_config] {
290 set repo_config_new($name) $default_config($name)
291 set global_config_new($name) $default_config($name)
294 foreach option $font_descs {
295 set name [lindex $option 0]
296 set repo_config(gui.$name) $default_config(gui.$name)
298 apply_config
300 foreach option $font_descs {
301 set name [lindex $option 0]
302 set font [lindex $option 1]
303 set global_config_new(gui.$font^^family) \
304 [font configure $font -family]
305 set global_config_new(gui.$font^^size) \
306 [font configure $font -size]
310 proc do_save_config {w} {
311 if {[catch {save_config} err]} {
312 error_popup "Failed to completely save options:\n\n$err"
314 reshow_diff
315 destroy $w