<Window x:Class="RoslynPad.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:roslynPad="clr-namespace:RoslynPad"
        xmlns:roslyn="clr-namespace:Microsoft.CodeAnalysis;assembly=Microsoft.CodeAnalysis"
        xmlns:dock="https://github.com/Dirkster99/AvalonDock"
        xmlns:av="http://schemas.codeplex.com/wpfcontrib/xaml/presentation"
        xmlns:ui="clr-namespace:RoslynPad.UI;assembly=RoslynPad.Common.UI"
        mc:Ignorable="d"
        d:DataContext="{d:DesignInstance ui:MainViewModelBase}"
        TextOptions.TextFormattingMode="Display"
        UseLayoutRounding="True"
        Title="{Binding WindowTitle, Mode=OneTime}"
        Height="600"
        Width="800"
        Name="This">

    <FrameworkElement.InputBindings>
        <KeyBinding Gesture="Ctrl+N"
                    Command="{Binding NewDocumentCommand, Mode=OneTime}"
                    CommandParameter="{x:Static roslyn:SourceCodeKind.Regular}" />
        <KeyBinding Gesture="Ctrl+Shift+N"
                    Command="{Binding NewDocumentCommand, Mode=OneTime}"
                    CommandParameter="{x:Static roslyn:SourceCodeKind.Script}" />
        <KeyBinding Gesture="Ctrl+O"
                    Command="{Binding OpenFileCommand, Mode=OneTime}" />
        <KeyBinding Gesture="Ctrl+W"
                    Command="{Binding CloseCurrentDocumentCommand, Mode=OneTime}" />
        <KeyBinding Gesture="Ctrl+Shift+O"
                    Command="{Binding ToggleOptimizationCommand, Mode=OneTime}" />
    </FrameworkElement.InputBindings>
    <FrameworkElement.Resources>

        <DataTemplate DataType="{x:Type ui:OpenDocumentViewModel}">
            <roslynPad:DocumentView />
        </DataTemplate>

    </FrameworkElement.Resources>
    <av:InlineModalDecorator Target="{Binding ElementName=This, Mode=OneTime}">
        <DockPanel>
            <Border Padding="3"
                    Margin="1"
                    Background="#eebbbb"
                    DockPanel.Dock="Bottom"
                    Visibility="{Binding HasError, Converter={StaticResource BooleanToVisibilityConverter}}">
                <DockPanel LastChildFill="False">
                    <Button Margin="3"
                            Content="View details"
                            DockPanel.Dock="Right"
                            Background="Transparent"
                            Click="ViewErrorDetails_OnClick" />
                    <Button Background="Transparent"
                            Content=""
                            FontFamily="Segoe UI Symbol"
                            Command="{Binding ClearErrorCommand, Mode=OneTime}"
                            Margin="3" />
                    <TextBlock VerticalAlignment="Center"
                               TextTrimming="CharacterEllipsis"
                               Text="{Binding LastError.Message}" />
                </DockPanel>
            </Border>
            <Grid IsEnabled="{Binding IsInitialized}">
                <dock:DockingManager Name="DockingManager"
                                     DocumentsSource="{Binding OpenDocuments, Mode=OneTime}"
                                     ActiveContent="{Binding CurrentOpenDocument, Mode=TwoWay}"
                                     DocumentClosing="DockingManager_OnDocumentClosing"
                                     AnchorableContextMenu="{x:Null}">
                    <dock:DockingManager.DocumentHeaderTemplate>
                        <DataTemplate>
                            <TextBlock>
                                <Run Text="{Binding Content.Title, Mode=OneWay}" />
                                <Run Name="DirtyIndicator"
                                     Text="" />
                            </TextBlock>
                            <DataTemplate.Triggers>
                                <DataTrigger Binding="{Binding Content.IsDirty}"
                                             Value="True">
                                    <Setter TargetName="DirtyIndicator"
                                            Property="Text"
                                            Value="*" />
                                </DataTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>
                    </dock:DockingManager.DocumentHeaderTemplate>
                    <dock:DockingManager.DocumentPaneMenuItemHeaderTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Content.Title}" />
                        </DataTemplate>
                    </dock:DockingManager.DocumentPaneMenuItemHeaderTemplate>
                    <dock:DockingManager.LayoutItemContainerStyle>
                        <Style TargetType="{x:Type dock:LayoutItem}">
                            <Setter Property="Title" Value="{Binding Model.Title}"/>
                        </Style>
                    </dock:DockingManager.LayoutItemContainerStyle>
                    <dock:LayoutRoot>
                        <dock:LayoutPanel Orientation="Horizontal">
                            <dock:LayoutAnchorablePane Name="Documents"
                                                       DockWidth="200">
                                <dock:LayoutAnchorable x:Name="DocumentsPane"
                                                       CanHide="False"
                                                       CanClose="False"
                                                       CanFloat="False"
                                                       CanAutoHide="True"
                                                       AutoHideWidth="200"
                                                       Title="Documents">
                                    <DockPanel x:Name="DocumentTree">
                                        <AdornerDecorator>
                                            <roslynPad:DocumentTreeView />
                                        </AdornerDecorator>
                                    </DockPanel>
                                </dock:LayoutAnchorable>
                            </dock:LayoutAnchorablePane>
                            <dock:LayoutDocumentPane />
                        </dock:LayoutPanel>
                    </dock:LayoutRoot>
                </dock:DockingManager>

                <UniformGrid HorizontalAlignment="Center"
                             VerticalAlignment="Center"
                             Rows="1"
                             Visibility="{Binding HasNoOpenDocuments, Converter={StaticResource BooleanToVisibilityConverter}}">

                    <Button Padding="5"
                            Margin="20 0 0 0"
                            Background="Transparent"
                            Command="{Binding NewDocumentCommand}"
                            CommandParameter="{x:Static roslyn:SourceCodeKind.Regular}">
                        <StackPanel>
                            <Image Source="{StaticResource CsFile}"
                                   Width="64"
                                   Height="64" />
                            <TextBlock Text="New&#xA;(Ctrl+N)"
                                       TextAlignment="Center"
                                       HorizontalAlignment="Center" />
                        </StackPanel>
                    </Button>

                    <Button Padding="5"
                            Margin="20 0 0 0"
                            Background="Transparent"
                            Command="{Binding NewDocumentCommand}"
                            CommandParameter="{x:Static roslyn:SourceCodeKind.Script}">
                        <StackPanel>
                            <Image Source="{StaticResource CsFile}"
                                   Width="64"
                                   Height="64" />
                            <TextBlock Text="New Script&#xA;(Ctrl+Shift+N)"
                                       TextAlignment="Center"
                                       HorizontalAlignment="Center" />
                        </StackPanel>
                    </Button>

                </UniformGrid>

                <StackPanel Orientation="Horizontal"
                            HorizontalAlignment="Right"
                            VerticalAlignment="Bottom"
                            Margin="5">

                    <ToggleButton Margin="20 0 0 0"
                                  BorderThickness="0"
                                  Background="Transparent"
                                  IsChecked="{Binding Settings.OptimizeCompilation}"
                                  ToolTipService.Placement="Top">
                        <ToggleButton.Style>
                            <Style TargetType="ToggleButton">
                                <Setter Property="ToolTip"
                                        Value="Optimization: Off (Ctrl+Shift+O)" />
                                <Style.Triggers>
                                    <Trigger Property="IsChecked"
                                             Value="True">
                                        <Setter Property="ToolTip"
                                                Value="Optimization: On (Ctrl+Shift+O)" />
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </ToggleButton.Style>
                        <Image Source="{StaticResource Time}"
                               Width="16"
                               Height="16" />
                    </ToggleButton>

                    <Button Margin="20 0 0 0"
                            BorderThickness="0"
                            Background="Gold"
                            Cursor="Hand"
                            ToolTip="Update Available"
                            ToolTipService.Placement="Top"
                            Visibility="{Binding HasUpdate, Converter={StaticResource BooleanToVisibilityConverter}}"
                            Click="ViewUpdateClick">
                        <Button.Content>
                            <StackPanel Orientation="Horizontal">
                                <Image Source="{StaticResource Update}"
                                       Width="16"
                                       Height="16" />
                                <TextBlock Margin="5 0 0 0">
                                    Update Available
                                </TextBlock>
                            </StackPanel>
                        </Button.Content>
                    </Button>

                    <Image Margin="20 0 0 0"
                           Source="{StaticResource FontSize}"
                           Height="16"
                           Width="16" />
                    <Slider Width="100"
                            ToolTip="Font Size"
                            ToolTipService.Placement="Top"
                            Margin="5 0 0 0"
                            Minimum="{Binding MinimumEditorFontSize, Mode=OneTime}"
                            Maximum="{Binding MaximumEditorFontSize, Mode=OneTime}"
                            SmallChange="1"
                            LargeChange="10"
                            IsSnapToTickEnabled="True"
                            TickFrequency="1"
                            Value="{Binding EditorFontSize}" />
                    <TextBlock Text="{Binding EditorFontSize}"
                               Margin="5 0 0 0" />

                    <Menu Margin="20 0 0 0"
                          Background="Transparent">
                        <MenuItem Padding="0"
                                  BorderThickness="0"
                                  ToolTip="Send Feedback"
                                  ToolTipService.Placement="Top">
                            <MenuItem.Header>
                                <Image Source="{StaticResource Feedback}"
                                       Width="16"
                                       Height="16" />
                            </MenuItem.Header>
                            <MenuItem IsCheckable="True"
                                      IsChecked="{Binding SendTelemetry}"
                                      Header="Send Telemetry"
                                      ToolTip="Send errors to the author (stack traces of internal RoslynPad errors - not your code)" />
                            <MenuItem Header="Report a problem..."
                                      Command="{Binding ReportProblemCommand}" />
                        </MenuItem>
                    </Menu>
                </StackPanel>
            </Grid>
        </DockPanel>
    </av:InlineModalDecorator>
</Window>
