<m:MetroWindow x:Class="MyPad.Views.MainWindow"
               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:l="http://schemas.livet-mvvm.net/2011/wpf"
               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:pb="clr-namespace:WinCopies.Util.Data;assembly=WinCopies.Util.Desktop"
               xmlns:dr="clr-namespace:Dragablz;assembly=Dragablz"
               xmlns:ae="http://icsharpcode.net/sharpdevelop/avalonedit"
               xmlns:s="clr-namespace:System;assembly=System.Runtime"
               xmlns:viewModels="clr-namespace:MyPad.ViewModels"
               xmlns:views="clr-namespace:MyPad.Views"
               xmlns:behaviors="clr-namespace:MyPad.Views.Behaviors"
               xmlns:controls="clr-namespace:MyPad.Views.Controls"
               xmlns:markup="clr-namespace:MyPad.Views.Markup"
               xmlns:regions="clr-namespace:MyPad.Views.Regions"
               d:DataContext="{d:DesignInstance {x:Type viewModels:MainWindowViewModel}}"
               mc:Ignorable="d"
               p:ViewModelLocator.AutoWireViewModel="True"
               Style="{StaticResource Common.Window}"
               FontFamily="{Binding Settings.System.FontFamily, Mode=OneWay}"
               Title="{qc:MultiBinding '($P0 ? $P1 : Path.GetFileName($P1)) + ($P2 ? \'*\' : null) + \' \- \' + $P3',
                       P0={Binding Settings.System.ShowFullName, Mode=OneWay},
                       P1={Binding ActiveTextEditor.Value.FileName, Mode=OneWay},
                       P2={Binding ActiveTextEditor.Value.IsModified, Mode=OneWay},
                       P3={Binding ProductInfo.Product, Mode=OneWay}}"
               TitleBarHeight="{qc:MultiBinding '$P0.CompareTo(Math.Ceiling($P1.LineSpacing * $P2) + 5) == 1 ? $P0 : Math.Ceiling($P1.LineSpacing * $P2) + 5',
                                P0={Binding Source={StaticResource Const.WindowButtonCommands.Height}},
                                P1={Binding Settings.System.FontFamily, Mode=OneWay},
                                P2={Binding Source={StaticResource Const.FontDpiSize}}}"
               Cursor="{qc:Binding '$P ? Cursors.Wait : Cursors.Arrow', P={Binding IsPending.Value, Mode=OneWay}}"
               ResizeMode="{qc:Binding '$P ? ResizeMode.CanResizeWithGrip : ResizeMode.CanResize', P={Binding Settings.System.ShowStatusBar, Mode=OneWay}}" 
               Height="525" Width="850" WindowStartupLocation="CenterScreen" AllowDrop="{Binding IsEditMode.Value, Mode=OneWay}"
               Loaded="Window_Loaded" ContentRendered="Window_ContentRendered" Closed="Window_Closed" DataContextChanged="Window_DataContextChanged">

    <!-- イベントトリガー -->
    <i:Interaction.Triggers>
        <l:InteractionMessageTrigger MessageKey="Activate" Messenger="{Binding Messenger, Mode=OneWay}">
            <behaviors:WindowActivateAction/>
        </l:InteractionMessageTrigger>
        <l:InteractionMessageTrigger MessageKey="ScrollToCaret" Messenger="{Binding Messenger, Mode=OneWay}">
            <i:CallMethodAction MethodName="ScrollToCaret" TargetObject="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Mode=OneWay}"/>
        </l:InteractionMessageTrigger>
        <i:EventTrigger EventName="ContentRendered">
            <behaviors:WindowActivateAction/>
        </i:EventTrigger>
        <i:EventTrigger EventName="Drop">
            <i:InvokeCommandAction Command="{Binding DropHandler, Mode=OneTime}" PassEventArgsToCommand="True"/>
        </i:EventTrigger>
        <i:EventTrigger EventName="Closing">
            <i:InvokeCommandAction Command="{Binding ClosingHandler, Mode=OneTime}" PassEventArgsToCommand="True"/>
        </i:EventTrigger>
    </i:Interaction.Triggers>

    <!-- リソース -->
    <Window.Resources>
        <Style x:Key="RegionContent" TargetType="{x:Type ContentControl}">
            <Setter Property="p:RegionManager.RegionManager" Value="{Binding RegionManager, RelativeSource={RelativeSource AncestorType={x:Type Window}}, Mode=OneWay}"/>
            <Setter Property="Focusable" Value="False"/>
        </Style>
        <Style TargetType="{x:Type m:Flyout}" BasedOn="{StaticResource Common.Flyout}">
            <EventSetter Event="IsOpenChanged" Handler="Flyout_IsOpenChanged"/>
            <Setter Property="Position" Value="Left"/>
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
            <Setter Property="IsModal" Value="True"/>
            <Setter Property="CloseButtonIsCancel" Value="True"/>
        </Style>
        <ContextMenu x:Key="ContextMenu">
            <MenuItem IsCheckable="True" IsChecked="{Binding Settings.System.ShowMenuBar,   Mode=TwoWay}" Header="{le:Loc Command_ShowMenuBar}"/>
            <MenuItem IsCheckable="True" IsChecked="{Binding Settings.System.ShowToolBar,   Mode=TwoWay}" Header="{le:Loc Command_ShowToolBar}"/>
            <MenuItem IsCheckable="True" IsChecked="{Binding Settings.System.ShowSideBar,   Mode=TwoWay}" Header="{le:Loc Command_ShowSideBar}"/>
            <MenuItem IsCheckable="True" IsChecked="{Binding Settings.System.ShowStatusBar, Mode=TwoWay}" Header="{le:Loc Command_ShowStatusBar}"/>
        </ContextMenu>
    </Window.Resources>

    <!-- 入力バインディング -->
    <Window.InputBindings>
        <KeyBinding Command="{Binding NewCommand,                 Mode=OneTime}" Gesture="{markup:CommandKeyGesture NewCommand}"/>
        <KeyBinding Command="{Binding NewWindowCommand,           Mode=OneTime}" Gesture="{markup:CommandKeyGesture NewWindowCommand}"/>
        <KeyBinding Command="{Binding OpenCommand,                Mode=OneTime}" Gesture="{markup:CommandKeyGesture OpenCommand}"/>
        <KeyBinding Command="{Binding SaveCommand,                Mode=OneTime}" Gesture="{markup:CommandKeyGesture SaveCommand}"/>
        <KeyBinding Command="{Binding SaveAsCommand,              Mode=OneTime}" Gesture="{markup:CommandKeyGesture SaveAsCommand}"/>
        <KeyBinding Command="{Binding SaveAllCommand,             Mode=OneTime}" Gesture="{markup:CommandKeyGesture SaveAllCommand}"/>
        <KeyBinding Command="{Binding ExitApplicationCommand,     Mode=OneTime}" Gesture="{markup:CommandKeyGesture ExitApplicationCommand}"/>
        <KeyBinding Command="{Binding CloseCommand,               Mode=OneTime}" Gesture="{markup:CommandKeyGesture CloseCommand}"/>
        <KeyBinding Command="{Binding CloseAllCommand,            Mode=OneTime}" Gesture="{markup:CommandKeyGesture CloseAllCommand}"/>
        <KeyBinding Command="{Binding CloseOtherCommand,          Mode=OneTime}" Gesture="{markup:CommandKeyGesture CloseOtherCommand}"/>
        <KeyBinding Command="{Binding PrintDirectCommand,         Mode=OneTime}" Gesture="{markup:CommandKeyGesture PrintDirectCommand}"/>
        <KeyBinding Command="{Binding PrintPreviewCommand,        Mode=OneTime}" Gesture="{markup:CommandKeyGesture PrintPreviewCommand}"/>
        <KeyBinding Command="{Binding OptionCommand,              Mode=OneTime}" Gesture="{markup:CommandKeyGesture OptionCommand}"/>
        <KeyBinding Command="{Binding MaintenanceCommand,         Mode=OneTime}" Gesture="{markup:CommandKeyGesture MaintenanceCommand}"/>
        <KeyBinding Command="{Binding AboutCommand,               Mode=OneTime}" Gesture="{markup:CommandKeyGesture AboutCommand}"/>
        <KeyBinding Command="{Binding ShortcutKeysCommand,        Mode=OneTime}" Gesture="{markup:CommandKeyGesture ShortcutKeysCommand}"/>
        <KeyBinding Command="{Binding GoToLineCommand,            Mode=OneTime}" Gesture="{markup:CommandKeyGesture GoToLineCommand}"/>
        <KeyBinding Command="{Binding ChangeEncodingCommand,      Mode=OneTime}" Gesture="{markup:CommandKeyGesture ChangeEncodingCommand}"/>
        <KeyBinding Command="{Binding ChangeSyntaxCommand,        Mode=OneTime}" Gesture="{markup:CommandKeyGesture ChangeSyntaxCommand}"/>
        <KeyBinding Command="{Binding DiffCommand,                Mode=OneTime}" Gesture="{markup:CommandKeyGesture DiffCommand}"/>
        <KeyBinding Command="{Binding DiffUnmodifiedCommand,      Mode=OneTime}" Gesture="{markup:CommandKeyGesture DiffUnmodifiedCommand}"/>
        <KeyBinding Command="{Binding SwitchPomodoroTimerCommand, Mode=OneTime}" Gesture="{markup:CommandKeyGesture SwitchPomodoroTimerCommand}"/>

        <!-- Mac のショートカットキーを再現する -->
        <KeyBinding Command="{Binding NewCommand,                 Mode=OneTime}" Key="T" Modifiers="Ctrl"/>
        <KeyBinding Command="{Binding CloseCommand,               Mode=OneTime}" Key="W" Modifiers="Ctrl"/>
        <KeyBinding Command="Close"                                              Key="W" Modifiers="Ctrl+Shift"/>
        <KeyBinding Command="{Binding ExitApplicationCommand,     Mode=OneTime}" Key="Q" Modifiers="Ctrl"/>

        <KeyBinding Command="{x:Static views:MainWindow.ActivateTextEditorCommand}"   Gesture="{markup:CommandKeyGesture ActivateTextEditorCommand}"/>
        <KeyBinding Command="{x:Static views:MainWindow.ActivateTerminalCommand}"     Gesture="{markup:CommandKeyGesture ActivateTerminalCommand}"/>
        <KeyBinding Command="{x:Static views:MainWindow.ActivateScriptRunnerCommand}" Gesture="{markup:CommandKeyGesture ActivateScriptRunnerCommand}"/>
        <KeyBinding Command="{x:Static views:MainWindow.ActivateExplorerCommand}"     Gesture="{markup:CommandKeyGesture ActivateExplorerCommand}"/>
        <KeyBinding Command="{x:Static views:MainWindow.ActivateGrepCommand}"         Gesture="{markup:CommandKeyGesture ActivateGrepCommand}"/>
        <KeyBinding Command="{x:Static views:MainWindow.ActivatePropertyCommand}"     Gesture="{markup:CommandKeyGesture ActivatePropertyCommand}"/>
        <KeyBinding Command="{Binding SwitchFullScreenModeCommand, Mode=OneTime, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" Gesture="{markup:CommandKeyGesture SwitchFullScreenModeCommand}"/>
    </Window.InputBindings>

    <!-- ウィンドウコマンド(右) -->
    <m:MetroWindow.RightWindowCommands>
        <m:WindowCommands>
            <!-- 最前面表示ボタン -->
            <ToggleButton IsChecked="{Binding Topmost, RelativeSource={RelativeSource AncestorType={x:Type Window}}, Mode=TwoWay}" ToolTip="{le:Loc Command_Topmost}"
                          Height="{StaticResource Const.WindowButtonCommands.Height}" VerticalAlignment="Top" Focusable="False">
                <mi:PackIconBootstrapIcons Foreground="{DynamicResource MahApps.Brushes.ThemeForeground}">
                    <mi:PackIconBootstrapIcons.Resources>
                        <Style TargetType="{x:Type mi:PackIconBootstrapIcons}">
                            <Setter Property="Kind" Value="PinAngle"/>
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding Topmost, RelativeSource={RelativeSource AncestorType={x:Type Window}}, Mode=OneWay}" Value="True">
                                    <Setter Property="Kind" Value="PinFill"/>
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </mi:PackIconBootstrapIcons.Resources>
                </mi:PackIconBootstrapIcons>
            </ToggleButton>
            
            <!-- 全画面表示ボタン -->
            <Button Command="{Binding SwitchFullScreenModeCommand, Mode=OneTime, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" ToolTip="{le:Loc Command_SwitchFullScreenMode}"
                    Height="{StaticResource Const.WindowButtonCommands.Height}" VerticalAlignment="Top" Focusable="False">
                <mi:PackIconBootstrapIcons Kind="ArrowsFullscreen" Foreground="{DynamicResource MahApps.Brushes.ThemeForeground}">
                    <mi:PackIconBootstrapIcons.Resources>
                        <Style TargetType="{x:Type mi:PackIconBootstrapIcons}"/>
                    </mi:PackIconBootstrapIcons.Resources>
                </mi:PackIconBootstrapIcons>
            </Button>
        </m:WindowCommands>
    </m:MetroWindow.RightWindowCommands>

    <!-- ウィンドウコマンド(左) -->
    <m:MetroWindow.LeftWindowCommands>
        <m:WindowCommands Margin="0 1 0 0">
            <!-- メニューバー(ウィンドウ表示時) -->
            <regions:MenuBarView x:Name="TitleMenuBar"
                                 Visibility="{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed', P={Binding Settings.System.ShowMenuBar, Mode=OneWay}}"
                                 IsEnabled="{Binding IsEditMode.Value, Mode=OneWay}"/>
        </m:WindowCommands>
    </m:MetroWindow.LeftWindowCommands>

    <!-- コンテンツ -->
    <Grid ge:GridEx.RowDefinition="Auto, Auto, *, Auto">
        <!-- メニューバー(全画面表示時) -->
        <ContentControl Grid.Row="0" Style="{StaticResource RegionContent}" p:RegionManager.RegionName="MenuBarRegion"
                        Visibility="{qc:MultiBinding '!$P0 ## $P1 ? Visibility.Visible : Visibility.Collapsed',
                                     P0={Binding ShowTitleBar, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type Window}}},
                                     P1={Binding Settings.System.ShowMenuBar, Mode=OneWay}}"
                        IsEnabled="{Binding IsEditMode.Value, Mode=OneWay}"
                        ContextMenu="{StaticResource ContextMenu}"/>

        <!-- ツールバー -->
        <regions:ToolBarView Grid.Row="1"
                             Visibility="{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed', P={Binding Settings.System.ShowToolBar, Mode=OneWay}}"
                             ContextMenu="{StaticResource ContextMenu}"/>

        <!-- ステータスバー -->
        <regions:StatusBarView Grid.Row="3" 
                               Visibility="{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed', P={Binding Settings.System.ShowStatusBar, Mode=OneWay}}"
                               ContextMenu="{StaticResource ContextMenu}"/>

        <!-- ウィンドウ表示ボタン(全画面表示時) -->
        <Button Grid.Row="{qc:Binding '$P ? 0 : 1', P={Binding Settings.System.ShowMenuBar, Mode=OneWay}}"
                Command="{Binding SwitchFullScreenModeCommand, Mode=OneTime, RelativeSource={RelativeSource AncestorType={x:Type Window}}}" ToolTip="{le:Loc Command_SwitchFullScreenMode}" Focusable="False"
                Style="{DynamicResource Common.ChromelessButton}" Padding="10 5" VerticalAlignment="Top" HorizontalAlignment="Right"
                Visibility="{qc:MultiBinding '!$P0 ## ($P1 || $P2) ? Visibility.Visible : Visibility.Collapsed',
                             P0={Binding ShowTitleBar, Mode=OneWay, RelativeSource={RelativeSource AncestorType={x:Type Window}}},
                             P1={Binding Settings.System.ShowMenuBar, Mode=OneWay},
                             P2={Binding Settings.System.ShowToolBar, Mode=OneWay}}">
            <mi:PackIconBootstrapIcons Kind="ArrowsFullscreen" Foreground="{DynamicResource MahApps.Brushes.ThemeForeground}"/>
        </Button>

        <!-- コンテンツグリッド -->
        <Grid Grid.Row="2">
            <Grid.Resources>
                <s:Double x:Key="SideContentWidth">48</s:Double>
                <GridLength x:Key="SideContentColumnWidth">48</GridLength>
                <views:BindingProxy x:Key="Proxy" Data="{Binding Mode=OneWay}"/>
            </Grid.Resources>

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" x:Name="SideContentColumn"
                                  MinWidth="{qc:MultiBinding '$P0 ? $P1 : 0', P0={Binding Settings.System.ShowSideBar, Mode=OneWay}, P1={Binding Source={StaticResource SideContentWidth}}}"
                                  MaxWidth="{qc:MultiBinding '$P0 - $P1', P0={Binding ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type Window}}, Mode=OneWay}, P1={Binding Source={StaticResource SideContentWidth}}}"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*" x:Name="MainContentColumn"/>
            </Grid.ColumnDefinitions>

            <Grid.RowDefinitions>
                <RowDefinition Height="*" MinHeight="50"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto" x:Name="BottomContentRow"/>
            </Grid.RowDefinitions>

            <!-- ハンバーガーメニュー -->
            <m:HamburgerMenu Grid.Column="0" Grid.RowSpan="3" x:Name="SideContent"
                             Width="{StaticResource SideContentWidth}"
                             HamburgerWidth="{StaticResource SideContentWidth}"
                             HamburgerVisibility="Collapsed"
                             Visibility="{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed', P={Binding Settings.System.ShowSideBar, Mode=OneWay}}"
                             IsTabStop="False"
                             ContextMenu="{StaticResource ContextMenu}"
                             ItemInvoked="SideContent_ItemInvoked">
                <i:Interaction.Triggers>
                    <i:PropertyChangedTrigger Binding="{Binding Visibility, ElementName=SideContent, Mode=OneWay}">
                        <i:ChangePropertyAction TargetName="SideContentColumn" PropertyName="Width" Value="Auto"/>
                    </i:PropertyChangedTrigger>
                </i:Interaction.Triggers>
                <m:HamburgerMenu.ItemTemplate>
                    <DataTemplate DataType="{x:Type m:HamburgerMenuIconItem}">
                        <Grid Height="{StaticResource SideContentWidth}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="{StaticResource SideContentColumnWidth}"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Border ToolTip="{Binding Label, Mode=OneWay}" Background="{qc:MultiBinding '$P0 == $P1 ? new SolidColorBrush(ThemeManager.Current.DetectTheme().PrimaryAccentColor) : Brushes.Transparent', P0={Binding Mode=OneWay}, P1={Binding Content, ElementName=SideContent, Mode=OneWay}}">
                                <ContentControl Content="{Binding Icon, Mode=OneWay}" HorizontalAlignment="Center" VerticalAlignment="Center" IsTabStop="False" Focusable="False"/>
                            </Border>
                        </Grid>
                    </DataTemplate>
                </m:HamburgerMenu.ItemTemplate>
                <m:HamburgerMenu.OptionsItemTemplate>
                    <DataTemplate DataType="{x:Type m:HamburgerMenuIconItem}">
                        <Grid Height="{StaticResource SideContentWidth}">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="{StaticResource SideContentColumnWidth}"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Border ToolTip="{Binding Label, Mode=OneWay}" Background="Transparent">
                                <ContentControl Content="{Binding Icon, Mode=OneWay}" HorizontalAlignment="Center" VerticalAlignment="Center" IsTabStop="False" Focusable="False"/>
                            </Border>
                        </Grid>
                    </DataTemplate>
                </m:HamburgerMenu.OptionsItemTemplate>
                <m:HamburgerMenu.ContentTemplate>
                    <DataTemplate DataType="{x:Type m:HamburgerMenuIconItem}">
                        <Grid ge:GridEx.RowDefinition="10, Auto, 10, *" Width="{qc:MultiBinding '$P0 - $P1', P0={Binding ActualWidth, ElementName=SideContent, Mode=OneWay}, P1={Binding Source={StaticResource SideContentWidth}}}">
                            <Grid.ContextMenu>
                                <ContextMenu/>
                            </Grid.ContextMenu>
                            <TextBlock      Grid.Row="1" Margin="3 0" Text="{Binding Label, Mode=OneWay}" FontSize="{DynamicResource MahApps.Font.Size.Default}"/>
                            <ContentControl Grid.Row="3" Margin="3 0" Content="{Binding Tag, Mode=OneWay}" IsTabStop="False" Focusable="False"/>
                        </Grid>
                    </DataTemplate>
                </m:HamburgerMenu.ContentTemplate>
                <m:HamburgerMenu.ItemsSource>
                    <m:HamburgerMenuItemCollection>
                        <!-- エクスプローラー -->
                        <m:HamburgerMenuIconItem x:Name="ExplorerItem" Label="{le:Loc Command_Explorer}">
                            <m:HamburgerMenuIconItem.Icon>
                                <mi:Codicons Kind="Files"/>
                            </m:HamburgerMenuIconItem.Icon>
                            <m:HamburgerMenuIconItem.Tag>
                                <ContentControl x:Name="ExplorerRegion" Style="{StaticResource RegionContent}"/>
                            </m:HamburgerMenuIconItem.Tag>
                        </m:HamburgerMenuIconItem>

                        <!-- Grep -->
                        <m:HamburgerMenuIconItem x:Name="GrepItem" Label="{le:Loc Command_Grep}">
                            <m:HamburgerMenuIconItem.Icon>
                                <mi:VaadinIcons Kind="FolderSearch"/>
                            </m:HamburgerMenuIconItem.Icon>
                            <m:HamburgerMenuIconItem.Tag>
                                <ContentControl x:Name="GrepRegion" Style="{StaticResource RegionContent}"/>
                            </m:HamburgerMenuIconItem.Tag>
                        </m:HamburgerMenuIconItem>

                        <!-- プロパティ -->
                        <m:HamburgerMenuIconItem x:Name="PropertyItem" Label="{le:Loc Command_Property}">
                            <m:HamburgerMenuIconItem.Icon>
                                <mi:Codicons Kind="File"/>
                            </m:HamburgerMenuIconItem.Icon>
                            <m:HamburgerMenuIconItem.Tag>
                                <ContentControl x:Name="PropertyRegion" Style="{StaticResource RegionContent}" DataContext="{Binding Data.ActiveTextEditor.Value, Source={StaticResource Proxy}, Mode=OneWay}" />
                            </m:HamburgerMenuIconItem.Tag>
                        </m:HamburgerMenuIconItem>
                    </m:HamburgerMenuItemCollection>
                </m:HamburgerMenu.ItemsSource>
                <m:HamburgerMenu.OptionsItemsSource>
                    <m:HamburgerMenuItemCollection>
                        <!-- オプション -->
                        <m:HamburgerMenuIconItem Label="{le:Loc Command_Option}" Command="{Binding Data.OptionCommand, Source={StaticResource Proxy}, Mode=OneTime}">
                            <m:HamburgerMenuIconItem.Icon>
                                <mi:Codicons Kind="Gear"/>
                            </m:HamburgerMenuIconItem.Icon>
                        </m:HamburgerMenuIconItem>
                    </m:HamburgerMenuItemCollection>
                </m:HamburgerMenu.OptionsItemsSource>
            </m:HamburgerMenu>

            <GridSplitter Grid.Column="1" Grid.RowSpan="3"
                          Width="{qc:MultiBinding '$P0 == Visibility.Visible ## double.IsNaN($P1) ? 5 : 0',
                                  P0={Binding Visibility, ElementName=SideContent, Mode=OneWay},
                                  P1={Binding Width, ElementName=SideContent, Mode=OneWay}}"
                          DragCompleted="ColumnSplitter_DragCompleted"/>

            <!-- タブコントロール(メイン) -->
            <controls:DraggableTabControl Grid.Column="2" Grid.Row="0" x:Name="MainContent"
                                          ItemsSource="{Binding TextEditors, Mode=OneWay}"
                                          SelectedItem="{Binding ActiveTextEditor.Value, Mode=TwoWay}"
                                          NewItemFactory="{Binding TextEditorFactory, Mode=OneTime}"
                                          ClosingItemCallback="{Binding ClosingTextEditorHandler, Mode=OneTime}"
                                          IsHeaderPanelVisible="{qc:MultiBinding '$P0 || $P1.CompareTo(1) == 1', P0={Binding Settings.System.ShowSingleTab, Mode=OneWay}, P1={Binding Items.Count, RelativeSource={RelativeSource Self}, Mode=OneWay}}"
                                          ShowDefaultAddButton="False"
                                          ShowDefaultCloseButton="True"
                                          SelectionChanged="MainContent_SelectionChanged">
                <dr:TabablzControl.InterTabController>
                    <dr:InterTabController InterTabClient="{Binding InterTabClient, RelativeSource={RelativeSource AncestorType={x:Type Window}}, Mode=OneWay}"/>
                </dr:TabablzControl.InterTabController>
                <dr:TabablzControl.Resources>
                    <!-- WARN: AncestorType=Window も ContextMenu.PlacementTarget も使えないため Proxy から取得する -->
                    <Style TargetType="{x:Type ContextMenu}" BasedOn="{StaticResource Common.ContextMenu}">
                        <Style.Resources>
                            <Style TargetType="{x:Type MenuItem}" BasedOn="{StaticResource MahApps.Styles.MenuItem}">
                                <Setter Property="FontFamily" Value="{Binding Data.Settings.System.FontFamily, Source={StaticResource Proxy}, Mode=OneWay}"/>
                            </Style>
                        </Style.Resources>
                    </Style>
                </dr:TabablzControl.Resources>
                <dr:TabablzControl.HeaderSuffixContent>
                    <DockPanel MinWidth="30">
                        <DockPanel.ContextMenu>
                            <ContextMenu>
                                <MenuItem Command="{Binding NewCommand, Mode=OneTime}"
                                          Header="{le:Loc {markup:CommandResourceKey NewCommand}}"
                                          InputGestureText="{markup:CommandKeyGestureText NewCommand}">
                                    <MenuItem.Icon>
                                        <mi:Codicons Kind="NewFile"/>
                                    </MenuItem.Icon>
                                </MenuItem>
                                <MenuItem Command="{Binding SaveAllCommand, Mode=OneTime}"
                                          Header="{le:Loc {markup:CommandResourceKey SaveAllCommand}}"
                                          InputGestureText="{markup:CommandKeyGestureText SaveAllCommand}">
                                    <MenuItem.Icon>
                                        <mi:Codicons Kind="SaveAll"/>
                                    </MenuItem.Icon>
                                </MenuItem>
                                <MenuItem Command="{Binding CloseAllCommand, Mode=OneTime}"
                                          Header="{le:Loc {markup:CommandResourceKey CloseAllCommand}}"
                                          InputGestureText="{markup:CommandKeyGestureText CloseAllCommand}">
                                    <MenuItem.Icon>
                                        <mi:Codicons Kind="CloseAll"/>
                                    </MenuItem.Icon>
                                </MenuItem>
                            </ContextMenu>
                        </DockPanel.ContextMenu>
                        <Button Command="{x:Static dr:TabablzControl.AddItemCommand}" ToolTip="{le:Loc Command_New}" Width="{Binding ActualHeight, RelativeSource={RelativeSource Self}, Mode=OneWay}" Padding="0" BorderThickness="0" Background="Transparent" BorderBrush="Transparent" Focusable="False">
                            <mi:PackIconCodicons Kind="Add" Height="{DynamicResource MahApps.Font.Size.Button}" Width="{DynamicResource MahApps.Font.Size.Button}" Foreground="{DynamicResource MahApps.Brushes.Gray5}"/>
                        </Button>
                        <Border VerticalAlignment="Stretch" Background="Transparent"/>
                    </DockPanel>
                </dr:TabablzControl.HeaderSuffixContent>
                <dr:TabablzControl.HeaderItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="{Binding FileIcon, Mode=OneWay}" Height="{DynamicResource MahApps.Font.Size.Button.ClearText}" Margin="0 0 5 0" Visibility="{qc:MultiBinding '$P0 != null ## $P1 ? Visibility.Visible : Visibility.Collapsed', P0={Binding FileIcon, Mode=OneWay}, P1={Binding DataContext.Settings.System.ShowFileIcon, RelativeSource={RelativeSource AncestorType={x:Type Window}}, Mode=OneWay}}"/>
                            <TextBlock DataContext="{Binding Mode=OneWay}" Text="{qc:MultiBinding 'string.Concat(Path.GetFileName($P0), $P1 ? \'*\' : null)', P0={Binding FileName, Mode=OneWay}, P1={Binding IsModified, Mode=OneWay}}" VerticalAlignment="Center"/>
                            <mi:PackIconMaterial Kind="Lock" Margin="5 0 0 0" Visibility="{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed', P={Binding IsReadOnly, Mode=OneWay}}"/>
                        </StackPanel>
                    </DataTemplate>
                </dr:TabablzControl.HeaderItemTemplate>
                <dr:TabablzControl.ItemContainerStyle>
                    <Style TargetType="{x:Type dr:DragablzItem}" BasedOn="{StaticResource Common.DragablzItem}">
                        <EventSetter Event="MouseRightButtonDown" Handler="MainContentItem_MouseRightButtonDown"/>
                        <Setter Property="ToolTipService.IsEnabled" Value="{qc:Binding '!$P', P={Binding IsNewFile, Mode=OneWay}}"/>
                        <Setter Property="ToolTip" Value="{qc:MultiBinding '($P0 ? \'[R/O] \' : null) + $P1', P0={Binding IsReadOnly, Mode=OneWay}, P1={Binding FileName, Mode=OneWay}}"/>
                        <Style.Triggers>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding IsReadOnly, Mode=OneWay}" Value="True"/>
                                    <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}, Mode=OneWay}" Value="True"/>
                                </MultiDataTrigger.Conditions>
                                <Setter Property="Background" Value="{DynamicResource MahApps.Brushes.Control.Disabled}"/>
                            </MultiDataTrigger>
                            <MultiDataTrigger>
                                <MultiDataTrigger.Conditions>
                                    <Condition Binding="{Binding IsReadOnly, Mode=OneWay}" Value="True"/>
                                    <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}, Mode=OneWay}" Value="True"/>
                                </MultiDataTrigger.Conditions>
                                <Setter Property="Background" Value="{DynamicResource MahApps.Brushes.Control.Disabled}"/>
                            </MultiDataTrigger>
                        </Style.Triggers>
                    </Style>
                </dr:TabablzControl.ItemContainerStyle>
                <dr:TabablzControl.ContextMenu>
                    <ContextMenu>
                        <MenuItem Command="{Binding CloseCommand, Mode=OneTime}"
                                  Header="{le:Loc {markup:CommandResourceKey CloseCommand}}"
                                  InputGestureText="{markup:CommandKeyGestureText CloseCommand}">
                            <MenuItem.Icon>
                                <mi:JamIcons Kind="CloseRectangle"/>
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Command="{Binding CloseAllCommand, Mode=OneTime}"
                                  Header="{le:Loc {markup:CommandResourceKey CloseAllCommand}}"
                                  InputGestureText="{markup:CommandKeyGestureText CloseAllCommand}">
                            <MenuItem.Icon>
                                <mi:Codicons Kind="CloseAll"/>
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Command="{Binding CloseOtherCommand, Mode=OneTime}"
                                  Header="{le:Loc {markup:CommandResourceKey CloseOtherCommand}}"
                                  InputGestureText="{markup:CommandKeyGestureText CloseOtherCommand}">
                        </MenuItem>
                        <Separator/>
                        <MenuItem Command="{Binding SaveCommand, Mode=OneTime}"
                                  Header="{le:Loc {markup:CommandResourceKey SaveCommand}}"
                                  InputGestureText="{markup:CommandKeyGestureText SaveCommand}">
                            <MenuItem.Icon>
                                <mi:Codicons Kind="Save"/>
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Command="{Binding SaveAsCommand, Mode=OneTime}"
                                  Header="{le:Loc {markup:CommandResourceKey SaveAsCommand}}"
                                  HeaderStringFormat="{}{0}..."
                                  InputGestureText="{markup:CommandKeyGestureText SaveAsCommand}">
                            <MenuItem.Icon>
                                <mi:Codicons Kind="SaveAs"/>
                            </MenuItem.Icon>
                        </MenuItem>
                        <Separator/>
                        <MenuItem Command="{Binding DiffUnmodifiedCommand, Mode=OneTime}"
                                  Header="{le:Loc {markup:CommandResourceKey DiffUnmodifiedCommand}}"
                                  HeaderStringFormat="{}{0}..."
                                  InputGestureText="{markup:CommandKeyGestureText DiffUnmodifiedCommand}">
                            <MenuItem.Icon>
                                <mi:Material Kind="FileCompare"/>
                            </MenuItem.Icon>
                        </MenuItem>
                        <MenuItem Header="{le:Loc Command_OpenParentDirectory}"
                                  IsEnabled="{qc:Binding '!$P', P={Binding ActiveTextEditor.Value.IsNewFile, Mode=OneWay}}">
                            <i:Interaction.Triggers>
                                <i:EventTrigger EventName="Click">
                                    <behaviors:ProcessStartAction FileName="explorer.exe" Arguments="{qc:Binding '\'/select, \' + $P', P={Binding ActiveTextEditor.Value.FileName, Mode=OneWay}}"/>
                                </i:EventTrigger>
                            </i:Interaction.Triggers>
                            <MenuItem.Icon>
                                <mi:Codicons Kind="FolderOpened"/>
                            </MenuItem.Icon>
                        </MenuItem>
                    </ContextMenu>
                </dr:TabablzControl.ContextMenu>
                <dr:TabablzControl.ContentTemplate>
                    <DataTemplate>
                        <!-- テキストエディタ -->
                        <controls:TextEditor x:Name="TextEditor">
                            <controls:TextEditor.Resources>
                                <Style TargetType="{x:Type ae:SearchPanel}" BasedOn="{StaticResource Common.SearchPanel}">
                                    <Setter Property="Localization" Value="{Binding Localization, RelativeSource={RelativeSource AncestorType={x:Type Window}}, Mode=OneWay}"/>
                                </Style>
                            </controls:TextEditor.Resources>
                            <controls:TextEditor.Style>
                                <Style TargetType="{x:Type controls:TextEditor}" BasedOn="{StaticResource Common.TextEditor}">
                                    <EventSetter Event="Loaded" Handler="TextEditor_Loaded"/>
                                    <EventSetter Event="Unloaded" Handler="TextEditor_Unloaded"/>
                                    <Setter Property="Settings"         Value="{Binding DataContext.Settings.TextEditor, RelativeSource={RelativeSource AncestorType={x:Type Window}}, Mode=OneWay}"/>
                                    <Setter Property="Document"         Value="{Binding Document, Mode=OneWay}"/>
                                    <Setter Property="IsReadOnly"       Value="{Binding IsReadOnly, Mode=TwoWay}"/>
                                    <Setter Property="IsModified"       Value="{Binding IsModified, Mode=TwoWay}"/>
                                    <Setter Property="SyntaxDefinition" Value="{Binding SyntaxDefinition, Mode=TwoWay}"/>
                                    <Setter Property="OverstrikeMode"   Value="{Binding OverstrikeMode, Mode=TwoWay}"/>
                                    <Setter Property="Line"             Value="{Binding Line, Mode=TwoWay}"/>
                                    <Setter Property="Column"           Value="{Binding Column, Mode=TwoWay}"/>
                                    <Setter Property="VisualColumn"     Value="{Binding VisualColumn, Mode=TwoWay}"/>
                                    <Setter Property="pb:PushBindingManager.StylePushBindings">
                                        <Setter.Value>
                                            <pb:PushBindingCollection>
                                                <pb:PushBinding TargetProperty="VisualLength"         Path="VisualLength"/>
                                                <pb:PushBinding TargetProperty="TextLength"           Path="TextLength"/>
                                                <pb:PushBinding TargetProperty="SelectionLength"      Path="SelectionLength"/>
                                                <pb:PushBinding TargetProperty="SelectionStart"       Path="SelectionStart"/>
                                                <pb:PushBinding TargetProperty="SelectionEnd"         Path="SelectionEnd"/>
                                                <pb:PushBinding TargetProperty="SelectionStartLine"   Path="SelectionStartLine"/>
                                                <pb:PushBinding TargetProperty="SelectionEndLine"     Path="SelectionEndLine"/>
                                                <pb:PushBinding TargetProperty="SelectionLineCount"   Path="SelectionLineCount"/>
                                                <pb:PushBinding TargetProperty="SelectedText"         Path="SelectedText"/>
                                                <pb:PushBinding TargetProperty="CharName"             Path="CharName"/>
                                                <pb:PushBinding TargetProperty="IsAtEndOfLine"        Path="IsAtEndOfLine"/>
                                                <pb:PushBinding TargetProperty="IsInVirtualSpace"     Path="IsInVirtualSpace"/>
                                            </pb:PushBindingCollection>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </controls:TextEditor.Style>
                            <controls:TextEditor.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Command="Undo"
                                              Header="{le:Loc {markup:CommandResourceKey Undo}}"
                                              InputGestureText="{markup:CommandKeyGestureText Undo}">
                                        <MenuItem.Icon>
                                            <mi:Codicons Kind="Discard"/>
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <MenuItem Command="Redo"
                                              Header="{le:Loc {markup:CommandResourceKey Redo}}"
                                              InputGestureText="{markup:CommandKeyGestureText Redo}">
                                        <MenuItem.Icon>
                                            <mi:Codicons Kind="Redo"/>
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <Separator/>
                                    <MenuItem Command="Cut"
                                              Header="{le:Loc {markup:CommandResourceKey Cut}}"
                                              InputGestureText="{markup:CommandKeyGestureText Cut}">
                                        <MenuItem.Icon>
                                            <mi:Modern Kind="Scissor"/>
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <MenuItem Command="Copy"
                                              Header="{le:Loc {markup:CommandResourceKey Copy}}"
                                              InputGestureText="{markup:CommandKeyGestureText Copy}">
                                        <MenuItem.Icon>
                                            <mi:Codicons Kind="Copy"/>
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <MenuItem Command="Paste"
                                              Header="{le:Loc {markup:CommandResourceKey Paste}}"
                                              InputGestureText="{markup:CommandKeyGestureText Paste}">
                                        <MenuItem.Icon>
                                            <mi:Material Kind="ClipboardFileOutline"/>
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <MenuItem Command="EditingCommands.Delete"
                                              Header="{le:Loc {markup:CommandResourceKey Delete}}"
                                              InputGestureText="{markup:CommandKeyGestureText Delete}">
                                        <MenuItem.Icon>
                                            <mi:Material Kind="BackspaceOutline"/>
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <MenuItem Command="SelectAll"
                                              Header="{le:Loc {markup:CommandResourceKey SelectAll}}"
                                              InputGestureText="{markup:CommandKeyGestureText SelectAll}">
                                        <MenuItem.Icon>
                                            <mi:Material Kind="CursorDefaultClickOutline"/>
                                        </MenuItem.Icon>
                                    </MenuItem>
                                    <Separator/>
                                    <MenuItem Header="{le:Loc Command_Movement}">
                                        <MenuItem Command="EditingCommands.MoveLeftByWord"
                                                  Header="{le:Loc {markup:CommandResourceKey MoveLeftByWord}}"
                                                  InputGestureText="{markup:CommandKeyGestureText MoveLeftByWord}"/>
                                        <MenuItem Command="EditingCommands.MoveRightByWord"
                                                  Header="{le:Loc {markup:CommandResourceKey MoveRightByWord}}"
                                                  InputGestureText="{markup:CommandKeyGestureText MoveRightByWord}"/>
                                        <MenuItem Command="EditingCommands.MoveToLineStart"
                                                  Header="{le:Loc {markup:CommandResourceKey MoveToLineStart}}"
                                                  InputGestureText="{markup:CommandKeyGestureText MoveToLineStart}"/>
                                        <MenuItem Command="EditingCommands.MoveToLineEnd"
                                                  Header="{le:Loc {markup:CommandResourceKey MoveToLineEnd}}"
                                                  InputGestureText="{markup:CommandKeyGestureText MoveToLineEnd}"/>
                                        <MenuItem Command="EditingCommands.MoveUpByPage"
                                                  Header="{le:Loc {markup:CommandResourceKey MoveUpByPage}}"
                                                  InputGestureText="{markup:CommandKeyGestureText MoveUpByPage}"/>
                                        <MenuItem Command="EditingCommands.MoveDownByPage"
                                                  Header="{le:Loc {markup:CommandResourceKey MoveDownByPage}}"
                                                  InputGestureText="{markup:CommandKeyGestureText MoveDownByPage}"/>
                                        <MenuItem Command="EditingCommands.MoveToDocumentStart"
                                                  Header="{le:Loc {markup:CommandResourceKey MoveToDocumentStart}}"
                                                  InputGestureText="{markup:CommandKeyGestureText MoveToDocumentStart}"/>
                                        <MenuItem Command="EditingCommands.MoveToDocumentEnd"
                                                  Header="{le:Loc {markup:CommandResourceKey MoveToDocumentEnd}}"
                                                  InputGestureText="{markup:CommandKeyGestureText MoveToDocumentEnd}"/>
                                    </MenuItem>
                                    <MenuItem Header="{le:Loc Command_Select}">
                                        <MenuItem Command="EditingCommands.SelectLeftByWord"
                                                  Header="{le:Loc {markup:CommandResourceKey SelectLeftByWord}}"
                                                  InputGestureText="{markup:CommandKeyGestureText SelectLeftByWord}"/>
                                        <MenuItem Command="EditingCommands.SelectRightByWord"
                                                  Header="{le:Loc {markup:CommandResourceKey SelectRightByWord}}"
                                                  InputGestureText="{markup:CommandKeyGestureText SelectRightByWord}"/>
                                        <MenuItem Command="EditingCommands.SelectToLineStart"
                                                  Header="{le:Loc {markup:CommandResourceKey SelectToLineStart}}"
                                                  InputGestureText="{markup:CommandKeyGestureText SelectToLineStart}"/>
                                        <MenuItem Command="EditingCommands.SelectToLineEnd"
                                                  Header="{le:Loc {markup:CommandResourceKey SelectToLineEnd}}"
                                                  InputGestureText="{markup:CommandKeyGestureText SelectToLineEnd}"/>
                                        <MenuItem Command="EditingCommands.SelectUpByPage"
                                                  Header="{le:Loc {markup:CommandResourceKey SelectUpByPage}}"
                                                  InputGestureText="{markup:CommandKeyGestureText SelectUpByPage}"/>
                                        <MenuItem Command="EditingCommands.SelectDownByPage"
                                                  Header="{le:Loc {markup:CommandResourceKey SelectDownByPage}}"
                                                  InputGestureText="{markup:CommandKeyGestureText SelectDownByPage}"/>
                                        <MenuItem Command="EditingCommands.SelectToDocumentStart"
                                                  Header="{le:Loc {markup:CommandResourceKey SelectToDocumentStart}}"
                                                  InputGestureText="{markup:CommandKeyGestureText SelectToDocumentStart}"/>
                                        <MenuItem Command="EditingCommands.SelectToDocumentEnd"
                                                  Header="{le:Loc {markup:CommandResourceKey SelectToDocumentEnd}}"
                                                  InputGestureText="{markup:CommandKeyGestureText SelectToDocumentEnd}"/>
                                    </MenuItem>
                                    <MenuItem Header="{le:Loc Command_Formatting}">
                                        <MenuItem Command="controls:TextArea+Commands.ConvertToNarrow"
                                                  Header="{le:Loc {markup:CommandResourceKey ConvertToNarrow}}"
                                                  InputGestureText="{markup:CommandKeyGestureText ConvertToNarrow}"/>
                                        <MenuItem Command="controls:TextArea+Commands.ConvertToWide"
                                                  Header="{le:Loc {markup:CommandResourceKey ConvertToWide}}"
                                                  InputGestureText="{markup:CommandKeyGestureText ConvertToWide}"/>
                                        <Separator/>
                                        <MenuItem Command="ae:AvalonEditCommands.ConvertToLowercase"
                                                  Header="{le:Loc {markup:CommandResourceKey ConvertToLowercase}}"
                                                  InputGestureText="{markup:CommandKeyGestureText ConvertToLowercase}"/>
                                        <MenuItem Command="ae:AvalonEditCommands.ConvertToUppercase"
                                                  Header="{le:Loc {markup:CommandResourceKey ConvertToUppercase}}"
                                                  InputGestureText="{markup:CommandKeyGestureText ConvertToUppercase}"/>
                                        <MenuItem Command="ae:AvalonEditCommands.ConvertToTitleCase"
                                                  Header="{le:Loc {markup:CommandResourceKey ConvertToTitleCase}}"
                                                  InputGestureText="{markup:CommandKeyGestureText ConvertToTitleCase}"/>
                                        <Separator/>
                                        <MenuItem Command="ae:AvalonEditCommands.ConvertTabsToSpaces"
                                                  Header="{le:Loc {markup:CommandResourceKey ConvertTabsToSpaces}}"
                                                  InputGestureText="{markup:CommandKeyGestureText ConvertTabsToSpaces}"/>
                                        <MenuItem Command="ae:AvalonEditCommands.ConvertSpacesToTabs"
                                                  Header="{le:Loc {markup:CommandResourceKey ConvertSpacesToTabs}}"
                                                  InputGestureText="{markup:CommandKeyGestureText ConvertSpacesToTabs}"/>
                                    </MenuItem>
                                    <MenuItem Header="{le:Loc Command_Coding}">
                                        <MenuItem Command="controls:TextArea+Commands.Completion"
                                                  Header="{le:Loc {markup:CommandResourceKey Completion}}"
                                                  InputGestureText="{markup:CommandKeyGestureText Completion}">
                                            <MenuItem.Icon>
                                                <mi:Codicons Kind="Wand"/>
                                            </MenuItem.Icon>
                                        </MenuItem>
                                        <MenuItem Command="controls:TextArea+Commands.Folding"
                                                  Header="{le:Loc {markup:CommandResourceKey Folding}}"
                                                  InputGestureText="{markup:CommandKeyGestureText Folding}">
                                            <MenuItem.Icon>
                                                <mi:Codicons Kind="Fold"/>
                                            </MenuItem.Icon>
                                        </MenuItem>
                                        <MenuItem Command="controls:TextArea+Commands.Unfolding"
                                                  Header="{le:Loc {markup:CommandResourceKey Unfolding}}"
                                                  InputGestureText="{markup:CommandKeyGestureText Unfolding}">
                                            <MenuItem.Icon>
                                                <mi:Codicons Kind="Unfold"/>
                                            </MenuItem.Icon>
                                        </MenuItem>
                                    </MenuItem>
                                </ContextMenu>
                            </controls:TextEditor.ContextMenu>
                        </controls:TextEditor>
                    </DataTemplate>
                </dr:TabablzControl.ContentTemplate>
            </controls:DraggableTabControl>

            <GridSplitter Grid.Column="2" Grid.Row="1" Height="5"
                          Visibility="{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed', P={Binding IsVisibleBottomContent, RelativeSource={RelativeSource AncestorType={x:Type Window}}, Mode=OneWay}}"
                          DragCompleted="RowSplitter_DragCompleted"/>

            <!-- タブコントロール(ボトム) -->
            <TabControl Grid.Column="2" Grid.Row="2" x:Name="BottomContent"
                        TabStripPlacement="Bottom" m:HeaderedControlHelper.HeaderFontWeight="Bold" m:HeaderedControlHelper.HeaderFontSize="{DynamicResource MahApps.Font.Size.FloatingWatermark}"
                        Visibility="{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed', P={Binding IsVisibleBottomContent, RelativeSource={RelativeSource AncestorType={x:Type Window}}, Mode=OneWay}}">
                <TabItem Header="{le:Loc Command_Terminal}">
                    <!-- ターミナル -->
                    <ContentControl Style="{StaticResource RegionContent}" p:RegionManager.RegionName="TerminalRegion"/>
                </TabItem>
                <TabItem Header="{le:Loc Command_ScriptRunner}">
                    <!-- スクリプトランナー -->
                    <ContentControl Style="{StaticResource RegionContent}" p:RegionManager.RegionName="ScriptRunnerRegion"/>
                </TabItem>
            </TabControl>
        </Grid>

        <!-- プログレスサークル -->
        <Border Grid.Row="0" Grid.RowSpan="4" d:IsHidden="True" Style="{StaticResource Common.Overlay}" Visibility="{qc:Binding '$P ? Visibility.Visible : Visibility.Collapsed', P={Binding IsPending.Value, Mode=OneWay}}">
            <StackPanel Margin="5 0" HorizontalAlignment="Stretch" VerticalAlignment="Center">
                <TextBlock Text="{le:Loc Text_Working}" HorizontalAlignment="Center" TextAlignment="Center"/>
                <Border Height="10"/>
                <m:ProgressRing/>
            </StackPanel>
        </Border>
    </Grid>

    <!-- フライアウト -->
    <m:MetroWindow.Flyouts>
        <m:FlyoutsControl>
            <m:Flyout Header="{le:Loc Command_Print}" IsOpen="{Binding IsOpenPrintPreviewContent.Value, Mode=TwoWay}">
                <ContentControl Style="{StaticResource RegionContent}" p:RegionManager.RegionName="PrintPreviewContentRegion"/>
            </m:Flyout>
            <m:Flyout Header="{le:Loc Command_Option}" IsOpen="{Binding IsOpenOptionContent.Value, Mode=TwoWay}">
                <ContentControl Style="{StaticResource RegionContent}" p:RegionManager.RegionName="OptionContentRegion"/>
            </m:Flyout>
            <m:Flyout Header="{le:Loc Command_Maintenance}" IsOpen="{Binding IsOpenMaintenanceContent.Value, Mode=TwoWay}">
                <ContentControl Style="{StaticResource RegionContent}" p:RegionManager.RegionName="MaintenanceContentRegion"/>
            </m:Flyout>
            <m:Flyout Header="{le:Loc Command_About}" IsOpen="{Binding IsOpenAboutContent.Value, Mode=TwoWay}">
                <ContentControl Style="{StaticResource RegionContent}" p:RegionManager.RegionName="AboutContentRegion"/>
            </m:Flyout>
            <m:Flyout Header="{le:Loc Command_ShortcutKeys}" IsOpen="{Binding IsOpenShortcutKeysContent.Value, Mode=TwoWay}">
                <ContentControl Style="{StaticResource RegionContent}" p:RegionManager.RegionName="ShortcutKeysContentRegion"/>
            </m:Flyout>
            <m:Flyout Header="{le:Loc Command_Diff}" IsOpen="{Binding IsOpenDiffContent.Value, Mode=TwoWay}">
                <ContentControl Style="{StaticResource RegionContent}" p:RegionManager.RegionName="DiffContentRegion"/>
            </m:Flyout>
        </m:FlyoutsControl>
    </m:MetroWindow.Flyouts>

</m:MetroWindow>
