git-gui: Allow forcing display encoding for diffs using a submenu.
Add a submenu to allow dynamically changing the encoding to use for diffs. Encoding settings are remembered while git-gui runs. The rules are: 1) Encoding set for a specific file overrides gitattributes. 2) Last explicitly set value of the encoding overrides gui.encoding 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
3fe0162362f80262ed1965f19c1f57f298931c94
3 files changed
+44
-2
git-gui.sh
+8
@@ -3010,6 +3010,14 @@ proc create_common_diff_popup {ctxm} {
3010
-command {incr_font_size font_diff 1}
3011
lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3012
$ctxm add separator
3013
+ set emenu $ctxm.enc
3014
+ menu $emenu
3015
+ build_encoding_menu $emenu [list force_diff_encoding]
3016
+ $ctxm add cascade \
3017
+ -label [mc "Encoding"] \
3018
+ -menu $emenu
3019
+ lappend diff_actions [list $ctxm entryconf [$ctxm index last] -state]
3020
+ $ctxm add separator
3021
$ctxm add command -label [mc "Options..."] \
3022
-command do_options
3023
}
lib/diff.tcl
+9
@@ -40,6 +40,15 @@ proc reshow_diff {} {
40
}
41
}
42
43
+proc force_diff_encoding {enc} {
44
+ global current_diff_path
45
+
46
+ if {$current_diff_path ne {}} {
47
+ force_path_encoding $current_diff_path $enc
48
+ reshow_diff
49
+ }
50
+}
51
+
52
proc handle_empty_diff {} {
53
global current_diff_path file_states file_lists
54
lib/encoding.tcl
+27
-2
@@ -321,13 +321,38 @@ proc tcl_encoding {enc} {
321
return {}
322
}
323
324
+proc force_path_encoding {path enc} {
325
+ global path_encoding_overrides last_encoding_override
326
+
327
+ set enc [tcl_encoding $enc]
328
+ if {$enc eq {}} {
329
+ catch { unset last_encoding_override }
330
+ catch { unset path_encoding_overrides($path) }
331
+ } else {
332
+ set last_encoding_override $enc
333
+ if {$path ne {}} {
334
+ set path_encoding_overrides($path) $enc
335
+ }
336
+ }
337
+}
338
+
339
proc get_path_encoding {path} {
325
- set tcl_enc [tcl_encoding [get_config gui.encoding]]
340
+ global path_encoding_overrides last_encoding_override
341
+
342
+ if {[info exists last_encoding_override]} {
343
+ set tcl_enc $last_encoding_override
344
+ } else {
345
+ set tcl_enc [tcl_encoding [get_config gui.encoding]]
346
+ }
347
if {$tcl_enc eq {}} {
348
set tcl_enc [encoding system]
349
}
350
if {$path ne {}} {
330
- set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
351
+ if {[info exists path_encoding_overrides($path)]} {
352
+ set enc2 $path_encoding_overrides($path)
353
+ } else {
354
+ set enc2 [tcl_encoding [gitattr $path encoding $tcl_enc]]
355
+ }
356
if {$enc2 ne {}} {
357
set tcl_enc $enc2
358
}