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
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 set global_config_new
(gui.
$name) [font configure
$font]
19 unset global_config_new
(gui.
$font^^family
)
20 unset global_config_new
(gui.
$font^^size
)
23 foreach name
[array names default_config
] {
24 set value
$global_config_new($name)
25 if {$value ne
$global_config($name)} {
26 if {$value eq
$default_config($name)} {
27 catch {git config
--global --unset $name}
29 regsub -all "\[{}\]" $value {"} value
30 git config --global $name $value
32 set global_config($name) $value
33 if {$value eq $repo_config($name)} {
34 catch {git config --unset $name}
35 set repo_config($name) $value
40 foreach name [array names default_config] {
41 set value $repo_config_new($name)
42 if {$value ne $repo_config($name)} {
43 if {$value eq $global_config($name)} {
44 catch {git config --unset $name}
46 regsub -all "\[{}\]" $value {"} value
47 git config
$name $value
49 set repo_config
($name) $value
55 global appvers copyright
56 global tcl_patchLevel tk_patchLevel
60 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
62 label $w.header
-text "About [appname]" \
64 pack $w.header
-side top
-fill x
67 button $w.buttons.
close -text {Close
} \
69 -command [list destroy $w]
70 pack $w.buttons.
close -side right
71 pack $w.buttons
-side bottom
-fill x
-pady 10 -padx 10
74 -text "git-gui - a graphical user interface for Git.
81 pack $w.desc
-side top
-fill x
-padx 5 -pady 5
84 append v
"git-gui version $appvers\n"
85 append v
"[git version]\n"
87 if {$tcl_patchLevel eq
$tk_patchLevel} {
88 append v
"Tcl/Tk version $tcl_patchLevel"
90 append v
"Tcl version $tcl_patchLevel"
91 append v
", Tk version $tk_patchLevel"
101 pack $w.vers
-side top
-fill x
-padx 5 -pady 5
103 menu $w.ctxm
-tearoff 0
104 $w.ctxm add command
\
108 clipboard append -format STRING -type STRING -- \[$w.vers cget -text\]
111 bind $w <Visibility
> "grab $w; focus $w.buttons.close"
112 bind $w <Key-Escape
> "destroy $w"
113 bind $w <Key-Return
> "destroy $w"
114 bind_button3
$w.vers
"tk_popup $w.ctxm %X %Y; grab $w; focus $w"
115 wm title
$w "About [appname]"
120 global repo_config global_config font_descs
121 global repo_config_new global_config_new
123 array unset repo_config_new
124 array unset global_config_new
125 foreach name
[array names repo_config
] {
126 set repo_config_new
($name) $repo_config($name)
129 foreach name
[array names repo_config
] {
131 gui.diffcontext
{continue}
133 set repo_config_new
($name) $repo_config($name)
135 foreach name
[array names global_config
] {
136 set global_config_new
($name) $global_config($name)
139 set w .options_editor
141 wm geometry
$w "+[winfo rootx .]+[winfo rooty .]"
143 label $w.header
-text "Options" \
145 pack $w.header
-side top
-fill x
148 button $w.buttons.restore
-text {Restore Defaults
} \
150 -command do_restore_defaults
151 pack $w.buttons.restore
-side left
152 button $w.buttons.save
-text Save
\
154 -command [list do_save_config
$w]
155 pack $w.buttons.save
-side right
156 button $w.buttons.cancel
-text {Cancel
} \
158 -command [list destroy $w]
159 pack $w.buttons.cancel
-side right
-padx 5
160 pack $w.buttons
-side bottom
-fill x
-pady 10 -padx 10
162 labelframe $w.repo
-text "[reponame] Repository"
163 labelframe $w.
global -text {Global
(All Repositories
)}
164 pack $w.repo
-side left
-fill both
-expand 1 -pady 5 -padx 5
165 pack $w.
global -side right
-fill both
-expand 1 -pady 5 -padx 5
169 {t user.name
{User Name
}}
170 {t user.email
{Email Address
}}
172 {b merge.summary
{Summarize Merge Commits
}}
173 {i-1.
.5 merge.verbosity
{Merge Verbosity
}}
175 {b gui.trustmtime
{Trust File Modification Timestamps
}}
176 {i-0.
.99 gui.diffcontext
{Number of Diff Context Lines
}}
177 {t gui.newbranchtemplate
{New Branch Name Template
}}
179 set type
[lindex $option 0]
180 set name
[lindex $option 1]
181 set text [lindex $option 2]
183 foreach f
{repo
global} {
184 switch -glob -- $type {
186 checkbutton $w.
$f.
$optid -text $text \
187 -variable ${f
}_config_new
($name) \
190 pack $w.
$f.
$optid -side top
-anchor w
193 regexp -- {-(\d
+)\.
\.
(\d
+)$} $type _junk min max
195 label $w.
$f.
$optid.l
-text "$text:"
196 pack $w.
$f.
$optid.l
-side left
-anchor w
-fill x
197 spinbox $w.
$f.
$optid.v
\
198 -textvariable ${f
}_config_new
($name) \
202 -width [expr {1 + [string length
$max]}]
203 bind $w.
$f.
$optid.v
<FocusIn
> {%W
selection range
0 end
}
204 pack $w.
$f.
$optid.v
-side right
-anchor e
-padx 5
205 pack $w.
$f.
$optid -side top
-anchor w
-fill x
209 label $w.
$f.
$optid.l
-text "$text:"
210 entry $w.
$f.
$optid.v
\
214 -textvariable ${f
}_config_new
($name)
215 pack $w.
$f.
$optid.l
-side left
-anchor w
216 pack $w.
$f.
$optid.v
-side left
-anchor w
\
219 pack $w.
$f.
$optid -side top
-anchor w
-fill x
225 set all_fonts
[lsort [font families
]]
226 foreach option $font_descs {
227 set name
[lindex $option 0]
228 set font [lindex $option 1]
229 set text [lindex $option 2]
231 set global_config_new
(gui.
$font^^family
) \
232 [font configure
$font -family]
233 set global_config_new
(gui.
$font^^size
) \
234 [font configure
$font -size]
236 frame $w.
global.
$name
237 label $w.
global.
$name.l
-text "$text:"
238 pack $w.
global.
$name.l
-side left
-anchor w
-fill x
239 eval tk_optionMenu $w.
global.
$name.family
\
240 global_config_new
(gui.
$font^^family
) \
242 spinbox $w.
global.
$name.size
\
243 -textvariable global_config_new
(gui.
$font^^size
) \
244 -from 2 -to 80 -increment 1 \
246 bind $w.
global.
$name.size
<FocusIn
> {%W
selection range
0 end
}
247 pack $w.
global.
$name.size
-side right
-anchor e
248 pack $w.
global.
$name.family
-side right
-anchor e
249 pack $w.
global.
$name -side top
-anchor w
-fill x
252 bind $w <Visibility
> "grab $w; focus $w.buttons.save"
253 bind $w <Key-Escape
> "destroy $w"
254 bind $w <Key-Return
> [list do_save_config
$w]
255 wm title
$w "[appname] ([reponame]): Options"
259 proc do_restore_defaults
{} {
260 global font_descs default_config repo_config
261 global repo_config_new global_config_new
263 foreach name
[array names default_config
] {
264 set repo_config_new
($name) $default_config($name)
265 set global_config_new
($name) $default_config($name)
268 foreach option $font_descs {
269 set name
[lindex $option 0]
270 set repo_config
(gui.
$name) $default_config(gui.
$name)
274 foreach option $font_descs {
275 set name
[lindex $option 0]
276 set font [lindex $option 1]
277 set global_config_new
(gui.
$font^^family
) \
278 [font configure
$font -family]
279 set global_config_new
(gui.
$font^^size
) \
280 [font configure
$font -size]
284 proc do_save_config
{w
} {
285 if {[catch {save_config
} err
]} {
286 error_popup
"Failed to completely save options:\n\n$err"