git-config --get-color: get configured color
[git/jnareb-git/bp-gitweb.git] / git-gui / lib / option.tcl
blobf812e5e89a1f21e2ee96a90e83958a472539bdd5
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_options {} {
58 global repo_config global_config font_descs
59 global repo_config_new global_config_new
61 array unset repo_config_new
62 array unset global_config_new
63 foreach name [array names repo_config] {
64 set repo_config_new($name) $repo_config($name)
66 load_config 1
67 foreach name [array names repo_config] {
68 switch -- $name {
69 gui.diffcontext {continue}
71 set repo_config_new($name) $repo_config($name)
73 foreach name [array names global_config] {
74 set global_config_new($name) $global_config($name)
77 set w .options_editor
78 toplevel $w
79 wm geometry $w "+[winfo rootx .]+[winfo rooty .]"
81 frame $w.buttons
82 button $w.buttons.restore -text [mc "Restore Defaults"] \
83 -default normal \
84 -command do_restore_defaults
85 pack $w.buttons.restore -side left
86 button $w.buttons.save -text [mc Save] \
87 -default active \
88 -command [list do_save_config $w]
89 pack $w.buttons.save -side right
90 button $w.buttons.cancel -text [mc "Cancel"] \
91 -default normal \
92 -command [list destroy $w]
93 pack $w.buttons.cancel -side right -padx 5
94 pack $w.buttons -side bottom -fill x -pady 10 -padx 10
96 labelframe $w.repo -text [mc "%s Repository" [reponame]]
97 labelframe $w.global -text [mc "Global (All Repositories)"]
98 pack $w.repo -side left -fill both -expand 1 -pady 5 -padx 5
99 pack $w.global -side right -fill both -expand 1 -pady 5 -padx 5
101 set optid 0
102 foreach option {
103 {t user.name {mc "User Name"}}
104 {t user.email {mc "Email Address"}}
106 {b merge.summary {mc "Summarize Merge Commits"}}
107 {i-1..5 merge.verbosity {mc "Merge Verbosity"}}
108 {b merge.diffstat {mc "Show Diffstat After Merge"}}
110 {b gui.trustmtime {mc "Trust File Modification Timestamps"}}
111 {b gui.pruneduringfetch {mc "Prune Tracking Branches During Fetch"}}
112 {b gui.matchtrackingbranch {mc "Match Tracking Branches"}}
113 {i-0..99 gui.diffcontext {mc "Number of Diff Context Lines"}}
114 {t gui.newbranchtemplate {mc "New Branch Name Template"}}
116 set type [lindex $option 0]
117 set name [lindex $option 1]
118 set text [eval [lindex $option 2]]
119 incr optid
120 foreach f {repo global} {
121 switch -glob -- $type {
123 checkbutton $w.$f.$optid -text $text \
124 -variable ${f}_config_new($name) \
125 -onvalue true \
126 -offvalue false
127 pack $w.$f.$optid -side top -anchor w
129 i-* {
130 regexp -- {-(\d+)\.\.(\d+)$} $type _junk min max
131 frame $w.$f.$optid
132 label $w.$f.$optid.l -text "$text:"
133 pack $w.$f.$optid.l -side left -anchor w -fill x
134 spinbox $w.$f.$optid.v \
135 -textvariable ${f}_config_new($name) \
136 -from $min \
137 -to $max \
138 -increment 1 \
139 -width [expr {1 + [string length $max]}]
140 bind $w.$f.$optid.v <FocusIn> {%W selection range 0 end}
141 pack $w.$f.$optid.v -side right -anchor e -padx 5
142 pack $w.$f.$optid -side top -anchor w -fill x
145 frame $w.$f.$optid
146 label $w.$f.$optid.l -text "$text:"
147 entry $w.$f.$optid.v \
148 -borderwidth 1 \
149 -relief sunken \
150 -width 20 \
151 -textvariable ${f}_config_new($name)
152 pack $w.$f.$optid.l -side left -anchor w
153 pack $w.$f.$optid.v -side left -anchor w \
154 -fill x -expand 1 \
155 -padx 5
156 pack $w.$f.$optid -side top -anchor w -fill x
162 set all_fonts [lsort [font families]]
163 foreach option $font_descs {
164 set name [lindex $option 0]
165 set font [lindex $option 1]
166 set text [eval [lindex $option 2]]
168 set global_config_new(gui.$font^^family) \
169 [font configure $font -family]
170 set global_config_new(gui.$font^^size) \
171 [font configure $font -size]
173 frame $w.global.$name
174 label $w.global.$name.l -text "$text:"
175 button $w.global.$name.b \
176 -text [mc "Change Font"] \
177 -command [list \
178 choose_font::pick \
179 $w \
180 [mc "Choose %s" $text] \
181 global_config_new(gui.$font^^family) \
182 global_config_new(gui.$font^^size) \
184 label $w.global.$name.f -textvariable global_config_new(gui.$font^^family)
185 label $w.global.$name.s -textvariable global_config_new(gui.$font^^size)
186 label $w.global.$name.pt -text [mc "pt."]
187 pack $w.global.$name.l -side left -anchor w
188 pack $w.global.$name.b -side right -anchor e
189 pack $w.global.$name.pt -side right -anchor w
190 pack $w.global.$name.s -side right -anchor w
191 pack $w.global.$name.f -side right -anchor w
192 pack $w.global.$name -side top -anchor w -fill x
195 bind $w <Visibility> "grab $w; focus $w.buttons.save"
196 bind $w <Key-Escape> "destroy $w"
197 bind $w <Key-Return> [list do_save_config $w]
199 if {[is_MacOSX]} {
200 set t [mc "Preferences"]
201 } else {
202 set t [mc "Options"]
204 wm title $w "[appname] ([reponame]): $t"
205 tkwait window $w
208 proc do_restore_defaults {} {
209 global font_descs default_config repo_config
210 global repo_config_new global_config_new
212 foreach name [array names default_config] {
213 set repo_config_new($name) $default_config($name)
214 set global_config_new($name) $default_config($name)
217 foreach option $font_descs {
218 set name [lindex $option 0]
219 set repo_config(gui.$name) $default_config(gui.$name)
221 apply_config
223 foreach option $font_descs {
224 set name [lindex $option 0]
225 set font [lindex $option 1]
226 set global_config_new(gui.$font^^family) \
227 [font configure $font -family]
228 set global_config_new(gui.$font^^size) \
229 [font configure $font -size]
233 proc do_save_config {w} {
234 if {[catch {save_config} err]} {
235 error_popup [strcat [mc "Failed to completely save options:"] "\n\n$err"]
237 reshow_diff
238 destroy $w