<wpf:ThemableWindow x:Class="InABox.DynamicGrid.ScriptEditorWindow"
        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:wpf="clr-namespace:InABox.Wpf"
        xmlns:local="clr-namespace:InABox.DynamicGrid"
        xmlns:editor="clr-namespace:RoslynPad.Editor;assembly=RoslynPad.Editor.Windows"
        mc:Ignorable="d"
        Title="ScriptEditor" Height="800" Width="1200" WindowStartupLocation="CenterScreen" Closing="Window_Closing"
        Loaded="OnLoaded">

    <Window.CommandBindings>
        <CommandBinding x:Name="SaveCommandBinding" Command="{x:Static local:ScriptEditorWindow.SaveCommand}"
                        Executed="SaveCommandBinding_Executed"
                        CanExecute="SaveCommandBinding_CanExecute" />
    </Window.CommandBindings>

    <Grid Margin="0" x:Name="Grid" Background="Silver">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="5" />
            <RowDefinition Height="100" />
            <!--<RowDefinition Height="40" />-->
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="80" />
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="80" />
            <ColumnDefinition Width="80" />
        </Grid.ColumnDefinitions>

        <ToolBar Grid.Row="0" Grid.ColumnSpan="4" Margin="-1,0,0,0">

            <Button x:Name="SaveButton" ToolTip="Save &amp; Close" Click="SaveButton_Click" IsEnabled="false">
                <Image Source="pack://application:,,,/Resources/disk.png" Height="32" Width="32" />
            </Button>

            <Separator />

            <Button x:Name="CopyButton" ToolTip="Copy" Click="CopyButton_Click" IsEnabled="true">
                <Image Source="pack://application:,,,/Resources/copy.png" Height="32" Width="32" />
            </Button>

            <Button x:Name="CutButton" ToolTip="Cut" Click="CutButton_Click" IsEnabled="true">
                <Image Source="pack://application:,,,/Resources/cut.png" Height="32" Width="32" />
            </Button>
            <Button x:Name="PasteButton" ToolTip="Paste" Click="PasteButton_Click" IsEnabled="true">
                <Image Source="pack://application:,,,/Resources/paste.png" Height="32" Width="32" />
            </Button>

            <Separator />
            <Button x:Name="UndoButton" ToolTip="Undo" Click="UndoButton_Click" IsEnabled="true">
                <Image Source="pack://application:,,,/Resources/undo.png" Height="32" Width="32" />
            </Button>
            <Button x:Name="RedoButton" ToolTip="Redo" Click="RedoButton_Click" IsEnabled="true">
                <Image Source="pack://application:,,,/Resources/redo.png" Height="32" Width="32" />
            </Button>

            <Separator />
            <Button x:Name="PrintButton" ToolTip="Print" Click="PrintButton_Click" IsEnabled="false">
                <Image Source="pack://application:,,,/Resources/print.png" Height="32" Width="32" />
            </Button>

            <Separator />
            <Button x:Name="CompileButton" ToolTip="Execute" Click="CompileButton_Click" IsEnabled="true">
                <Image Source="pack://application:,,,/Resources/tick.png" Height="32" Width="32" />
            </Button>
            <Button x:Name="RunButton" ToolTip="Execute" Click="RunButton_Click" IsEnabled="true">
                <Image Source="pack://application:,,,/Resources/run.png" Height="32" Width="32" />
            </Button>


        </ToolBar>
        <Grid Grid.Row="1" Grid.ColumnSpan="4" Margin="2,2,2,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <editor:RoslynCodeEditor
                x:Name="Editor"
                Loaded="Roslyn_Loaded"
                PreviewKeyDown="Roslyn_PreviewKeyDown"
                TextChanged="Roslyn_TextChanged"
                IsReadOnly="false"
                HorizontalScrollBarVisibility="Auto"
                VerticalScrollBarVisibility="Auto"
                ShowLineNumbers="true"
                FontFamily="Courier New"
                FontSize="12"
                Grid.Column="0"/>

            <GridSplitter Grid.Column="1" ResizeDirection="Columns" />

            <DockPanel x:Name="SnippetPanel" Grid.Column="2" Width="150" Visibility="Collapsed">

                <ComboBox x:Name="SnippetSection" DockPanel.Dock="Top" Margin="0,0,0,2"
                          SelectionChanged="SnippetSection_SelectionChanged" />

                <ListView x:Name="SnippetList" HorizontalAlignment="Stretch"
                          MouseDoubleClick="Snippets_MouseDoubleClick" Background="WhiteSmoke" BorderBrush="Gray"
                          BorderThickness="0.75">
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Border BorderBrush="Gray" BorderThickness="0.75" Background="LightYellow" Margin="0"
                                    HorizontalAlignment="Stretch">
                                <TextBlock Height="Auto" TextWrapping="Wrap" Margin="4,0,4,0" TextAlignment="Left"
                                           Text="{Binding}" VerticalAlignment="Center" HorizontalAlignment="Stretch" />
                            </Border>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

            </DockPanel>


        </Grid>

        <GridSplitter Grid.Row="2" Grid.ColumnSpan="4" ResizeDirection="Rows" Height="2" />
        <ListBox x:Name="Errors" Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="4" Margin="0,0,0,0"
                 SelectionChanged="Errors_SelectionChanged" PreviewMouseDown="Errors_PreviewMouseDown" />
        <GridSplitter HorizontalAlignment="Left" Height="100" Margin="-115,494,0,0" Grid.Row="1" Grid.RowSpan="2"
                      VerticalAlignment="Top" Width="5" />

    </Grid>
</wpf:ThemableWindow>