<Window x:Class="Serein.Workbench.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:local="clr-namespace:Serein.Workbench"
        xmlns:tool="clr-namespace:Serein.Workbench.Tool.Converters"
        xmlns:nodeView="clr-namespace:Serein.Workbench.Node.View"
        xmlns:themes="clr-namespace:Serein.Workbench.Themes"
        xmlns:converters="clr-namespace:Serein.Workbench.Tool.Converters"
        mc:Ignorable="d"
        d:DataContext="{d:DesignInstance local:MainWindowViewModel}"
        Title="Dynamic Node Flow" Height="900" Width="1400"
        AllowDrop="True" 
        Drop="Window_Drop" 
        DragOver="Window_DragOver"
        Loaded="Window_Loaded"
        ContentRendered="Window_ContentRendered"
        PreviewKeyDown="Window_PreviewKeyDown"
        Closing="Window_Closing">

    <Window.Resources>
        <converters:InvertableBooleanToVisibilityConverter x:Key="InvertedBoolConverter"/>
        <tool:RightThumbPositionConverter x:Key="RightThumbPositionConverter" />
        <tool:BottomThumbPositionConverter x:Key="BottomThumbPositionConverter" />
        <tool:VerticalCenterThumbPositionConverter x:Key="VerticalCenterThumbPositionConverter" />
        <tool:HorizontalCenterThumbPositionConverter x:Key="HorizontalCenterThumbPositionConverter" />
    </Window.Resources>

    <Window.InputBindings>
        <!--<KeyBinding Key="Escape" Command="{Binding CancelConnectionCommand}"/>-->
    </Window.InputBindings>
    
    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300"/>
            <ColumnDefinition Width="5"/>
            <ColumnDefinition Width="3*"/>
            <ColumnDefinition Width="5"/>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>

        <Menu DockPanel.Dock="Top" Grid.Row="0" Grid.ColumnSpan="5" Height="20">
            
            <MenuItem Header="项目">
                <!--菜单项为MenuItem，文字使用属性 Header-->
                <MenuItem Header="保存项目" Click="ButtonSaveFile_Click" ></MenuItem>
                <MenuItem Header="打开本地文件" Click="ButtonOpenLocalProject_Click"></MenuItem>
            </MenuItem>
            <MenuItem Header="拓展">
                <!--菜单项为MenuItem，文字使用属性 Header-->
                <MenuItem Header="动态编译" Click="OpenDynamicCompileEdit_Click" ></MenuItem>
            </MenuItem>
            <MenuItem Header="调试">
                <MenuItem Header="运行（从起始节点）" Click="ButtonDebugRun_Click"></MenuItem>
                <MenuItem Header="运行（从选定节点）" Click="ButtonStartFlowInSelectNode_Click"></MenuItem>
                <MenuItem Header="结束流程" Click="ButtonDebugFlipflopNode_Click"></MenuItem>
            </MenuItem>
            <MenuItem Header="视图">
                <MenuItem Header="输出窗口" Click="ButtonOpenConsoleOutWindow_Click"></MenuItem>
                <MenuItem Header="重置画布" Click="ButtonResetCanvas_Click"></MenuItem>
                <MenuItem Header="定位节点" Click="ButtonLocationNode_Click"></MenuItem>
            </MenuItem>
            <MenuItem Header="远程">
                <MenuItem Header="启动远程服务" Click="ButtonStartRemoteServer_Click"></MenuItem>

                <MenuItem Header="连接远程环境" Click="ButtonConnectionRemoteEnv_Click"></MenuItem>
            </MenuItem>
            <!--<MenuItem Header="说明"></MenuItem>-->
        </Menu>

        <DockPanel Grid.Row="1" Grid.Column="0" Background="#F5F5F5">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto"></RowDefinition>
                    <RowDefinition Height="*"></RowDefinition>
                    <!--<RowDefinition Height="3"></RowDefinition>-->
                    <!--<RowDefinition Height="3*"></RowDefinition>-->
                </Grid.RowDefinitions>

                <!--暂时隐藏基础面板  Visibility="Collapsed"  -->
                <ScrollViewer Grid.Row="0" HorizontalScrollBarVisibility="Auto">
                    <StackPanel  Orientation="Horizontal">
                        <!--<nodeView:NetScriptNodeControl x:Name="NetScriptNodeControl" Margin="10" AllowDrop="True" PreviewMouseMove="BaseNodeControl_PreviewMouseMove"/>-->
                        <nodeView:ScriptNodeControl x:Name="ScriptNodeControl" Margin="10" AllowDrop="True" PreviewMouseMove="BaseNodeControl_PreviewMouseMove"/>
                        <nodeView:GlobalDataControl x:Name="GlobalDataControl" Margin="10" AllowDrop="True" PreviewMouseMove="BaseNodeControl_PreviewMouseMove"/>
                        <nodeView:ExpOpNodeControl x:Name="ExpOpNodeControl" Margin="10" AllowDrop="True" PreviewMouseMove="BaseNodeControl_PreviewMouseMove"/>
                        <nodeView:ConditionNodeControl x:Name="ConditionNodeControl" Margin="10" AllowDrop="True" PreviewMouseMove="BaseNodeControl_PreviewMouseMove"/>
                        <!--<nodeView:ConditionRegionControl  x:Name="ConditionRegionControl" Margin="10" AllowDrop="True" PreviewMouseMove="BaseNodeControl_PreviewMouseMove"/>-->
                    </StackPanel>
                </ScrollViewer>
                
                <ScrollViewer VerticalAlignment="Top" Grid.Row="1"  VerticalScrollBarVisibility="Auto" Grid.RowSpan="2">
                    <StackPanel x:Name="DllStackPanel" Margin="5"/>
                </ScrollViewer>
                <!--<GridSplitter Grid.Row="3" Height="5" HorizontalAlignment="Stretch" VerticalAlignment="Center" ResizeBehavior="PreviousAndNext" Background="Gray"/>-->
                
            </Grid>
        </DockPanel>

        <GridSplitter  Grid.Row="1"   Grid.Column="1" Width="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ResizeBehavior="PreviousAndNext" Background="Gray" />

        <Grid  Grid.Row="1"  Grid.Column="2" x:Name="FlowChartStackGrid">
            <ListBox ItemsSource="{Binding Nodes}" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            
            <StackPanel x:Name="FlowChartStackPanel"
                         ClipToBounds="True">
                <!-- 虚拟化 VirtualizingStackPanel.IsVirtualizing="True" -->
                <Canvas 
                    x:Name="FlowChartCanvas" 
                    Background="#E1FBEA"
                    AllowDrop="True" 
                    Width="1920"
                    Height="1080"
                    MouseLeftButtonDown ="FlowChartCanvas_MouseLeftButtonDown"
                    MouseLeftButtonUp="FlowChartCanvas_MouseLeftButtonUp"
                    MouseDown="FlowChartCanvas_MouseDown"
                    MouseUp="FlowChartCanvas_MouseUp"
                    MouseMove="FlowChartCanvas_MouseMove"
                    MouseWheel="FlowChartCanvas_MouseWheel"
                    Drop="FlowChartCanvas_Drop" 
                    DragOver="FlowChartCanvas_DragOver"
                    >

                    <Rectangle x:Name="SelectionRectangle" 
                               Stroke="Blue" 
                               StrokeThickness="2" 
                               Fill="LightBlue" 
                               Opacity="0.2" 
                               Panel.ZIndex="999999"
                               Visibility="Collapsed"/>

                    <!-- Top-Left Thumb -->
                    <!--<Thumb x:Name="TopLeftThumb" 
                           Width="10" Height="10"
                           DragDelta="Thumb_DragDelta_TopLeft"
                           Cursor="SizeNWSE"
                           Canvas.Left="0" Canvas.Top="0"/>-->

                    <!-- Top-Right Thumb -->
                    <!--<Thumb x:Name="TopRightThumb" 
                           Width="10" Height="10"
                           DragDelta="Thumb_DragDelta_TopRight"
                           Cursor="SizeNESW"
                           Canvas.Left="{Binding ActualWidth, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource RightThumbPositionConverter}}" 
                           Canvas.Top="0"/>-->

                    <!-- Bottom-Left Thumb -->
                    <!--<Thumb x:Name="BottomLeftThumb" 
                           Width="10" Height="10"
                           DragDelta="Thumb_DragDelta_BottomLeft"
                           Cursor="SizeNESW"
                           Canvas.Left="0" 
                           Canvas.Top="{Binding ActualHeight, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource BottomThumbPositionConverter}}"/>-->

                    <!-- Left Thumb -->
                    <!--<Thumb x:Name="LeftThumb" 
                           Width="10" Height="10"
                           DragDelta="Thumb_DragDelta_Left"
                           Cursor="SizeWE"
                           Canvas.Left="0" 
                           Canvas.Top="{Binding ActualHeight, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource VerticalCenterThumbPositionConverter}}"/>-->

                    <!-- Right Thumb -->

                    <!-- Top Thumb -->
                    <!--<Thumb x:Name="TopThumb" 
                           Width="10" Height="10"
                           DragDelta="Thumb_DragDelta_Top"
                           Cursor="SizeNS"
                           Canvas.Left="{Binding ActualWidth, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource HorizontalCenterThumbPositionConverter}}" 
                           Canvas.Top="0"/>-->

                    <!-- Bottom Thumb -->
                    <!-- Bottom-Right Thumb -->
                    <Thumb x:Name="BottomRightThumb" 
                           Width="15" Height="15"
                           DragDelta="Thumb_DragDelta_BottomRight"
                           Cursor="SizeNWSE"
                           Canvas.Left="{Binding ActualWidth, Converter={StaticResource RightThumbPositionConverter}, ElementName=FlowChartCanvas, Mode=OneWay}" 
                           Canvas.Top="{Binding ActualHeight, Converter={StaticResource BottomThumbPositionConverter}, ElementName=FlowChartCanvas, Mode=OneWay}"/>

                    <!--Canvas.Left="{Binding ActualWidth, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource RightThumbPositionConverter}}" 
Canvas.Top="{Binding ActualHeight, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource VerticalCenterThumbPositionConverter}}"-->
                    <Thumb x:Name="RightThumb" Width="5" Cursor="SizeWE" Canvas.Top="0" Canvas.Right="0" DragDelta="Thumb_DragDelta_Right">
                        <Thumb.Template>
                            <ControlTemplate>
                                <Border Background="#B1B9F8" Width="5" Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type Canvas}}}" />
                            </ControlTemplate>
                        </Thumb.Template>
                    </Thumb>

                    <!--Canvas.Left="{Binding ActualWidth, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource HorizontalCenterThumbPositionConverter}}" 
 Canvas.Top="{Binding ActualHeight, ElementName=FlowChartCanvas, Mode=OneWay, Converter={StaticResource BottomThumbPositionConverter}}"-->
                    <Thumb x:Name="BottomThumb" Height="5" Cursor="SizeNS" Canvas.Bottom="0" Canvas.Left="0"  DragDelta="Thumb_DragDelta_Bottom">
                        <Thumb.Template>
                            <ControlTemplate>
                                <Border Background="#B1B9F8" Height="5" Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type Canvas}}}" />
                            </ControlTemplate>
                        </Thumb.Template>
                    </Thumb>
                </Canvas>


            </StackPanel>
            <StackPanel>
                <StackPanel x:Name="CreateNodeInvoke"
                            Margin="14" Width="auto" HorizontalAlignment="Left" Background="White" Opacity="0.8"
                            Visibility="{Binding IsConnectionInvokeNode, 
                                Converter={StaticResource InvertedBoolConverter},ConverterParameter=Normal}" >
                    <TextBlock Margin="8,2,8,0" Foreground="#FF2727" FontSize="14" Text="正在设置方法调用关系 （ 按 Ecs 退出连线状态 )"/>
                    <TextBlock Margin="8,0,8,0" Foreground="#4A82E4" FontSize="14" Text="  按 1 切换：上游分支（运行本节点前，优先执行目标节点）"/>
                    <TextBlock Margin="8,0,8,0" Foreground="#04FC10" FontSize="14" Text="  按 2 切换：Succeed 分支（本节点运行完成，将会运行目标节点）"/>
                    <TextBlock Margin="8,0,8,0" Foreground="#F18905" FontSize="14" Text="  按 3 切换：Fail 分支（条件节点的false分支）"/>
                    <TextBlock Margin="8,0,8,2" Foreground="#FE1343" FontSize="14" Text="  按 4 切换：异常分支（本节点运行发生异常时执行目标节点）"/>
                </StackPanel>
                <StackPanel Margin="14" Width="auto" HorizontalAlignment="Left" Background="White" Opacity="0.8"
                            Visibility="{Binding IsConnectionArgSourceNode, 
                            Converter={StaticResource InvertedBoolConverter},ConverterParameter=Normal}" >
                    <TextBlock Margin="8,2,8,0" Foreground="#FF2727" FontSize="14" Text="正在设置参数传递关系 （ 按 Ecs 退出连线状态 )"/>
                    <TextBlock Margin="8,0,8,0" Foreground="#56CEF6" FontSize="14" Text="  按 1 切换：使用返回值作为当前上下文的入参参数（当前上下文下如果未曾运行过该节点，将会返回null）"/>
                    <TextBlock Margin="8,0,8,2" Foreground="#B06BBB" FontSize="14" Text="  按 2 切换：立刻调用节点，取其返回值作为当前上下文的入参参数"/>
                </StackPanel>
            </StackPanel>
        </Grid>
        <GridSplitter  Grid.Row="1"  Grid.Column="3" Width="5" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ResizeBehavior="PreviousAndNext" Background="Gray" />
        <!--IOC容器属性-->
        <Grid  Grid.Row="1"  Grid.Column="4" >
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition Height="*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            <Grid Grid.Row="0" >
                <!--<themes:LazyTreeView x:Name="lazyTreeView" />-->
                <themes:NodeTreeViewControl x:Name="NodeTreeViewer"></themes:NodeTreeViewControl>
            </Grid>
            <Grid Grid.Row="1" >
                <themes:IOCObjectViewControl x:Name="IOCObjectViewer">
                    <!--<x:Arguments>
                        <x:String>Apple</x:String>
                    </x:Arguments>-->
                </themes:IOCObjectViewControl>
            </Grid>
            <Grid  Grid.Row="3"  Margin="0,3,0,0" Grid.RowSpan="2">
                <themes:ObjectViewerControl x:Name="ViewObjectViewer"></themes:ObjectViewerControl>
            </Grid>
        </Grid>

    </Grid>
</Window>
