<UserControl x:Class="MyPad.Views.Regions.DiffContentView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
             xmlns:p="http://prismlibrary.com/"
             xmlns:m="http://metro.mahapps.com/winfx/xaml/controls"
             xmlns:mi="http://metro.mahapps.com/winfx/xaml/iconpacks"
             xmlns:le="http://wpflocalizeextension.codeplex.com"
             xmlns:qc="http://QuickConverter.CodePlex.com/"
             xmlns:ge="clr-namespace:SourceChord.GridExtra;assembly=GridExtra.Wpf"
             xmlns:dp="clr-namespace:DiffPlex.Wpf.Controls;assembly=DiffPlex.Wpf"
             mc:Ignorable="d" 
             p:ViewModelLocator.AutoWireViewModel="True"
             d:DesignHeight="450" d:DesignWidth="800"
             IsVisibleChanged="UserControl_IsVisibleChanged">

    <Grid Margin="20 0 20 20" ge:GridEx.RowDefinition="*, 5, Auto">
        <!--
        INFO: DiffPlex の OldText, NewText に空文字を設定すると例外が発生する問題への対応
        DiffPlex.Wpf v1.1.2 以降で確認された。
        System.InvalidOperationException: Nullable object must have a value. が発生する。
        IsNullOrEmpty に該当する場合は半角スペースに置き換える。
        -->
        <dp:DiffViewer x:Name="DiffViewer"
                       OldText="{qc:Binding 'string.IsNullOrEmpty($P) ? \' \' : $P', P={Binding DiffSource.Value.Document.Text, Mode=OneWay}}"
                       NewText="{qc:Binding 'string.IsNullOrEmpty($P) ? \' \' : $P', P={Binding DiffDestination.Value.Document.Text, Mode=OneWay}}"
                       OldTextHeader="{qc:MultiBinding 'Path.GetDirectoryName($P0) == Path.GetDirectoryName($P1) ? Path.GetFileName($P0) : $P0', P0={Binding DiffSource.Value.FileName, Mode=OneWay}, P1={Binding DiffDestination.Value.FileName, Mode=OneWay}}"
                       NewTextHeader="{qc:MultiBinding 'Path.GetDirectoryName($P0) == Path.GetDirectoryName($P1) ? Path.GetFileName($P1) : $P1', P0={Binding DiffSource.Value.FileName, Mode=OneWay}, P1={Binding DiffDestination.Value.FileName, Mode=OneWay}}"
                       Opacity="{qc:MultiBinding '$P0 == $P1 ? 0.2 : 1.0', P0={Binding DiffSource.Value.Document.Text, Mode=OneWay}, P1={Binding DiffDestination.Value.Document.Text, Mode=OneWay}}"/>
        
        <Grid Visibility="{qc:MultiBinding '$P0 == $P1 ? Visibility.Visible : Visibility.Collapsed', P0={Binding DiffSource.Value.Document.Text, Mode=OneWay}, P1={Binding DiffDestination.Value.Document.Text, Mode=OneWay}}">
            <Border d:IsHidden="True" Style="{StaticResource Common.Overlay}">
                <StackPanel Margin="5 0" HorizontalAlignment="Stretch" VerticalAlignment="Center">
                    <TextBlock Text="{le:Loc Text_SameTexts}" HorizontalAlignment="Center" TextAlignment="Center"/>
                </StackPanel>
            </Border>
        </Grid>

        <CheckBox Grid.Row="2" HorizontalAlignment="Right"
                  IsChecked="{Binding Settings.Misc.ShowInlineDiffViewer, Mode=TwoWay}" Content="{le:Loc LabelText_ShowInlineDiffViewer}"
                  Checked="ShowInlineDiffViewer_Checked" Unchecked="ShowInlineDiffViewer_Unchecked"/>
    </Grid>
    
</UserControl>
