<TabItem x:Class="Dependencies.DependencyWindow"
        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:local="clr-namespace:Dependencies"
        xmlns:properties="clr-namespace:Dependencies.Properties"
        mc:Ignorable="d" d:DesignHeight="600" d:DesignWidth="600">

    <TabItem.Resources>
        <local:ImageToHeaderConverter x:Key="img"/>
        <local:OverlayImageToHeaderConverter x:Key="img_overlay"/>
        
        <!-- Hide/Show the status bar based on a global switch -->
        <local:BooleanToVisibilityConverter x:Key="BooleanToVisibility"/>

        <Style x:Key="LeftAlignHeaderText" TargetType="{x:Type GridViewColumnHeader}">
            <Setter Property="HorizontalContentAlignment" Value="Left"></Setter>
            <Setter Property="Padding" Value="5,0,0,0"></Setter>
        </Style>

    </TabItem.Resources>


    <Grid x:Name="ResizeElemGrid" Margin="0,0,0,0">
        <Grid.RowDefinitions>
            <RowDefinition Height="146*"/>
            <RowDefinition Height="5"/>
            <RowDefinition Height="46*"/>
        </Grid.RowDefinitions>

        <Grid x:Name="TreeImportExportGrid" 
              Margin="0,0,0,0"
              Grid.Row="0">

            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="300*"/>
                <ColumnDefinition Width="5"/>
                <ColumnDefinition Width="600*"/>
            </Grid.ColumnDefinitions>

            <TreeView x:Name="DllTreeView"  
                    HorizontalContentAlignment="Stretch" 
                    VerticalContentAlignment="Stretch" 
                    Padding="0" 
                    SelectedItemChanged="OnTreeViewSelectedItemChanged"
                    >

                <TreeView.Resources>
                    <RoutedUICommand x:Key="DoExpandAllNodes" Text="Expand All" />
                    <RoutedUICommand x:Key="DoCollapseAllNodes" Text="Collapse All" />
                    <RoutedUICommand x:Key="DoFindModuleInList" Text="Highlight Matching Module In List" />

                    <ContextMenu x:Key="TreeItemContextMenu">
                        <MenuItem Header="Highlight Matching Module In List" 
                                Command="{StaticResource DoFindModuleInList}"
                                CommandParameter="{Binding RelativeSource={RelativeSource  AncestorLevel=1,AncestorType=TreeViewItem,Mode=FindAncestor}}"
                                InputGestureText="Ctrl+M" 
                                IsEnabled="True" />
                        <Separator Height="3" Margin="-1,0,0,0"/>
                        <MenuItem Header="Copy File Path" 
                                Command="{Binding Path=DataContext.MoreInfo, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListView}}" 
                                Background="WhiteSmoke" 
                                InputGestureText="Ctrl+C" 
                                IsEnabled="False"  />
                        <Separator Height="3" Margin="-1,0,0,0"/>
                        <MenuItem Header="Expand All" 
                                Command="{StaticResource DoExpandAllNodes}"
                                IsEnabled="True"  />
                        <MenuItem Header="Collapse All" 
                                Command="{StaticResource DoCollapseAllNodes}"
                                IsEnabled="True"  />
                        <Separator Height="3" Margin="-1,0,0,0"/>
                        <MenuItem Name="FullPathItemTree" Header="Full Paths" Height="25" InputGestureText="F9" IsCheckable="True" IsChecked="{Binding Source={x:Static properties:Settings.Default}, Path=FullPath, Mode=TwoWay}" Margin="0,0,0.2,0"/>
                        <Separator Height="3" Margin="-1,0,0,0"/>

                        <MenuItem Header="View Module in separate application" 
                                Command="{Binding  Path=OpenNewAppCommand, RelativeSource={RelativeSource AncestorLevel=1,AncestorType=TreeViewItem,Mode=FindAncestor}}"
                                CommandParameter ="{Binding DataContext, RelativeSource={RelativeSource AncestorLevel=1,AncestorType=Grid,Mode=FindAncestor}}"
                                InputGestureText="Alt+Enter"  
                                IsEnabled="True" />

                        <MenuItem Header="View Module in Peviewer" 
                                Command="{Binding  Path=OpenPeviewerCommand, RelativeSource={RelativeSource AncestorLevel=1,AncestorType=TreeViewItem,Mode=FindAncestor}}"
                                CommandParameter ="{Binding DataContext, RelativeSource={RelativeSource AncestorLevel=1,AncestorType=Grid,Mode=FindAncestor}}"
                                InputGestureText="Alt+Enter"  
                                IsEnabled="True" />

                        <!--AncestorType=Grid To get the current context feel like magic to me -->
                    </ContextMenu>

                    <Style TargetType="local:ModuleTreeViewItem">
                        <Setter Property="HeaderTemplate">
                            <Setter.Value>
                                <DataTemplate>
                                    <Grid Margin="0,0,5,0">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="24"/>
                                            <ColumnDefinition Width="3" />
                                            <ColumnDefinition Width="*" />
                                        </Grid.ColumnDefinitions>

                                        
                                        <!--System icon for the current module-->
                                        <Image Grid.Column="0" Width="16" Height="16" Margin="0,0,0,0" 
                                               Source="{Binding Path=(local:ModuleTreeViewItem.ModuleFilePath), RelativeSource={RelativeSource AncestorLevel=1,AncestorType=TreeViewItem,Mode=FindAncestor}, Converter={StaticResource img} }"
                                        ></Image>
                                        
                                        <!--Overlay for additional flags (delay import, apiset, etc.)-->
                                        <Image Grid.Column="0" Width="16" Height="16" Margin="4,0,0,0" Source="{Binding Path=(local:ModuleTreeViewItem.Flags), RelativeSource={RelativeSource AncestorLevel=1,AncestorType=TreeViewItem,Mode=FindAncestor}, Converter={StaticResource img_overlay} }"></Image>

                                        <!--Another red rectangle overlay on modules issues-->
                                        <Rectangle x:Name="ErrorModule"  Grid.Column="0" Width="14" Height="14" 
                                                   Visibility="{Binding Path=(local:ModuleTreeViewItem.HasErrors), RelativeSource={RelativeSource AncestorLevel=1,AncestorType=TreeViewItem,Mode=FindAncestor}, Converter={StaticResource BooleanToVisibility}}"
                                                   >
                                            <Rectangle.Fill>
                                                <SolidColorBrush Color="Red" />
                                            </Rectangle.Fill>
                                            <Rectangle.OpacityMask>
                                                <DrawingBrush AlignmentX="Left" AlignmentY="Top">
                                                    <DrawingBrush.Drawing>
                                                        <DrawingGroup>
                                                            <GeometryDrawing Brush="#33000000">
                                                                <GeometryDrawing.Geometry>
                                                                    <RectangleGeometry Rect="0,0,40,40" />
                                                                </GeometryDrawing.Geometry>
                                                            </GeometryDrawing>
                                                        </DrawingGroup>
                                                    </DrawingBrush.Drawing>
                                                </DrawingBrush>
                                            </Rectangle.OpacityMask>
                                        </Rectangle>
                                        
                                        <TextBlock Grid.Column="2" Text="{Binding}"></TextBlock>
                                    </Grid>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                        
                        <Setter Property="FontFamily" Value="{Binding Source={x:Static properties:Settings.Default}, Path=Font, Mode=OneWay}" />
                        <Setter Property="ContextMenu" Value="{StaticResource TreeItemContextMenu}" />
                        
                    </Style>

                </TreeView.Resources>

                <TreeView.CommandBindings>
                    <CommandBinding Command="{StaticResource DoExpandAllNodes}" Executed="ExpandAllNodes_Executed"/>
                    <CommandBinding Command="{StaticResource DoCollapseAllNodes}" Executed="CollapseAllNodes_Executed"/>
                    <CommandBinding Command="{StaticResource DoFindModuleInList}" Executed="DoFindModuleInList_Executed"/>
                </TreeView.CommandBindings>
            </TreeView>
            
            <GridSplitter Grid.Column="1" 
                          HorizontalContentAlignment="Stretch"
                          VerticalContentAlignment="Stretch"
                          HorizontalAlignment="Stretch"/>
            
            <Grid x:Name="ImportExportGrid" Grid.Column="2">

                <Grid.RowDefinitions>
                    <RowDefinition Height="145*"/>
                    <RowDefinition Height="5"/>
                    <RowDefinition Height="142*"/>
                </Grid.RowDefinitions>

                <local:DependencyImportList x:Name="ImportList" 
                                            Grid.Row="0" />


                <GridSplitter x:Name="ImportExportSplitter" 
                              HorizontalAlignment="Stretch" 
                              HorizontalContentAlignment="Stretch" 
                              VerticalContentAlignment="Center" 
                              MinHeight="8" 
                              Grid.Row="1"/>

                <local:DependencyExportList x:Name="ExportList" 
                                            Grid.Row="2" />

            </Grid>

        </Grid>
        

        <GridSplitter x:Name="LogSplitter" 
                      HorizontalAlignment="Stretch" 
                      HorizontalContentAlignment="Stretch" 
                      VerticalContentAlignment="Stretch" 
                      Grid.Row="1"/>



        <local:DependencyModuleList x:Name="ModulesList"
                                    Grid.Row="2"
                                    SelectedModuleChanged="OnModuleViewSelectedItemChanged"
                                    />
                                    


    </Grid>
</TabItem>
