@matheusbsbs / matheus-bagliano / commits / 50102c5687
Fork 0

git-gui: Add a menu of available encodings.

To make encoding selection easier, add a menu that lists available encodings to the Options window. Menu structure is borrowed from Firefox. Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com> Tested-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Alexander Gavrilov committed Sep 18, 2008 at 01:07 UTC 50102c5687db83db48b9705e07de16d07cef7cd9
2 files changed +142 -4
lib/encoding.tcl
+130 -3
@@ -206,7 +206,7 @@ set encoding_aliases {
206 { ISO-8859-16 iso-ir-226 ISO_8859-16:2001 ISO_8859-16 latin10 l10 }
207 { GBK CP936 MS936 windows-936 }
208 { JIS_Encoding csJISEncoding }
209 - { Shift_JIS MS_Kanji csShiftJIS }
209 + { Shift_JIS MS_Kanji csShiftJIS ShiftJIS Shift-JIS }
210 { Extended_UNIX_Code_Packed_Format_for_Japanese csEUCPkdFmtJapanese
211 EUC-JP }
212 { Extended_UNIX_Code_Fixed_Width_for_Japanese csEUCFixWidJapanese }
@@ -240,6 +240,52 @@ set encoding_aliases {
240 { Big5 csBig5 }
241 }
242
243 +set encoding_groups {
244 + {"" ""
245 + {"Unicode" UTF-8}
246 + {"Western" ISO-8859-1}}
247 + {we "West European"
248 + {"Western" ISO-8859-15 CP-437 CP-850 MacRoman CP-1252 Windows-1252}
249 + {"Celtic" ISO-8859-14}
250 + {"Greek" ISO-8859-14 ISO-8859-7 CP-737 CP-869 MacGreek CP-1253 Windows-1253}
251 + {"Icelandic" MacIceland MacIcelandic CP-861}
252 + {"Nordic" ISO-8859-10 CP-865}
253 + {"Portuguese" CP-860}
254 + {"South European" ISO-8859-3}}
255 + {ee "East European"
256 + {"Baltic" CP-775 ISO-8859-4 ISO-8859-13 CP-1257 Windows-1257}
257 + {"Central European" CP-852 ISO-8859-2 MacCE CP-1250 Windows-1250}
258 + {"Croatian" MacCroatian}
259 + {"Cyrillic" CP-855 ISO-8859-5 ISO-IR-111 KOI8-R MacCyrillic CP-1251 Windows-1251}
260 + {"Russian" CP-866}
261 + {"Ukrainian" KOI8-U MacUkraine MacUkrainian}
262 + {"Romanian" ISO-8859-16 MacRomania MacRomanian}}
263 + {ea "East Asian"
264 + {"Generic" ISO-2022}
265 + {"Chinese Simplified" GB2312 GB1988 GB12345 GB2312-RAW GBK EUC-CN GB18030 HZ ISO-2022-CN}
266 + {"Chinese Traditional" Big5 Big5-HKSCS EUC-TW CP-950}
267 + {"Japanese" EUC-JP ISO-2022-JP Shift-JIS JIS-0212 JIS-0208 JIS-0201 CP-932 MacJapan}
268 + {"Korean" EUC-KR UHC JOHAB ISO-2022-KR CP-949 KSC5601}}
269 + {sa "SE & SW Asian"
270 + {"Armenian" ARMSCII-8}
271 + {"Georgian" GEOSTD8}
272 + {"Thai" TIS-620 ISO-8859-11 CP-874 Windows-874 MacThai}
273 + {"Turkish" CP-857 CP857 ISO-8859-9 MacTurkish CP-1254 Windows-1254}
274 + {"Vietnamese" TCVN VISCII VPS CP-1258 Windows-1258}
275 + {"Hindi" MacDevanagari}
276 + {"Gujarati" MacGujarati}
277 + {"Gurmukhi" MacGurmukhi}}
278 + {me "Middle Eastern"
279 + {"Arabic" ISO-8859-6 Windows-1256 CP-1256 CP-864 MacArabic}
280 + {"Farsi" MacFarsi}
281 + {"Hebrew" ISO-8859-8-I Windows-1255 CP-1255 ISO-8859-8 CP-862 MacHebrew}}
282 + {mi "Misc"
283 + {"7-bit" ASCII}
284 + {"16-bit" Unicode}
285 + {"Legacy" CP-863 EBCDIC}
286 + {"Symbol" Symbol Dingbats MacDingbats MacCentEuro}}
287 +}
288 +
289 proc tcl_encoding {enc} {
290 global encoding_aliases
291 set names [encoding names]
@@ -248,7 +294,7 @@ proc tcl_encoding {enc} {
294 set i [lsearch -exact $lcnames $enc]
295 if {$i < 0} {
296 # look for "isonnn" instead of "iso-nnn" or "iso_nnn"
251 - if {[regsub {^iso[-_]} $enc iso encx]} {
297 + if {[regsub {^(iso|cp|ibm|jis)[-_]} $enc {\1} encx]} {
298 set i [lsearch -exact $lcnames $encx]
299 }
300 }
@@ -260,7 +306,7 @@ proc tcl_encoding {enc} {
306 foreach e $ll {
307 set i [lsearch -exact $lcnames $e]
308 if {$i < 0} {
263 - if {[regsub {^iso[-_]} $e iso ex]} {
309 + if {[regsub {^(iso|cp|ibm|jis)[-_]} $e {\1} ex]} {
310 set i [lsearch -exact $lcnames $ex]
311 }
312 }
@@ -288,3 +334,84 @@ proc get_path_encoding {path} {
334 }
335 return $tcl_enc
336 }
337 +
338 +proc build_encoding_submenu {parent grp cmd} {
339 + global used_encodings
340 +
341 + set mid [lindex $grp 0]
342 + set gname [mc [lindex $grp 1]]
343 +
344 + set smenu {}
345 + foreach subset [lrange $grp 2 end] {
346 + set name [mc [lindex $subset 0]]
347 +
348 + foreach enc [lrange $subset 1 end] {
349 + set tcl_enc [tcl_encoding $enc]
350 + if {$tcl_enc eq {}} continue
351 +
352 + if {$smenu eq {}} {
353 + if {$mid eq {}} {
354 + set smenu $parent
355 + } else {
356 + set smenu "$parent.$mid"
357 + menu $smenu
358 + $parent add cascade \
359 + -label $gname \
360 + -menu $smenu
361 + }
362 + }
363 +
364 + if {$name ne {}} {
365 + set lbl "$name ($enc)"
366 + } else {
367 + set lbl $enc
368 + }
369 + $smenu add command \
370 + -label $lbl \
371 + -command [concat $cmd [list $tcl_enc]]
372 +
373 + lappend used_encodings $tcl_enc
374 + }
375 + }
376 +}
377 +
378 +proc popup_btn_menu {m b} {
379 + tk_popup $m [winfo pointerx $b] [winfo pointery $b]
380 +}
381 +
382 +proc build_encoding_menu {emenu cmd {nodef 0}} {
383 + $emenu configure -postcommand \
384 + [list do_build_encoding_menu $emenu $cmd $nodef]
385 +}
386 +
387 +proc do_build_encoding_menu {emenu cmd {nodef 0}} {
388 + global used_encodings encoding_groups
389 +
390 + $emenu configure -postcommand {}
391 +
392 + if {!$nodef} {
393 + $emenu add command \
394 + -label [mc "Default"] \
395 + -command [concat $cmd [list {}]]
396 + }
397 + set sysenc [encoding system]
398 + $emenu add command \
399 + -label [mc "System (%s)" $sysenc] \
400 + -command [concat $cmd [list $sysenc]]
401 +
402 + # Main encoding tree
403 + set used_encodings [list identity]
404 + $emenu add separator
405 + foreach grp $encoding_groups {
406 + build_encoding_submenu $emenu $grp $cmd
407 + }
408 +
409 + # Add unclassified encodings
410 + set unused_grp [list [mc Other]]
411 + foreach enc [encoding names] {
412 + if {[lsearch -exact $used_encodings $enc] < 0} {
413 + lappend unused_grp $enc
414 + }
415 + }
416 + build_encoding_submenu $emenu [list other [mc Other] $unused_grp] $cmd
417 +}
lib/option.tcl
+12 -1
@@ -152,7 +152,7 @@ proc do_options {} {
152 {i-1..99 gui.diffcontext {mc "Number of Diff Context Lines"}}
153 {i-0..99 gui.commitmsgwidth {mc "Commit Message Text Width"}}
154 {t gui.newbranchtemplate {mc "New Branch Name Template"}}
155 - {t gui.encoding {mc "Default File Contents Encoding"}}
155 + {c gui.encoding {mc "Default File Contents Encoding"}}
156 } {
157 set type [lindex $option 0]
158 set name [lindex $option 1]
@@ -182,6 +182,7 @@ proc do_options {} {
182 pack $w.$f.$optid.v -side right -anchor e -padx 5
183 pack $w.$f.$optid -side top -anchor w -fill x
184 }
185 + c -
186 t {
187 frame $w.$f.$optid
188 label $w.$f.$optid.l -text "$text:"
@@ -194,6 +195,16 @@ proc do_options {} {
195 pack $w.$f.$optid.v -side left -anchor w \
196 -fill x -expand 1 \
197 -padx 5
198 + if {$type eq {c}} {
199 + menu $w.$f.$optid.m
200 + build_encoding_menu $w.$f.$optid.m \
201 + [list set ${f}_config_new($name)] 1
202 + button $w.$f.$optid.b \
203 + -text [mc "Change"] \
204 + -command [list popup_btn_menu \
205 + $w.$f.$optid.m $w.$f.$optid.b]
206 + pack $w.$f.$optid.b -side left -anchor w
207 + }
208 pack $w.$f.$optid -side top -anchor w -fill x
209 }
210 }