<fluent:RibbonWindow x:Class="Filtration.Views.MainWindow"
        x:ClassModifier="internal"
        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:fluent="clr-namespace:Fluent;assembly=Fluent"
        xmlns:viewModels="clr-namespace:Filtration.ViewModels"
        xmlns:viewsAvalonDock="clr-namespace:Filtration.Views.AvalonDock"
        xmlns:views="clr-namespace:Filtration.Views"
        xmlns:gif="http://wpfanimatedgif.codeplex.com"
        xmlns:utility="clr-namespace:Filtration.Utility"
        mc:Ignorable="d"
        d:DataContext="{d:DesignInstance Type=viewModels:MainWindowViewModel}"
        Title="{Binding WindowTitle}" Height="762" Width="1126" IsIconVisible="True"
        Closing="MainWindow_OnClosing" Drop="MainWindow_OnDrop" AllowDrop="True">

    <fluent:RibbonWindow.InputBindings>
        <KeyBinding Command="{Binding SaveCommand}" Modifiers="Control" Key="S" />
        <KeyBinding Command="{Binding OpenScriptCommand}" Modifiers="Control" Key="O" />
        <KeyBinding Command="{Binding NewScriptCommand}" Modifiers="Control" Key="N" />
        <KeyBinding Command="{Binding UndoCommand}" Modifiers="Control" Key="Z" />
        <KeyBinding Command="{Binding RedoCommand}" Modifiers="Control" Key="Y" />
    </fluent:RibbonWindow.InputBindings>
    <utility:RoutedCommandHandlers.Commands>
        <utility:RoutedCommandHandler RoutedCommand="{StaticResource OpenScriptRoutedCommand}" Command="{Binding OpenScriptCommand}" />
    </utility:RoutedCommandHandlers.Commands>
    <DockPanel x:Name="RootDockPanel">
        <fluent:Ribbon DockPanel.Dock="Top" x:Name="RibbonRoot" IsEnabled="{Binding ShowLoadingBanner, Converter={StaticResource BoolInverterConverter}}">
            <fluent:Ribbon.Menu>
                <fluent:Backstage>
                    <fluent:BackstageTabControl>
                        <fluent:BackstageTabItem Header="Filtration" Content="{StaticResource SettingsIcon}">
                            <fluent:BackstageTabItem.ContentTemplate>
                                <DataTemplate>
                                    <StackPanel>
                                        <TextBlock Margin="20">Recent Documents will go here in a future release.</TextBlock>
                                    </StackPanel>
                                </DataTemplate>
                            </fluent:BackstageTabItem.ContentTemplate>
                        </fluent:BackstageTabItem>
                        <fluent:Button Header="New Script" Command="{Binding NewScriptCommand}" Icon="{StaticResource NewIcon}" ToolTip="New Script (Ctrl+N)" />
                        <fluent:Button Header="Open Script" Command="{Binding OpenScriptCommand}" Icon="{StaticResource OpenIcon}" ToolTip="Open Script (Ctrl+O)" />
                        <fluent:Button Header="Open Theme" Command="{Binding OpenThemeCommand}" Icon="{StaticResource OpenIcon}" />
                        <fluent:Button Header="Save" Command="{Binding SaveCommand}" Icon="{StaticResource SaveIcon}" ToolTip="Save (Ctrl+S)" />
                        <fluent:Button Header="Save As" Command="{Binding SaveAsCommand}" Icon="{StaticResource SaveIcon}" />
                        <fluent:Button Header="Close" Command="{Binding CloseCommand}" />
                        <fluent:SeparatorTabItem />
                        <fluent:BackstageTabItem Header="Settings" Content="{StaticResource SettingsIcon}">
                            <fluent:BackstageTabItem.ContentTemplate>
                                <DataTemplate>
                                    <views:SettingsPageView DataContext="{Binding ElementName=RootDockPanel, Path=DataContext.SettingsPageViewModel}" />
                                </DataTemplate>
                            </fluent:BackstageTabItem.ContentTemplate>
                        </fluent:BackstageTabItem>
                        <fluent:SeparatorTabItem />
                        <fluent:Button Header="About Filtration" Icon="{StaticResource AboutIcon}" Command="{Binding OpenAboutWindowCommand}" VerticalAlignment="Bottom" />
                    </fluent:BackstageTabControl>
                </fluent:Backstage>
            </fluent:Ribbon.Menu>
            <fluent:Ribbon.ContextualGroups>
                <fluent:RibbonContextualTabGroup Header="Script"
                                                 Background="ForestGreen"
                                                 BorderBrush="ForestGreen"
                                                 x:Name="ScriptToolsGroup"
                                                 IsVisibleChanged="ScriptToolsGroup_OnIsVisibleChanged"  
                                                 Visibility="{Binding ActiveDocumentIsScript, Converter={StaticResource BooleanVisibilityConverter}, Mode=OneWay}" />
                <fluent:RibbonContextualTabGroup Header="Theme"
                                                 Background="DodgerBlue"
                                                 BorderBrush="DodgerBlue"
                                                 x:Name="ThemeToolsGroup" 
                                                 IsVisibleChanged="ThemeToolsGroup_OnIsVisibleChanged"
                                                 Visibility="{Binding ActiveDocumentIsTheme, Converter={StaticResource BooleanVisibilityConverter}, Mode=OneWay}" />
            </fluent:Ribbon.ContextualGroups>
            <fluent:RibbonTabItem Header="View">
                <fluent:RibbonGroupBox Header="Tools">
                    <fluent:ToggleButton Header="Section Browser" Width="150" Size="Middle" Icon="{StaticResource AddSectionIcon}" IsChecked="{Binding AvalonDockWorkspaceViewModel.CommentBlockBrowserViewModel.IsVisible}"/>
                    <fluent:ToggleButton Header="Block Group Browser" SizeDefinition="Middle" Icon="{StaticResource BlockGroupBrowserIcon}" IsChecked="{Binding AvalonDockWorkspaceViewModel.BlockGroupBrowserViewModel.IsVisible}" />
                    <fluent:ToggleButton Header="Block Output Preview" SizeDefinition="Middle" Icon="{StaticResource BlockOutputPreviewIcon}" IsChecked="{Binding AvalonDockWorkspaceViewModel.BlockOutputPreviewViewModel.IsVisible}" />
                </fluent:RibbonGroupBox>
            </fluent:RibbonTabItem>
            <fluent:RibbonTabItem x:Name="ScriptToolsTabItem" Header="Script Tools" Group="{Binding ElementName=ScriptToolsGroup}" Visibility="{Binding ActiveDocumentIsScript, Converter={StaticResource BooleanVisibilityConverter}, Mode=OneWay}" >
                <fluent:RibbonGroupBox Header="Clipboard">
                    <fluent:Button Header="Copy Block" Command="{Binding CopyBlockCommand}" Icon="{StaticResource CopyIcon}" LargeIcon="{StaticResource CopyIcon}" ToolTip="Copy Block (Ctrl+C)"/>
                    <fluent:Button Header="Paste Block" Command="{Binding PasteCommand}" Icon="{StaticResource PasteIcon}" LargeIcon="{StaticResource PasteIcon}" ToolTip="Paste Block (Ctrl+V)"/>
                    <fluent:Button Header="Copy Style" Command="{Binding CopyBlockStyleCommand}" Icon="{StaticResource CopyIcon}" LargeIcon="{StaticResource CopyIcon}" SizeDefinition="Middle" ToolTip="Copy Style (Ctrl+Shift+C)" />
                    <fluent:Button Header="Paste Style" Command="{Binding PasteBlockStyleCommand}" Icon="{StaticResource PasteStyleIcon}" LargeIcon="{StaticResource PasteIcon}" SizeDefinition="Middle" ToolTip="Paste Style (Ctrl+Shift+V)" />
                    <fluent:Button Header="Copy Script" Command="{Binding CopyScriptCommand}" Icon="{StaticResource CopyIcon}" LargeIcon="{StaticResource PasteIcon}" SizeDefinition="Middle" />
                </fluent:RibbonGroupBox>
                <fluent:RibbonGroupBox Header="Undo">
                    <fluent:Button Header="Undo" Command="{Binding UndoCommand}"  ToolTip="Undo" SizeDefinition="Middle" Icon="{StaticResource UndoIcon}" />
                    <fluent:Button Header="Redo" Command="{Binding RedoCommand}" ToolTip="Redo" SizeDefinition="Middle" Icon="{StaticResource RedoIcon}" />
                </fluent:RibbonGroupBox>
                <fluent:RibbonGroupBox Header="Blocks">
                    <fluent:Button Header="Add Block" Command="{Binding AddBlockCommand}" SizeDefinition="Middle" Icon="{StaticResource AddBlockIcon}" />
                    <fluent:Button Header="Add Section" Command="{Binding AddSectionCommand}" SizeDefinition="Middle" Icon="{StaticResource AddSectionIcon}" />
                    <fluent:Button Header="Delete Block" Command="{Binding DeleteBlockCommand}"  SizeDefinition="Middle" Icon="{StaticResource DeleteIcon}" />
                    <fluent:Button Header="Move To Top" Command="{Binding MoveBlockToTopCommand}" SizeDefinition="Middle" Icon="{StaticResource MoveToTopIcon}" />
                    <fluent:Button Header="Move Up" Command="{Binding MoveBlockUpCommand}"  SizeDefinition="Middle" Icon="{StaticResource MoveUpIcon}" />
                    <fluent:Button Header="Move Down" Command="{Binding MoveBlockDownCommand}" SizeDefinition="Middle" Icon="{StaticResource MoveDownIcon}" />
                    <fluent:Button Header="Move To Bottom" Command="{Binding MoveBlockToBottomCommand}"  SizeDefinition="Middle" Icon="{StaticResource MoveToBottomIcon}" />
                    <fluent:Button Header="Enable Block" Command="{Binding EnableBlockCommand}"  SizeDefinition="Middle" Icon="{StaticResource StandbyEnabledIcon}" />
                    <fluent:Button Header="Disable Block" Command="{Binding DisableBlockCommand}"  SizeDefinition="Middle" Icon="{StaticResource StandbyDisabledIcon}" />
                </fluent:RibbonGroupBox>
                <fluent:RibbonGroupBox Header="Sections">
                    <fluent:Button Header="Enable Section" Command="{Binding EnableSectionCommand}"  SizeDefinition="Middle" Icon="{StaticResource StandbyEnabledIcon}" />
                    <fluent:Button Header="Disable Section" Command="{Binding DisableSectionCommand}"  SizeDefinition="Middle" Icon="{StaticResource StandbyDisabledIcon}" />
                    <fluent:Button Header=""  SizeDefinition="Middle" IsEnabled="False" />
                    <fluent:Button Header="Expand All Sections" Command="{Binding ExpandAllSectionsCommand}" SizeDefinition="Middle" Icon="{StaticResource ExpandIcon}" />
                    <fluent:Button Header="Collapse All Sections" Command="{Binding CollapseAllSectionsCommand}" SizeDefinition="Middle" Icon="{StaticResource CollapseIcon}" />
                </fluent:RibbonGroupBox>
                <fluent:RibbonGroupBox Header="Expand / Collapse">
                    <fluent:Button Header="Expand All" Command="{Binding ExpandAllBlocksCommand}" SizeDefinition="Middle" Icon="{StaticResource ExpandIcon}" />
                    <fluent:Button Header="Collapse All" Command="{Binding CollapseAllBlocksCommand}" SizeDefinition="Middle" Icon="{StaticResource CollapseIcon}" />
                </fluent:RibbonGroupBox>
                <fluent:RibbonGroupBox Header="Filters">
                    <fluent:ToggleButton Command="{Binding ToggleShowAdvancedCommand}" CommandParameter="{Binding Path=IsChecked, RelativeSource={RelativeSource Self}}" Header="Show Advanced Blocks" SizeDefinition="Middle" Icon="{StaticResource ShowAdvancedIcon}" IsChecked="{Binding ShowAdvancedStatus, Mode=OneWay}" />
                    <fluent:Button Header="Clear All Filters" Command="{Binding ClearFiltersCommand}" SizeDefinition="Middle" Icon="{StaticResource ClearFilterIcon}" />
                </fluent:RibbonGroupBox>
                <fluent:RibbonGroupBox Header="Themes">
                    <fluent:Button Header="Edit Master Theme" Command="{Binding EditMasterThemeCommand}" Icon="{StaticResource ThemeIcon}" LargeIcon="{StaticResource ThemeIcon}" />
                    <fluent:Button Header="Apply Theme" Command="{Binding ApplyThemeToScriptCommand}" Icon="{StaticResource ThemeIcon}" LargeIcon="{StaticResource ThemeIcon}" />
                    <fluent:Button Header="Create Theme" Command="{Binding CreateThemeCommand}" Icon="{StaticResource ThemeIcon}" LargeIcon="{StaticResource ThemeIcon}" />
                    <fluent:Button Header="Replace Colours" Command="{Binding ReplaceColorsCommand}" Icon="{StaticResource ReplaceColorsIcon}" LargeIcon="{StaticResource ReplaceColorsIcon}" />
                </fluent:RibbonGroupBox>
            </fluent:RibbonTabItem>
            <fluent:RibbonTabItem x:Name="ThemeToolsTabItem" Header="Theme Tools" Group="{Binding ElementName=ThemeToolsGroup}" Visibility="{Binding ActiveDocumentIsTheme, Converter={StaticResource BooleanVisibilityConverter}, Mode=OneWay}">
                <fluent:RibbonGroupBox Header="Add Components">
                    <fluent:Button SizeDefinition="Middle" Header="Add Text Color" Icon="{StaticResource AddIcon}" Command="{Binding AddTextColorThemeComponentCommand}" />
                    <fluent:Button SizeDefinition="Middle" Header="Add Background Color" Icon="{StaticResource AddIcon}" Command="{Binding AddBackgroundColorThemeComponentCommand}" />
                    <fluent:Button SizeDefinition="Middle" Header="Add Border Color" Icon="{StaticResource AddIcon}" Command="{Binding AddBorderColorThemeComponentCommand}" />
                </fluent:RibbonGroupBox>
                <fluent:RibbonGroupBox Header="Delete">
                    <fluent:Button Header="Delete Theme Component" Icon="{StaticResource ThemeComponentDeleteIcon}" LargeIcon="{StaticResource ThemeComponentDeleteIcon}" Command="{Binding DeleteThemeComponentCommand}" />
                </fluent:RibbonGroupBox>
            </fluent:RibbonTabItem>
        </fluent:Ribbon>
        <Grid>
            <viewsAvalonDock:AvalonDockWorkspaceView DataContext="{Binding AvalonDockWorkspaceViewModel}" />
            <Grid ZIndex="9999" Visibility="{Binding ShowLoadingBanner, Converter={StaticResource BooleanToVisibilityConverter}, ConverterParameter={x:Static Visibility.Hidden}}">

                <Grid.Background>
                    <SolidColorBrush Color="Black" Opacity="0.5" />
                </Grid.Background>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition  Width="*" />
                        <ColumnDefinition  Width="Auto" />
                        <ColumnDefinition  Width="*" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>
                    <Border Grid.Row="1" Grid.Column="1" BorderBrush="Black" BorderThickness="1" Background="White" Padding="20">
                        <StackPanel Orientation="Horizontal">
                            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" FontWeight="DemiBold">Working...</TextBlock>
                            <Image gif:ImageBehavior.AnimatedSource="/Filtration;component/Resources/loading_spinner.gif" Height="32"  Margin="10,0,0,0"/>
                        </StackPanel>
                    </Border>
                </Grid>
            </Grid>
        </Grid>
    </DockPanel>
</fluent:RibbonWindow>
 
 