# # # patch "lib/perl/Annotate.pm" # from [f80a20fab4e1b51c47331dc69f52153a640b1be9] # to [9a778d09c5f605b1795e81b05eb21f8feb4b1fb0] # # patch "lib/perl/Common.pm" # from [33b20690eec1b473b319b4d1cd1d76c14ed75ed6] # to [425d2a518dae5a26fd5d29793796e3f640b427fc] # # patch "lib/perl/FindFiles.pm" # from [1f7f9f51e6f4c16a4f70e590a7d8907644cc6617] # to [8545f8bea2d6d5b76ff34a5d949a7e29a553315d] # # patch "lib/perl/Globals.pm" # from [d368dbb3992aaf613f8ed630b6c088b22954715e] # to [09cc31511f47475ae3e8c8fdb5d4958175645df7] # # patch "lib/perl/History.pm" # from [89afe8aae1a4b16a8ac2ebc7a31c7f4f8f27b504] # to [7b9c9357c231510a04bb673b076cfbffc4fbb7a0] # # patch "lib/ui/mtn-browse.glade" # from [a3bf967092a7b37ea5ed81d21f8fe0c4788490ed] # to [14a1b707b7ed01890ee689c218fdb0a9a4bfd1ff] # # patch "mtn-browse" # from [38065b65e4d04bd545d489d7e42c4873e610df57] # to [0b1133d1a97872d445664bf5741f29380b98e0c1] # ============================================================ --- lib/perl/Annotate.pm f80a20fab4e1b51c47331dc69f52153a640b1be9 +++ lib/perl/Annotate.pm 9a778d09c5f605b1795e81b05eb21f8feb4b1fb0 @@ -137,8 +137,10 @@ sub display_annotation($$$) for ($i = 0; $i < scalar(@lines); ++ $i) { ($prefix[$i], $lines[$i]) = (unpack($template, $lines[$i]))[0, 2]; - $prefix[$i] = decode_utf8($prefix[$i]); - $lines[$i] = decode_utf8($lines[$i]); + eval + { + $lines[$i] = decode($file_encoding, $lines[$i], Encode::FB_CROAK); + }; $lines[$i] =~ s/\s+$//; $lines[$i] = expand($lines[$i]); $max_len = $len if (($len = length($lines[$i])) > $max_len); ============================================================ --- lib/perl/Common.pm 33b20690eec1b473b319b4d1cd1d76c14ed75ed6 +++ lib/perl/Common.pm 425d2a518dae5a26fd5d29793796e3f640b427fc @@ -185,7 +185,6 @@ sub run_command($@) eval { $pid = open3($fd_in, $fd_out, $fd_err, @args); - binmode($fd_out, ":utf8"); }; # Check for errors (remember that open3() errors can happen in both the ============================================================ --- lib/perl/FindFiles.pm 1f7f9f51e6f4c16a4f70e590a7d8907644cc6617 +++ lib/perl/FindFiles.pm 8545f8bea2d6d5b76ff34a5d949a7e29a553315d @@ -399,7 +399,7 @@ sub search_files_button_clicked_cb($$) # We need to convert the contents pattern from possibly UTF-8 to binary # as we may have to search binary data. - $pattern = encode_utf8($query->{contents_pattern}); + $pattern = encode($file_encoding, $query->{contents_pattern}); if ($query->{contents_pattern_is_regexp}) { ============================================================ --- lib/perl/Globals.pm d368dbb3992aaf613f8ed630b6c088b22954715e +++ lib/perl/Globals.pm 09cc31511f47475ae3e8c8fdb5d4958175645df7 @@ -90,6 +90,10 @@ our $mono_font; our $mono_font; +# The encoding used for file contents. + +our $file_encoding = "utf8"; + # Assorted pixmaps. our $line_image; @@ -129,7 +133,8 @@ our %EXPORT_TAGS = (constants => [qw(ALL REVISION_DETAILS REVISION_LIST SELECTED_REVISION_CHANGED)], - variables => [qw($glade_file + variables => [qw($file_encoding + $glade_file $line_image $mime_match_table $mono_font ============================================================ --- lib/perl/History.pm 89afe8aae1a4b16a8ac2ebc7a31c7f4f8f27b504 +++ lib/perl/History.pm 7b9c9357c231510a04bb673b076cfbffc4fbb7a0 @@ -572,11 +572,13 @@ sub display_revision_comparison($$$;$) $wm->update_gui(); if ($mtn->supports(MTN_CONTENT_DIFF_EXTRA_OPTIONS)) { + $mtn->suppress_utf8_conversion(1); $mtn->content_diff($instance->{diff_output}, ["with-header"], $revision_id_1, $revision_id_2, $file_name); + $mtn->suppress_utf8_conversion(0); } else { @@ -632,8 +634,10 @@ sub display_revision_comparison($$$;$) else { ($char, $rest) = unpack("a1a*", $line); - $char = decode_utf8($char); - $rest = decode_utf8($rest); + eval + { + $rest = decode($file_encoding, $rest, Encode::FB_CROAK); + }; $rest =~ s/\s+$//; $rest = expand($rest); $max_len = $len if (($len = length($rest)) > $max_len); @@ -877,9 +881,14 @@ sub display_revision_comparison($$$;$) else { + my $line = $instance->{diff_output}->[$i]; + eval + { + $line = decode($file_encoding, $line, Encode::FB_CROAK); + }; $instance->{comparison_buffer}->insert ($instance->{comparison_buffer}->get_end_iter(), - $instance->{diff_output}->[$i] . "\n"); + $line . "\n"); } if (($i % 100) == 0) ============================================================ --- lib/ui/mtn-browse.glade a3bf967092a7b37ea5ed81d21f8fe0c4788490ed +++ lib/ui/mtn-browse.glade 14a1b707b7ed01890ee689c218fdb0a9a4bfd1ff @@ -64,7 +64,7 @@ - + True gtk-new 1 @@ -107,7 +107,7 @@ - + True gtk-quit 1 @@ -145,6 +145,26 @@ + + True + GNOMEUIINFO_MENU_VIEW_TREE + + + + + + + True + File Encoding + True + + + + + + + + True GNOMEUIINFO_MENU_HELP_TREE @@ -161,7 +181,7 @@ - + True gtk-help 1 @@ -183,7 +203,7 @@ - + True gtk-help 1 @@ -205,7 +225,7 @@ - + True gtk-help 1 @@ -232,7 +252,7 @@ - + True gtk-home 1 ============================================================ --- mtn-browse 38065b65e4d04bd545d489d7e42c4873e610df57 +++ mtn-browse 0b1133d1a97872d445664bf5741f29380b98e0c1 @@ -1577,8 +1577,13 @@ sub get_browser_window(;$$$$$) if (! defined($browser = $wm->find_unused($window_type))) { - my($image, + my($cb, + @encodings, + $image, + $menu_item, $renderer, + $submenu, + $subsubmenu, $tv_column); $browser = {}; @@ -1602,6 +1607,7 @@ sub get_browser_window(;$$$$$) $browser->{window} = $browser->{glade}->get_widget($window_type); foreach my $widget ("appbar", + "file_encoding_menuitem", "main_vbox", "browser_hpaned", "close_toolbutton", @@ -1628,6 +1634,50 @@ sub get_browser_window(;$$$$$) $browser->{$widget} = $browser->{glade}->get_widget($widget); } + # Setup the character encodings submenu. + + @encodings = sort(Encode->encodings(":all")); + $submenu = Gtk2::Menu->new(); + $cb = sub + { + my($widget, $details) = @_; + return if ($details->{instance}->{in_cb}); + local $details->{instance}->{in_cb} = 1; + $details->{instance}->{appbar}->set_status + (__x("Changed file encoding from `{old_encoding}' to " + . "`{new_encoding}'", + old_encoding => __($file_encoding), + new_encoding => __($details->{encoding}))); + $file_encoding = $details->{encoding}; + }; + for my $encoding ("ascii", "utf8", "UTF-16") + { + $menu_item = Gtk2::MenuItem->new(__($encoding)); + $menu_item->signal_connect("activate", + $cb, + {instance => $browser, + encoding => $encoding}); + $menu_item->show(); + $submenu->append($menu_item); + } + $subsubmenu = Gtk2::Menu->new(); + for my $encoding (@encodings) + { + $menu_item = Gtk2::MenuItem->new(__($encoding)); + $menu_item->signal_connect("activate", + $cb, + {instance => $browser, + encoding => $encoding}); + $menu_item->show(); + $subsubmenu->append($menu_item); + } + $subsubmenu->show(); + $menu_item = Gtk2::MenuItem->new(__("All Encodings")); + $menu_item->set_submenu($subsubmenu); + $menu_item->show(); + $submenu->append($menu_item); + $browser->{file_encoding_menuitem}->set_submenu($submenu); + # Setup button sensitivity groups. $browser->{text_file_sensitive_group} = []; @@ -2941,7 +2991,11 @@ sub display_file($$) # Load in the contents (ensuring UTF-8 encoding). - $contents = decode_utf8($contents); + eval + { + $contents = + decode($file_encoding, $contents, Encode::FB_CROAK); + }; $browser->{file_view_svbuffer}->set_text($contents); }