<!--
Copyright 2019 faddenSoft

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<Window x:Class="SourceGen.WpfGui.EditProjectProperties"
        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:system="clr-namespace:System;assembly=mscorlib"
        xmlns:local="clr-namespace:SourceGen.WpfGui"
        mc:Ignorable="d"
        Title="Edit Project Properties"
        Width="640" Height="400" ResizeMode="NoResize"
        ShowInTaskbar="False" WindowStartupLocation="CenterOwner"
        Loaded="Window_Loaded" Closing="Window_Closing">

    <Window.Resources>
        <!-- don't center the column headers -->
        <Style TargetType="{x:Type GridViewColumnHeader}">
            <Setter Property="HorizontalContentAlignment" Value="Left" />
        </Style>

        <system:String x:Key="str_ConfirmDiscardChanges">Some changes have not been applied.  Discard them?</system:String>
        <system:String x:Key="str_ConfirmDiscardChangesCaption">Discard Changes?</system:String>

        <!-- strings for combo boxes -->
        <system:String x:Key="str_6502">MOS 6502</system:String>
        <system:String x:Key="str_65C02">WDC W65C02S</system:String>
        <system:String x:Key="str_65816">WDC W65C816S</system:String>

        <system:String x:Key="str_DisableStringScan">None (disabled)</system:String>

        <system:String x:Key="str_AutoLabelSimple">Simple ("L1234")</system:String>
        <system:String x:Key="str_AutoLabelAnnotated">Annotated ("W_1234")</system:String>
        <system:String x:Key="str_AutoLabelFullyAnnotated">Fully Annotated ("DWR_1234")</system:String>
    </Window.Resources>

    <DockPanel Margin="8">
        <DockPanel DockPanel.Dock="Bottom">
            <Button DockPanel.Dock="Right" Name="cancelButton" Content="Cancel" IsCancel="True"
                    Width="70" Margin="4,0,0,0"/>
            <Button DockPanel.Dock="Right" Name="okButton" Content="OK" IsDefault="True"
                    Width="70" Click="OkButton_Click"/>
            <Button DockPanel.Dock="Right" Name="applyButton" Content="Apply" Margin="0,0,20,0"
                    Width="70" IsEnabled="{Binding IsDirty}" Click="ApplyButton_Click"/>
            <TextBlock DockPanel.Dock="Left" Text="NOTE: changes are added to the undo/redo buffer"/>
        </DockPanel>

        <TabControl Name="tabControl" DockPanel.Dock="Top" Margin="0,0,0,8">
            <TabItem Name="generalTab" Header="General">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <GroupBox Header="CPU" Grid.Column="0" Grid.Row="0" Padding="2,4">
                        <StackPanel>
                            <ComboBox Name="cpuComboBox" ItemsSource="{Binding CpuItems}" DisplayMemberPath="Name"
                                      SelectionChanged="CpuComboBox_SelectionChanged"/>
                            <CheckBox Margin="0,4,0,0" Content="Enable undocumented instructions"
                                      IsChecked="{Binding IncludeUndocumentedInstr}"/>
                            <CheckBox Margin="0,4,0,0" Content="Treat BRK as two-byte instruction"
                                      IsChecked="{Binding TwoByteBrk}"/>
                        </StackPanel>
                    </GroupBox>
                    <GroupBox Header="Entry Flags" Grid.Column="0" Grid.Row="1" Padding="2,4">
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="Flags:"/>
                                <TextBlock Name="currentFlagsText" Margin="4,2,0,0"
                                           Text="N- V- M- X- D- I- Z- C- E-"
                                           FontFamily="{StaticResource GeneralMonoFont}"/>
                            </StackPanel>
                            <Button Width="75" Content="Change" Margin="0,4,0,0"
                                    HorizontalAlignment="Left" Click="ChangeFlagButton_Click"/>
                        </StackPanel>
                    </GroupBox>

                    <GroupBox Header="Analysis Parameters" Grid.Column="1" Grid.Row="0" Grid.RowSpan="2"
                              Margin="4,0,0,0" Padding="2,4">
                        <StackPanel>
                            <CheckBox Content="Analyze uncategorized data"
                                      IsChecked="{Binding AnalyzeUncategorizedData}"/>
                            <CheckBox Margin="0,4,0,0" Content="Seek nearby targets"
                                      IsChecked="{Binding SeekNearbyTargets}"/>
                            <CheckBox Margin="0,4,0,0" Content="Smart PLP handling"
                                      IsChecked="{Binding SmartPlpHandling}"/>

                            <StackPanel Orientation="Horizontal" Margin="0,4,0,0">
                                <TextBlock Margin="0,3,0,0" Text="Default text encoding:"/>
                                <ComboBox Name="defaultTextEncComboBox" Margin="8,2,0,0"
                                          Width="142"
                                          ItemsSource="{Binding DefaultTextScanModeItems}" DisplayMemberPath="Name"
                                          SelectionChanged="DefaultTextEncComboBox_SelectionChanged"/>
                            </StackPanel>

                            <StackPanel Orientation="Horizontal" Margin="0,4,0,0">
                                <TextBlock Margin="0,3,0,0" Text="Min chars for string detection:"/>
                                <ComboBox Name="minStringCharsComboBox" Margin="8,2,0,0" Width="100"
                                          ItemsSource="{Binding MinCharsItems}" DisplayMemberPath="Name"
                                          SelectionChanged="MinStringCharsComboBox_SelectionChanged"/>
                            </StackPanel>
                        </StackPanel>
                    </GroupBox>

                    <GroupBox Header="Miscellaneous" Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2"
                              Padding="2,4">
                        <DockPanel>
                            <TextBlock DockPanel.Dock="Left" Text="Auto-label style:" Margin="0,2,8,0"/>
                            <ComboBox DockPanel.Dock="Left" Name="autoLabelStyleComboBox"
                                      Width="300" HorizontalAlignment="Left"
                                      ItemsSource="{Binding AutoLabelItems}" DisplayMemberPath="Name"
                                      SelectionChanged="AutoLabelStyleComboBox_SelectionChanged"/>
                        </DockPanel>
                    </GroupBox>
                </Grid>
            </TabItem>


            <TabItem Name="projectSymbolsTab" Header="Project Symbols">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="*"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>

                    <TextBlock Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2"
                               Margin="4,0,0,0" Text="Symbols defined in project:"/>

                    <DataGrid Name="projectSymbolsList" Grid.Column="0" Grid.Row="1" Margin="4,4,4,0"
                              ItemsSource="{Binding ProjectSymbols}"
                              IsReadOnly="True"
                              FontFamily="{StaticResource GeneralMonoFont}"
                              SnapsToDevicePixels="True"
                              GridLinesVisibility="Vertical"
                              VerticalGridLinesBrush="#FF7F7F7F"
                              AutoGenerateColumns="False"
                              HeadersVisibility="Column"
                              CanUserReorderColumns="False"
                              SelectionMode="Single"
                              SelectionChanged="List_SelectionChanged"
                              Sorting="ProjectSymbolsList_Sorting"
                              MouseDoubleClick="ProjectSymbolsList_MouseDoubleClick">
                        <DataGrid.Resources>
                            <!-- make the no-focus color the same as the in-focus color -->
                            <!-- thanks: https://stackoverflow.com/a/13053511/294248 -->
                            <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}"
                                 Color="{x:Static SystemColors.HighlightColor}"/>
                            <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}"
                                 Color="{x:Static SystemColors.HighlightTextColor}"/>
                        </DataGrid.Resources>
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Name" Width="118" Binding="{Binding Label}"/>
                            <DataGridTextColumn Header="Value" Width="72" Binding="{Binding Value}"/>
                            <DataGridTextColumn Header="Type" Width="45" Binding="{Binding Type}"/>
                            <DataGridTextColumn Header="Width" Width="45" Binding="{Binding Width}"/>
                            <DataGridTextColumn Header="Comment" Width="300" Binding="{Binding Comment}"/>
                        </DataGrid.Columns>
                    </DataGrid>

                    <StackPanel Grid.Column="1" Grid.Row="1">
                        <Button Name="newSymbolButton" Width="120" Margin="4" Content="_New Symbol..."
                                Click="NewSymbolButton_Click"/>
                        <Button Name="editSymbolButton" Width="120" Margin="4,4" Content="_Edit Symbol..."
                                Click="EditSymbolButton_Click"/>
                        <Button Name="removeSymbolButton" Width="120" Margin="4,4" Content="_Remove"
                                Click="RemoveSymbolButton_Click"/>
                        <Button Name="importSymbolsButton" Width="120" Margin="4,20,4,0" Content="_Import..."
                                Click="ImportSymbolsButton_Click"/>
                    </StackPanel>
                </Grid>
            </TabItem>


            <TabItem Name="symbolFilesTab" Header="Symbol Files">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="300"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <TextBlock Grid.Column="0" Grid.Row="0" Margin="4,0,0,0"
                               Text="Currently configured symbol files:"/>

                    <ListBox Name="symbolFilesListBox" Grid.Column="0" Grid.Row="1" Margin="4"
                             SelectionMode="Extended"
                             ItemsSource="{Binding PlatformSymbolIdentifiers}"
                             SelectionChanged="List_SelectionChanged"/>

                    <StackPanel Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" Orientation="Horizontal">
                        <Button Width="200" Margin="4"
                                Content="Add Symbol Files from Runtime..."
                                Click="AddSymbolFilesPlatformButton_Click"/>
                        <Button Width="200" Margin="4"
                                Content="Add Symbol Files from Project..."
                                IsEnabled="{Binding HasProjectDir}"
                                Click="AddSymbolFilesProjectButton_Click"/>
                    </StackPanel>

                    <StackPanel Grid.Column="2" Grid.Row="1">
                        <Button Name="symbolFileUpButton" Width="75" Margin="4" Content="_Up"
                                Click="SymbolFileUpButton_Click"/>
                        <Button Name="symbolFileDownButton" Width="75" Margin="4,4" Content="_Down"
                                Click="SymbolFileDownButton_Click"/>
                        <Button Name="symbolFileRemoveButton" Width="75" Margin="4,20,4,0" Content="_Remove"
                                Click="SymbolFileRemoveButton_Click"/>
                    </StackPanel>
                </Grid>
            </TabItem>


            <TabItem Name="extensionScriptsTab" Header="Extension Scripts">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="300"/>
                        <ColumnDefinition Width="Auto"/>
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>

                    <TextBlock Grid.Column="0" Grid.Row="0" Margin="4,0,0,0"
                               Text="Currently configured extension scripts:"/>

                    <ListBox Name="extensionScriptsListBox" Grid.Column="0" Grid.Row="1" Margin="4"
                             SelectionMode="Extended"
                             ItemsSource="{Binding ExtensionScriptIdentifiers}"
                             SelectionChanged="List_SelectionChanged"/>

                    <StackPanel Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="2" Orientation="Horizontal">
                        <Button Width="200" Margin="4"
                                Content="Add Scripts from Runtime..."
                                Click="AddExtensionScriptsPlatformButton_Click"/>
                        <Button Width="200" Margin="4"
                                Content="Add Scripts from Project..."
                                IsEnabled="{Binding HasProjectDir}"
                                Click="AddExtensionScriptsProjectButton_Click"/>
                    </StackPanel>

                    <StackPanel Grid.Column="1" Grid.Row="1">
                        <Button Name="extensionScriptRemoveButton" Width="75" Margin="4" Content="_Remove"
                                Click="ExtensionScriptRemoveButton_Click"/>
                    </StackPanel>
                </Grid>
            </TabItem>
        </TabControl>

    </DockPanel>
</Window>
