<Window x:Class="FooEditor.ConfigDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:FooEditor"
        xmlns:cp="http://schemas.xceed.com/wpf/xaml/toolkit"
        xmlns:foo="clr-namespace:FooEditEngine;assembly=FooEditEngine.WPF"
        Title="設定"
        Width="400"
        Height="375">
    <Window.Resources>
        <Style x:Key="NumberCheck" TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="True">
                    <Setter Property="ToolTip"   
                        Value="{Binding RelativeSource={x:Static RelativeSource.Self}, Path=(Validation.Errors)[0].ErrorContent}" />
                </Trigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="UnitStyle" TargetType="Label">
            <Style.Triggers>
                <DataTrigger Binding="{Binding IsMetric}" Value="false">
                    <Setter Property="Content" Value="インチ"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding IsMetric}" Value="true">
                    <Setter Property="Content" Value="ミリ"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
        <ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="TextAntialiasModes">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="foo:TextAntialiasMode" />
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
    </Window.Resources>
    <Window.BindingGroup>
        <BindingGroup Name="AccountBindings"/>
    </Window.BindingGroup>
    <StackPanel>
        <TabControl Height="300" Width="380">
            <TabItem Header="全般">
                <TabItem.Content>
                    <StackPanel Margin="5,5,5,5">
                        <Grid Margin="0,0,0,5">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="2*"/>
                                <ColumnDefinition Width="1*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                                <RowDefinition/>
                            </Grid.RowDefinitions>
                            <Label Grid.Row="0" Grid.Column="0">タブの幅</Label>
                            <TextBox Grid.Row="0" Grid.Column="1" Style="{StaticResource NumberCheck}">
                                <TextBox.Text>
                                    <Binding Path="Config.TabStops" UpdateSourceTrigger="Explicit" BindingGroupName="AccountBindings">
                                        <Binding.ValidationRules>
                                            <ExceptionValidationRule/>
                                        </Binding.ValidationRules>
                                    </Binding>
                                </TextBox.Text>
                            </TextBox>
                            <Label Grid.Row="1" Grid.Column="0">ファイル履歴の最大数</Label>
                            <TextBox Grid.Row="1" Grid.Column="1" Style="{StaticResource NumberCheck}">
                                <TextBox.Text>
                                    <Binding Path="Config.RecentMaxCount" UpdateSourceTrigger="Explicit" BindingGroupName="AccountBindings">
                                        <Binding.ValidationRules>
                                            <ExceptionValidationRule/>
                                        </Binding.ValidationRules>
                                    </Binding>
                                </TextBox.Text>
                            </TextBox>
                            <Label Grid.Row="2" Grid.Column="0">バックアップの世代数</Label>
                            <TextBox Grid.Row="2" Grid.Column="1" Style="{StaticResource NumberCheck}">
                                <TextBox.Text>
                                    <Binding Path="Config.MaxBackupCount" UpdateSourceTrigger="Explicit" BindingGroupName="AccountBindings">
                                        <Binding.ValidationRules>
                                            <ExceptionValidationRule/>
                                        </Binding.ValidationRules>
                                    </Binding>
                                </TextBox.Text>
                            </TextBox>
                            <Label Grid.Row="3" Grid.Column="0">自動保存の開始回数</Label>
                            <TextBox Grid.Row="3" Grid.Column="1" Style="{StaticResource NumberCheck}">
                                <TextBox.Text>
                                    <Binding Path="Config.AutoSaveCount" UpdateSourceTrigger="Explicit" BindingGroupName="AccountBindings">
                                        <Binding.ValidationRules>
                                            <ExceptionValidationRule/>
                                        </Binding.ValidationRules>
                                    </Binding>
                                </TextBox.Text>
                            </TextBox>
                        </Grid>
                        <CheckBox IsChecked="{Binding Config.DrawLine, UpdateSourceTrigger=Explicit}">ラインマーカーを表示する</CheckBox>
                        <CheckBox IsChecked="{Binding Config.WordRap, UpdateSourceTrigger=Explicit}">ウィンドウの右端で折り返す</CheckBox>
                        <CheckBox IsChecked="{Binding Config.DrawLineNumber, UpdateSourceTrigger=Explicit}">行番号を表示する</CheckBox>
                        <CheckBox IsChecked="{Binding Config.UrlMark, UpdateSourceTrigger=Explicit}">URLに下線を引く</CheckBox>
                        <CheckBox IsChecked="{Binding Config.AutoIndent, UpdateSourceTrigger=Explicit}">オートインデントを行う</CheckBox>
                    </StackPanel>
                </TabItem.Content>
            </TabItem>
            <TabItem Header="印刷">
                <TabItem.Content>
                    <Grid Margin="5">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="2*"/>
                            <ColumnDefinition Width="3*"/>
                            <ColumnDefinition Width="1*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="24"/>
                            <RowDefinition Height="24"/>
                            <RowDefinition Height="24"/>
                            <RowDefinition Height="24"/>
                            <RowDefinition Height="24"/>
                            <RowDefinition Height="24"/>
                        </Grid.RowDefinitions>
                        <Label Grid.Row="0" Grid.Column="0">上の余白</Label>
                        <TextBox Grid.Row="0" Grid.Column="1" Style="{StaticResource NumberCheck}">
                            <TextBox.Text>
                                <Binding Path="Config.TopSpace" UpdateSourceTrigger="Explicit" BindingGroupName="AccountBindings">
                                    <Binding.ValidationRules>
                                        <ExceptionValidationRule/>
                                    </Binding.ValidationRules>
                                </Binding>
                            </TextBox.Text>
                        </TextBox>
                        <Label Grid.Row="0" Grid.Column="2" Style="{StaticResource UnitStyle}"/>
                        <Label Grid.Row="1" Grid.Column="0">右の余白</Label>
                        <TextBox Grid.Row="1" Grid.Column="1" Style="{StaticResource NumberCheck}">
                            <TextBox.Text>
                                <Binding Path="Config.RightSpace" UpdateSourceTrigger="Explicit" BindingGroupName="AccountBindings">
                                    <Binding.ValidationRules>
                                        <ExceptionValidationRule/>
                                    </Binding.ValidationRules>
                                </Binding>
                            </TextBox.Text>
                        </TextBox>
                        <Label Grid.Row="1" Grid.Column="2" Style="{StaticResource UnitStyle}"/>
                        <Label Grid.Row="2" Grid.Column="0">下の余白</Label>
                        <TextBox Grid.Row="2" Grid.Column="1" Style="{StaticResource NumberCheck}">
                            <TextBox.Text>
                                <Binding Path="Config.BottomSpace" UpdateSourceTrigger="Explicit" BindingGroupName="AccountBindings">
                                    <Binding.ValidationRules>
                                        <ExceptionValidationRule/>
                                    </Binding.ValidationRules>
                                </Binding>
                            </TextBox.Text>
                        </TextBox>
                        <Label Grid.Row="2" Grid.Column="2" Style="{StaticResource UnitStyle}"/>
                        <Label Grid.Row="3" Grid.Column="0">左の余白</Label>
                        <TextBox Grid.Row="3" Grid.Column="1" Style="{StaticResource NumberCheck}">
                            <TextBox.Text>
                                <Binding Path="Config.LeftSpace" UpdateSourceTrigger="Explicit" BindingGroupName="AccountBindings">
                                    <Binding.ValidationRules>
                                        <ExceptionValidationRule/>
                                    </Binding.ValidationRules>
                                </Binding>
                            </TextBox.Text>
                        </TextBox>
                        <Label Grid.Row="3" Grid.Column="2" Style="{StaticResource UnitStyle}"/>
                        <Label Grid.Row="4" Grid.Column="0">ヘッダー</Label>
                        <TextBox Grid.Row="4" Grid.Column="1">
                            <TextBox.Text>
                                <Binding Path="Config.Header" UpdateSourceTrigger="Explicit" BindingGroupName="AccountBindings">
                                    <Binding.ValidationRules>
                                        <ExceptionValidationRule/>
                                    </Binding.ValidationRules>
                                </Binding>
                            </TextBox.Text>
                        </TextBox>
                        <Label Grid.Row="5" Grid.Column="0">フッター</Label>
                        <TextBox Grid.Row="5" Grid.Column="1">
                            <TextBox.Text>
                                <Binding Path="Config.Footer" UpdateSourceTrigger="Explicit" BindingGroupName="AccountBindings">
                                    <Binding.ValidationRules>
                                        <ExceptionValidationRule/>
                                    </Binding.ValidationRules>
                                </Binding>
                            </TextBox.Text>
                        </TextBox>
                    </Grid>
                </TabItem.Content>
            </TabItem>
            <TabItem Header="文章モード">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <StackPanel Orientation="Vertical" Grid.Column="0" Margin="0,0,5,0">
                        <ListBox Name="SyntaxNameList" Height="230" DisplayMemberPath="Name">
                            <ListBox.ItemsSource>
                                <Binding Path="DocumentTypeCollection"/>
                            </ListBox.ItemsSource>
                        </ListBox>
                        <StackPanel Orientation="Horizontal" Margin="0,5,0,0" HorizontalAlignment="Center">
                            <Button Name="AddSyntax" Content="追加" Width="50" Margin="0,0,5,0" Click="AddSyntax_Click"/>
                            <Button Name="RemoveSyntax" Content="削除" Width="50" Click="RemoveSyntax_Click"/>
                        </StackPanel>
                    </StackPanel>
                    <StackPanel Orientation="Vertical" Grid.Column="1">
                        <Label>ファイル名</Label>
                        <TextBox Name="SyntaxFileName">
                            <TextBox.Text>
                                <Binding Path="SelectedItem.Name" ElementName="SyntaxNameList" Mode="TwoWay"/>
                            </TextBox.Text>
                        </TextBox>
                        <Label>対象となる拡張子</Label>
                        <TextBox Name="TargetExtension">
                            <TextBox.Text>
                                <Binding Path="SelectedItem.Extension" ElementName="SyntaxNameList" Mode="TwoWay"/>
                            </TextBox.Text>
                        </TextBox>
                    </StackPanel>
                </Grid>
            </TabItem>
            <TabItem Header="表示">
                <StackPanel Orientation="Vertical">
                    <Grid Margin="0,0,0,5">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="1*" />
                            <ColumnDefinition Width="2*" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Label Grid.Column="0" Grid.Row="0">フォント名</Label>
                        <ComboBox Name="FontList" Grid.Column="1"/>
                        <Label Grid.Column="0" Grid.Row="1">フォントサイズ</Label>
                        <TextBox Grid.Column="1"  Grid.Row="1" Style="{StaticResource NumberCheck}">
                            <TextBox.Text>
                                <Binding Path="Config.FontSize" UpdateSourceTrigger="Explicit" BindingGroupName="AccountBindings">
                                    <Binding.ValidationRules>
                                        <ExceptionValidationRule/>
                                    </Binding.ValidationRules>
                                </Binding>
                            </TextBox.Text>
                        </TextBox>
                        <Label Grid.Column="0"  Grid.Row="2">レタリングモード</Label>
                        <ComboBox Grid.Column="1"  Grid.Row="2" ItemsSource="{Binding Source={StaticResource TextAntialiasModes}}" SelectedItem="{Binding Config.TextAntialiasMode, UpdateSourceTrigger=Explicit,BindingGroupName=AccountBindings}"/>
                    </Grid>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="2*"/>
                            <ColumnDefinition Width="1*"/>
                            <ColumnDefinition Width="2*"/>
                            <ColumnDefinition Width="1*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <Label Grid.Column="0" Grid.Row="0">文字色</Label>
                        <cp:ColorPicker Grid.Column="1" Grid.Row="0" SelectedColor="{Binding Config.Fore, UpdateSourceTrigger=Explicit, BindingGroupName=AccountBindings}"/>
                        <Label Grid.Column="0" Grid.Row="1">背景色</Label>
                        <cp:ColorPicker Grid.Column="1" Grid.Row="1" SelectedColor="{Binding Config.Back, UpdateSourceTrigger=Explicit, BindingGroupName=AccountBindings}"/>
                        <Label Grid.Column="0" Grid.Row="2">キーワード１</Label>
                        <cp:ColorPicker Grid.Column="1" Grid.Row="2" SelectedColor="{Binding Config.Keyword1, UpdateSourceTrigger=Explicit, BindingGroupName=AccountBindings}"/>
                        <Label Grid.Column="0" Grid.Row="3">キーワード２</Label>
                        <cp:ColorPicker Grid.Column="1" Grid.Row="3" SelectedColor="{Binding Config.Keyword2, UpdateSourceTrigger=Explicit, BindingGroupName=AccountBindings}"/>
                        <Label Grid.Column="0" Grid.Row="4">コメント</Label>
                        <cp:ColorPicker Grid.Column="1" Grid.Row="4" SelectedColor="{Binding Config.Comment, UpdateSourceTrigger=Explicit, BindingGroupName=AccountBindings}"/>
                        <Label Grid.Column="0" Grid.Row="5">リテラル</Label>
                        <cp:ColorPicker Grid.Column="1" Grid.Row="5" SelectedColor="{Binding Config.Literal, UpdateSourceTrigger=Explicit, BindingGroupName=AccountBindings}"/>
                        <Label Grid.Column="0" Grid.Row="6">URL</Label>
                        <cp:ColorPicker Grid.Column="1" Grid.Row="6" SelectedColor="{Binding Config.URL, UpdateSourceTrigger=Explicit, BindingGroupName=AccountBindings}"/>
                        <Label Grid.Column="2" Grid.Row="0">選択色</Label>
                        <cp:ColorPicker Grid.Column="3" Grid.Row="0" SelectedColor="{Binding Config.Hilight, UpdateSourceTrigger=Explicit, BindingGroupName=AccountBindings}"/>
                        <Label Grid.Column="2" Grid.Row="1">コントロール</Label>
                        <cp:ColorPicker Grid.Column="3" Grid.Row="1" SelectedColor="{Binding Config.Control, UpdateSourceTrigger=Explicit, BindingGroupName=AccountBindings}"/>
                        <Label Grid.Column="2" Grid.Row="2">キャレット(上書時)</Label>
                        <cp:ColorPicker Grid.Column="3" Grid.Row="2" SelectedColor="{Binding Config.OverwriteCaret, UpdateSourceTrigger=Explicit, BindingGroupName=AccountBindings}"/>
                        <Label Grid.Column="2" Grid.Row="3">キャレット(挿入時)</Label>
                        <cp:ColorPicker Grid.Column="3" Grid.Row="3" SelectedColor="{Binding Config.InsetCaret, UpdateSourceTrigger=Explicit, BindingGroupName=AccountBindings}"/>
                        <Label Grid.Column="2" Grid.Row="4">ラインマーカー</Label>
                        <cp:ColorPicker Grid.Column="3" Grid.Row="4" SelectedColor="{Binding Config.LineMarker, UpdateSourceTrigger=Explicit, BindingGroupName=AccountBindings}"/>
                    </Grid>
                </StackPanel>
            </TabItem>
            <TabItem Header="プラグイン">
                <StackPanel>
                    <ListView Name="PluginList" Height="200">
                        <ListView.ItemContainerStyle>
                            <Style TargetType="{x:Type ListViewItem}">
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding Version}" Value="">
                                        <Setter Property="Foreground" Value="Gray"/>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </ListView.ItemContainerStyle>
                        <ListView.View>
                            <GridView>
                                <GridViewColumn Header="プラグイン名" DisplayMemberBinding="{Binding Name}"/>
                                <GridViewColumn Header="バージョン" DisplayMemberBinding="{Binding Version}"/>
                            </GridView>
                        </ListView.View>
                    </ListView>
                    <Label Content="※反映させるには再起動が必要です" />
                    <StackPanel Orientation="Horizontal" Margin="0,5,0,5" HorizontalAlignment="Right">
                        <Button Name="ConfigButton" Height="24" Content="設定" Width="80" Click="Config_Click"/>
                        <Button Name="TogglePlugin" Height="24" Width="80" Margin="10,0,0,0" Click="TogglePlugin_Click">
                            <Button.Style>
                                <Style TargetType="Button">
                                    <Style.Setters>
                                        <Setter Property="Content" Value="無効化"/>
                                    </Style.Setters>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding SelectedItem.Version, ElementName=PluginList}" Value="">
                                            <Setter Property="Content" Value="有効化"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </Button.Style>
                        </Button>
                    </StackPanel>
                </StackPanel>
            </TabItem>
        </TabControl>
        <StackPanel Orientation="Horizontal" Margin="0,5,5,5" HorizontalAlignment="Right">
            <Button Name="OK" Height="24" Content="OK" Width="80" Click="OK_Click"/>
            <Button Name="Cancle" Height="24" Content="キャンセル" Width="80" Margin="10,0,0,0" Click="Cancle_Click"/>
        </StackPanel>
    </StackPanel>
</Window>
