<!--
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.MainWindow"
        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:SourceGen.WpfGui"
        xmlns:system="clr-namespace:System;assembly=mscorlib"
        mc:Ignorable="d"
        Title="6502bench SourceGen"
        Icon="/SourceGen;component/Res/SourceGenIcon.ico"
        Width="1200" Height="700" MinWidth="800" MinHeight="500" ResizeMode="CanResizeWithGrip"
        SourceInitialized="Window_SourceInitialized"
        Loaded="Window_Loaded"
        LocationChanged="Window_LocationChanged"
        SizeChanged="Window_SizeChanged"
        MouseDown="Window_MouseDown"
        Closing="Window_Closing">

    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="CodeListItemStyle.xaml"/>
                <ResourceDictionary Source="/Res/CommandIcons.xaml"/>
                <!--<ResourceDictionary Source="/Res/Theme_Light.xaml"/>-->
            </ResourceDictionary.MergedDictionaries>

            <BooleanToVisibilityConverter x:Key="BoolToVis"/>

            <!-- strings for message button -->
            <system:String x:Key="str_MessageSingularFmt">{0} message</system:String>
            <system:String x:Key="str_MessageSingularWarningFmt">{0} message ({1} warning/error)</system:String>
            <system:String x:Key="str_MessagePluralFmt">{0} messages</system:String>
            <system:String x:Key="str_MessagePluralWarningFmt">{0} messages ({1} warning/error)</system:String>

            <!-- don't center the ListView(GridView) column headers
            https://stackoverflow.com/q/44119146/294248
            (style without ID applies to all instances of that type)
            -->
            <Style TargetType="{x:Type GridViewColumnHeader}">
                <Setter Property="HorizontalContentAlignment" Value="Left" />
            </Style>

            <RoutedUICommand x:Key="AboutCmd" Text="About..."/>
            <RoutedUICommand x:Key="AssembleCmd" Text="Generate Assembly...">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+Shift+A</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="CloseCmd" Text="Close"/>
            <RoutedUICommand x:Key="ConcatenateFilesCmd" Text="Concatenate Files..."/>
            <RoutedUICommand x:Key="ConvertOmfCmd" Text="Convert OMF..."/>
            <RoutedUICommand x:Key="CreateLocalVariableTableCmd" Text="Create Local Variable Table..."/>
            <RoutedUICommand x:Key="DeleteMlcCmd" Text="Delete Note/Long Comment">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Del</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="EditAddressCmd" Text="Create/Edit Address Region..."/>
            <RoutedUICommand x:Key="EditAppSettingsCmd" Text="Settings..."/>
            <RoutedUICommand x:Key="EditCommentCmd" Text="Edit Comment...">
                <RoutedUICommand.InputGestures>
                    <!-- this works, but appears as "Ctrl+Oem1", so override tip in menu items -->
                    <KeyGesture>Ctrl+Semicolon</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="EditDataBankCmd" Text="Edit Data Bank..."/>
            <RoutedUICommand x:Key="EditHeaderCommentCmd" Text="Edit Header Comment..."/>
            <RoutedUICommand x:Key="EditOperandCmd" Text="Edit Operand...">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+O</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="EditLabelCmd" Text="Edit Label...">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+L</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="EditLocalVariableTableCmd" Text="Edit Prior Local Variable Table..."/>
            <RoutedUICommand x:Key="EditLongCommentCmd" Text="Edit Long Comment...">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+M</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="EditNoteCmd" Text="Edit Note...">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+N</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="EditOperandTargetLabelCmd" Text="Edit Operand Target Label...">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+Shift+L</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="EditProjectPropertiesSymbolsCmd">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>F6</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="EditProjectSymbolCmd" Text="Edit Project Symbol..."/>
            <RoutedUICommand x:Key="EditStatusFlagsCmd" Text="Override Status Flags..."/>
            <RoutedUICommand x:Key="EditVisualizationSetCmd" Text="Create/Edit Visualization Set...">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Alt+V</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="ExitCmd" Text="Exit"/>
            <RoutedUICommand x:Key="ExportCmd" Text="Export Listing...">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+Shift+E</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="FindAllCmd" Text="Find All">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+Shift+F</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="FindNextCmd" Text="Find Next">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>F3</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="FindPreviousCmd" Text="Find Previous">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Shift+F3</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="FormatAsWordCmd" Text="Format As Word">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+W</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="FormatAddressTableCmd" Text="Format Address Table..."/>
            <RoutedUICommand x:Key="GenerateLabelsCmd" Text="Generate Label File..."/>
            <RoutedUICommand x:Key="GotoCmd" Text="Go To...">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+G</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="GotoLastChangeCmd" Text="Go to Last Change"/>
            <RoutedUICommand x:Key="TagAsCodeStartPointCmd" Text="Tag Address As Code Start Point"/>
            <RoutedUICommand x:Key="TagAsCodeStopPointCmd" Text="Tag Address As Code Stop Point"/>
            <RoutedUICommand x:Key="TagAsInlineDataCmd" Text="Tag Bytes As Inline Data"/>
            <RoutedUICommand x:Key="JumpToOperandCmd" Text="Jump to Operand">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+J</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="NavigateBackwardCmd" Text="Nav Backward">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Alt+Left</KeyGesture>
                    <KeyGesture>Ctrl+Minus</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="NavigateForwardCmd" Text="Nav Forward">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Alt+Right</KeyGesture>
                    <KeyGesture>Ctrl+Shift+Minus</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="NewProjectCmd" Text="New"/>
            <RoutedUICommand x:Key="OpenCmd" Text="Open"/>
            <RoutedUICommand x:Key="RecentProjectCmd"/>
            <RoutedUICommand x:Key="RedoCmd" Text="Redo">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+Y</KeyGesture>
                    <KeyGesture>Ctrl+Shift+Z</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="ReloadExternalFilesCmd" Text="Reload External Files">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+Shift+R</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="RemoveAnalyzerTagsCmd" Text="Remove Analyzer Tags"/>
            <RoutedUICommand x:Key="RemoveFormattingCmd" Text="Remove Formatting"/>
            <RoutedUICommand x:Key="SelectAllCmd" Text="Select All">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+A</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="ShowFileHexDumpCmd" Text="File Hex Dump..."/>
            <RoutedUICommand x:Key="ShowHexDumpCmd" Text="Show Hex Dump"/>
            <RoutedUICommand x:Key="SliceFilesCmd" Text="Slice Files..."/>
            <RoutedUICommand x:Key="ToggleApple2ScreenChartCmd" Text="Apple II Screen Chart"/>
            <RoutedUICommand x:Key="ToggleAsciiChartCmd" Text="ASCII Chart"/>
            <RoutedUICommand x:Key="ToggleDataScanCmd" Text="Toggle Data Scan">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+D</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="ToggleInstructionChartCmd" Text="65xx Instruction Chart"/>
            <RoutedUICommand x:Key="ToggleSingleByteFormatCmd" Text="Toggle Single-Byte Format">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+B</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="UndoCmd" Text="Undo">
                <RoutedUICommand.InputGestures>
                    <KeyGesture>Ctrl+Z</KeyGesture>
                </RoutedUICommand.InputGestures>
            </RoutedUICommand>
            <RoutedUICommand x:Key="ViewAddressMapCmd" Text="View Address Map"/>

            <RoutedUICommand x:Key="Debug_ApplesoftToHtmlCmd" Text="Applesoft to HTML..."/>
            <RoutedUICommand x:Key="Debug_ApplyEditCommandsCmd" Text="Apply Edit Commands..."/>
            <RoutedUICommand x:Key="Debug_ApplyExternalSymbolsCmd" Text="Apply External Symbols"/>
            <RoutedUICommand x:Key="Debug_ExportEditCommandsCmd" Text="Export Edit Commands..."/>
            <RoutedUICommand x:Key="Debug_ExtensionScriptInfoCmd" Text="Extension Script Info..."/>
            <RoutedUICommand x:Key="Debug_RebootSecuritySandboxCmd" Text="Reboot Security Sandbox"/>
            <RoutedUICommand x:Key="Debug_ShowAnalysisTimersCmd" Text="Show Analysis Timers"/>
            <RoutedUICommand x:Key="Debug_ShowAnalyzerOutputCmd" Text="Show Analyzer Output"/>
            <RoutedUICommand x:Key="Debug_ShowUndoRedoHistoryCmd" Text="Show Undo/Redo History"/>
            <RoutedUICommand x:Key="Debug_SourceGenerationTestsCmd" Text="Source Generation Tests..."/>
            <RoutedUICommand x:Key="Debug_ToggleCommentRulersCmd" Text="Show Comment Rulers"/>
            <RoutedUICommand x:Key="Debug_ToggleKeepAliveHackCmd" Text="Disable Keep-Alive Hack"/>
            <RoutedUICommand x:Key="Debug_ToggleSecuritySandboxCmd" Text="Disable Security Sandbox"/>

            <CollectionViewSource x:Key="SymbolTableSource" Source="{Binding SymbolsList}"
                                  Filter="SymbolsList_Filter"/>
        </ResourceDictionary>
    </Window.Resources>

    <Window.CommandBindings>
        <CommandBinding Command="{StaticResource AboutCmd}"
                        Executed="AboutCmd_Executed"/>
        <CommandBinding Command="{StaticResource AssembleCmd}"
                        CanExecute="IsProjectOpen" Executed="AssembleCmd_Executed"/>
        <CommandBinding Command="{StaticResource CloseCmd}"
                        CanExecute="IsProjectOpen" Executed="CloseCmd_Executed"/>
        <CommandBinding Command="{StaticResource ConcatenateFilesCmd}"
                        Executed="ConcatenateFilesCmd_Executed"/>
        <CommandBinding Command="{StaticResource ConvertOmfCmd}"
                        Executed="ConvertOmfCmd_Executed"/>
        <CommandBinding Command="{StaticResource CreateLocalVariableTableCmd}"
                        CanExecute="CanCreateLocalVariableTable" Executed="CreateLocalVariableTableCmd_Executed"/>
        <CommandBinding Command="{StaticResource DeleteMlcCmd}"
                        CanExecute="CanDeleteMlc" Executed="DeleteMlcCmd_Executed"/>
        <CommandBinding Command="{StaticResource Debug_SourceGenerationTestsCmd}"
                        Executed="Debug_SourceGenerationTestsCmd_Executed"/>
        <CommandBinding Command="{StaticResource EditAddressCmd}"
                        CanExecute="CanEditAddress" Executed="EditAddressCmd_Executed"/>
        <CommandBinding Command="{StaticResource EditAppSettingsCmd}"
                        Executed="EditAppSettingsCmd_Executed"/>
        <CommandBinding Command="{StaticResource EditCommentCmd}"
                        CanExecute="CanEditComment" Executed="EditCommentCmd_Executed"/>
        <CommandBinding Command="{StaticResource EditDataBankCmd}"
                        CanExecute="CanEditDataBank" Executed="EditDataBankCmd_Executed"/>
        <CommandBinding Command="{StaticResource EditHeaderCommentCmd}"
                        CanExecute="IsProjectOpen" Executed="EditHeaderCommentCmd_Executed"/>
        <CommandBinding Command="{StaticResource EditLabelCmd}"
                        CanExecute="CanEditLabel" Executed="EditLabelCmd_Executed"/>
        <CommandBinding Command="{StaticResource EditLocalVariableTableCmd}"
                        CanExecute="CanEditLocalVariableTable" Executed="EditLocalVariableTableCmd_Executed"/>
        <CommandBinding Command="{StaticResource EditLongCommentCmd}"
                        CanExecute="CanEditLongComment" Executed="EditLongCommentCmd_Executed"/>
        <CommandBinding Command="{StaticResource EditNoteCmd}"
                        CanExecute="CanEditNote" Executed="EditNoteCmd_Executed"/>
        <CommandBinding Command="{StaticResource EditOperandCmd}"
                        CanExecute="CanEditOperand" Executed="EditOperandCmd_Executed"/>
        <CommandBinding Command="{StaticResource EditOperandTargetLabelCmd}"
                        CanExecute="CanEditOperandTargetLabel" Executed="EditOperandTargetLabelCmd_Executed"/>
        <CommandBinding Command="{StaticResource EditProjectPropertiesSymbolsCmd}"
                        CanExecute="IsProjectOpen" Executed="EditProjectPropertiesSymbolsCmd_Executed"/>
        <CommandBinding Command="{StaticResource EditProjectSymbolCmd}"
                        CanExecute="CanEditProjectSymbol" Executed="EditProjectSymbolCmd_Executed"/>
        <CommandBinding Command="{StaticResource EditStatusFlagsCmd}"
                        CanExecute="CanEditStatusFlags" Executed="EditStatusFlagsCmd_Executed"/>
        <CommandBinding Command="{StaticResource EditVisualizationSetCmd}"
                        CanExecute="CanEditVisualizationSet" Executed="EditVisualizationSetCmd_Executed"/>
        <CommandBinding Command="{StaticResource ExitCmd}"
                        Executed="ExitCmd_Executed"/>
        <CommandBinding Command="{StaticResource ExportCmd}"
                        CanExecute="IsProjectOpen" Executed="ExportCmd_Executed"/>
        <CommandBinding Command="Find"
                        CanExecute="IsProjectOpen" Executed="FindCmd_Executed"/>
        <CommandBinding Command="{StaticResource FindAllCmd}"
                        CanExecute="IsProjectOpen" Executed="FindAllCmd_Executed"/>
        <CommandBinding Command="{StaticResource FindNextCmd}"
                        CanExecute="IsProjectOpen" Executed="FindNextCmd_Executed"/>
        <CommandBinding Command="{StaticResource FindPreviousCmd}"
                        CanExecute="IsProjectOpen" Executed="FindPreviousCmd_Executed"/>
        <CommandBinding Command="{StaticResource FormatAsWordCmd}"
                        CanExecute="CanFormatAsWord" Executed="FormatAsWordCmd_Executed"/>
        <CommandBinding Command="{StaticResource FormatAddressTableCmd}"
                        CanExecute="CanFormatAddressTable" Executed="FormatAddressTableCmd_Executed"/>
        <CommandBinding Command="{StaticResource GenerateLabelsCmd}"
                        CanExecute="IsProjectOpen" Executed="GenerateLabelsCmd_Executed"/>
        <CommandBinding Command="{StaticResource GotoCmd}"
                        CanExecute="IsProjectOpen" Executed="GotoCmd_Executed"/>
        <CommandBinding Command="{StaticResource GotoLastChangeCmd}"
                        CanExecute="CanUndo" Executed="GotoLastChangeCmd_Executed"/>
        <CommandBinding Command="Help"
                        Executed="HelpCmd_Executed"/>
        <CommandBinding Command="{StaticResource TagAsCodeStartPointCmd}"
                        CanExecute="CanTagAsCodeStartPoint" Executed="TagAsCodeStartPointCmd_Executed"/>
        <CommandBinding Command="{StaticResource TagAsCodeStopPointCmd}"
                        CanExecute="CanTagAsCodeStopPoint" Executed="TagAsCodeStopPointCmd_Executed"/>
        <CommandBinding Command="{StaticResource TagAsInlineDataCmd}"
                        CanExecute="CanTagAsInlineData" Executed="TagAsInlineDataCmd_Executed"/>
        <CommandBinding Command="{StaticResource JumpToOperandCmd}"
                        CanExecute="CanJumpToOperand" Executed="JumpToOperandCmd_Executed"/>
        <CommandBinding Command="{StaticResource NavigateBackwardCmd}"
                        CanExecute="CanNavigateBackward" Executed="NavigateBackwardCmd_Executed"/>
        <CommandBinding Command="{StaticResource NavigateForwardCmd}"
                        CanExecute="CanNavigateForward" Executed="NavigateForwardCmd_Executed"/>
        <CommandBinding Command="{StaticResource NewProjectCmd}"
                        Executed="NewProjectCmd_Executed"/>
        <CommandBinding Command="{StaticResource OpenCmd}"
                        Executed="OpenCmd_Executed"/>
        <CommandBinding Command="Properties"
                        CanExecute="IsProjectOpen" Executed="EditProjectPropertiesCmd_Executed"/>
        <CommandBinding Command="{StaticResource RecentProjectCmd}" x:Name="recentProjectCmd"
                        Executed="RecentProjectCmd_Executed"/>
        <CommandBinding Command="{StaticResource RedoCmd}"
                        CanExecute="CanRedo" Executed="RedoCmd_Executed"/>
        <CommandBinding Command="{StaticResource ReloadExternalFilesCmd}"
                        CanExecute="IsProjectOpen" Executed="ReloadExternalFilesCmd_Executed"/>
        <CommandBinding Command="{StaticResource RemoveAnalyzerTagsCmd}"
                        CanExecute="CanRemoveAnalyzerTags" Executed="RemoveAnalyzerTagsCmd_Executed"/>
        <CommandBinding Command="{StaticResource RemoveFormattingCmd}"
                        CanExecute="CanRemoveFormatting" Executed="RemoveFormattingCmd_Executed"/>
        <CommandBinding Command="Save"
                        CanExecute="CanSaveProject" Executed="SaveCmd_Executed"/>
        <CommandBinding Command="SaveAs"
                        CanExecute="CanSaveProject" Executed="SaveAsCmd_Executed"/>
        <!-- ListView has a built-in Ctrl+A handler; this only fires when codeListView is not in focus -->
        <CommandBinding Command="{StaticResource SelectAllCmd}"
                        CanExecute="IsProjectOpen" Executed="SelectAllCmd_Executed"/>
        <CommandBinding Command="{StaticResource ShowFileHexDumpCmd}"
                        Executed="ShowFileHexDumpCmd_Executed"/>
        <CommandBinding Command="{StaticResource ShowHexDumpCmd}"
                        CanExecute="IsProjectOpen" Executed="ShowHexDumpCmd_Executed"/>
        <CommandBinding Command="{StaticResource SliceFilesCmd}"
                        Executed="SliceFilesCmd_Executed"/>
        <CommandBinding Command="{StaticResource ToggleApple2ScreenChartCmd}"
                        Executed="ToggleApple2ScreenChartCmd_Executed"/>
        <CommandBinding Command="{StaticResource ToggleAsciiChartCmd}"
                        Executed="ToggleAsciiChartCmd_Executed"/>
        <CommandBinding Command="{StaticResource ToggleDataScanCmd}"
                        CanExecute="IsProjectOpen" Executed="ToggleDataScanCmd_Executed"/>
        <CommandBinding Command="{StaticResource ToggleInstructionChartCmd}"
                        Executed="ToggleInstructionChartCmd_Executed"/>
        <CommandBinding Command="{StaticResource ToggleSingleByteFormatCmd}"
                        CanExecute="CanToggleSingleByteFormat" Executed="ToggleSingleByteFormatCmd_Executed"/>
        <CommandBinding Command="{StaticResource UndoCmd}"
                        CanExecute="CanUndo" Executed="UndoCmd_Executed"/>
        <CommandBinding Command="{StaticResource ViewAddressMapCmd}"
                        CanExecute="IsProjectOpen" Executed="ViewAddressMapCmd_Executed"/>

        <!-- must come after analyzer tag Ctrl+H Ctrl+C def -->
        <CommandBinding Command="Copy"
                        CanExecute="IsProjectOpen" Executed="CopyCmd_Executed"/>

        <CommandBinding Command="Refresh"
                        CanExecute="IsProjectOpen" Executed="Debug_RefreshCmd_Executed"/>
        <CommandBinding Command="{StaticResource Debug_ApplesoftToHtmlCmd}"
                        Executed="Debug_ApplesoftToHtmlCmd_Executed"/>
        <CommandBinding Command="{StaticResource Debug_ApplyEditCommandsCmd}"
                        CanExecute="IsProjectOpen" Executed="Debug_ApplyEditCommandsCmd_Executed"/>
        <CommandBinding Command="{StaticResource Debug_ApplyExternalSymbolsCmd}"
                        CanExecute="IsProjectOpen" Executed="Debug_ApplyExternalSymbolsCmd_Executed"/>
        <CommandBinding Command="{StaticResource Debug_ExportEditCommandsCmd}"
                        CanExecute="IsProjectOpen" Executed="Debug_ExportEditCommandsCmd_Executed"/>
        <CommandBinding Command="{StaticResource Debug_ExtensionScriptInfoCmd}"
                        CanExecute="IsProjectOpen" Executed="Debug_ExtensionScriptInfoCmd_Executed"/>
        <CommandBinding Command="{StaticResource Debug_RebootSecuritySandboxCmd}"
                        CanExecute="IsProjectOpen" Executed="Debug_RebootSecuritySandboxCmd_Executed"/>
        <CommandBinding Command="{StaticResource Debug_ShowAnalysisTimersCmd}"
                        CanExecute="IsProjectOpen" Executed="Debug_ShowAnalysisTimersCmd_Executed"/>
        <CommandBinding Command="{StaticResource Debug_ShowAnalyzerOutputCmd}"
                        CanExecute="IsProjectOpen" Executed="Debug_ShowAnalyzerOutputCmd_Executed"/>
        <CommandBinding Command="{StaticResource Debug_ShowUndoRedoHistoryCmd}"
                        CanExecute="IsProjectOpen" Executed="Debug_ShowUndoRedoHistoryCmd_Executed"/>
        <CommandBinding Command="{StaticResource Debug_ToggleCommentRulersCmd}"
                        Executed="Debug_ToggleCommentRulersCmd_Executed"/>
        <CommandBinding Command="{StaticResource Debug_ToggleKeepAliveHackCmd}"
                        Executed="Debug_ToggleKeepAliveHackCmd_Executed"/>
        <CommandBinding Command="{StaticResource Debug_ToggleSecuritySandboxCmd}"
                        Executed="Debug_ToggleSecuritySandboxCmd_Executed"/>
    </Window.CommandBindings>
    
    <DockPanel>
        <Menu Name="appMenu" DockPanel.Dock="Top">
            <MenuItem Header="_File">
                <MenuItem Command="{StaticResource NewProjectCmd}"/>
                <MenuItem Command="{StaticResource OpenCmd}"/>
                <MenuItem Command="Save"/>
                <MenuItem Command="SaveAs"/>
                <MenuItem Command="{StaticResource CloseCmd}"/>
                <Separator/>
                <MenuItem Name="recentProjectsMenu" Header="Recent Projects" SubmenuOpened="RecentProjectsMenu_SubmenuOpened">
                    <MenuItem Header="(none)"/>
                </MenuItem>
                <Separator/>
                <MenuItem Command="{StaticResource AssembleCmd}"/>
                <MenuItem Command="{StaticResource ExportCmd}"/>
                <MenuItem Command="{StaticResource GenerateLabelsCmd}"/>
                <Separator/>
                <MenuItem Command="{StaticResource ReloadExternalFilesCmd}"/>
                <Separator/>
                <MenuItem Command="{StaticResource ExitCmd}" InputGestureText="Alt+F4"/>
            </MenuItem>
            <MenuItem Header="_Edit" SubmenuOpened="EditMenu_SubmenuOpened">
                <MenuItem Command="{StaticResource UndoCmd}"/>
                <MenuItem Command="{StaticResource RedoCmd}"/>
                <Separator/>
                <MenuItem Command="Copy"/>
                <MenuItem Command="{StaticResource SelectAllCmd}"/>
                <Separator/>
                <MenuItem Command="{StaticResource EditHeaderCommentCmd}"/>
                <MenuItem Command="Properties" Header="Project Properties..."/>
                <!-- IsChecked is set when the menu is opened -->
                <MenuItem Name="toggleDataScanMenuItem"
                          Command="{StaticResource ToggleDataScanCmd}" IsCheckable="True"/>
                <Separator/>
                <MenuItem Command="{StaticResource EditAppSettingsCmd}"/>
            </MenuItem>
            <MenuItem Header="_Navigate">
                <MenuItem Command="{StaticResource NavigateForwardCmd}"/>
                <MenuItem Command="{StaticResource NavigateBackwardCmd}"/>
                <MenuItem Command="{StaticResource GotoCmd}"/>
                <MenuItem Command="{StaticResource GotoLastChangeCmd}"/>
                <MenuItem Command="{StaticResource JumpToOperandCmd}"/>
                <Separator/>
                <MenuItem Command="Find"/>
                <MenuItem Command="{StaticResource FindNextCmd}"/>
                <MenuItem Command="{StaticResource FindPreviousCmd}"/>
                <MenuItem Command="{StaticResource FindAllCmd}"/>
                <Separator/>
                <MenuItem Command="{StaticResource ViewAddressMapCmd}"/>
            </MenuItem>
            <MenuItem Name="actionsMenu" Header="_Actions">
                <MenuItem Command="{StaticResource EditOperandCmd}"/>
                <MenuItem Command="{StaticResource EditLabelCmd}"/>
                <MenuItem Command="{StaticResource EditCommentCmd}" InputGestureText="Ctrl+;"/>
                <MenuItem Command="{StaticResource EditLongCommentCmd}"/>
                <MenuItem Command="{StaticResource EditNoteCmd}"/>
                <MenuItem Command="{StaticResource EditOperandTargetLabelCmd}"/>
                <MenuItem Command="{StaticResource EditAddressCmd}"/>
                <MenuItem Command="{StaticResource EditStatusFlagsCmd}"/>
                <MenuItem Command="{StaticResource EditDataBankCmd}"/>
                <MenuItem Command="{StaticResource EditProjectSymbolCmd}"/>
                <MenuItem Command="{StaticResource CreateLocalVariableTableCmd}"/>
                <MenuItem Command="{StaticResource EditLocalVariableTableCmd}"/>
                <MenuItem Command="{StaticResource EditVisualizationSetCmd}"/>
                <Separator/>
                <MenuItem Command="{StaticResource TagAsCodeStartPointCmd}" InputGestureText="Ctrl+H, Ctrl+C"/>
                <MenuItem Command="{StaticResource TagAsCodeStopPointCmd}" InputGestureText="Ctrl+H, Ctrl+D"/>
                <MenuItem Command="{StaticResource TagAsInlineDataCmd}" InputGestureText="Ctrl+H, Ctrl+I"/>
                <MenuItem Command="{StaticResource RemoveAnalyzerTagsCmd}" InputGestureText="Ctrl+H, Ctrl+R"/>
                <Separator/>
                <MenuItem Command="{StaticResource FormatAddressTableCmd}"/>
                <MenuItem Command="{StaticResource ToggleSingleByteFormatCmd}"/>
                <MenuItem Command="{StaticResource FormatAsWordCmd}"/>
                <MenuItem Command="{StaticResource RemoveFormattingCmd}"/>
                <MenuItem Command="{StaticResource DeleteMlcCmd}"/>
                <Separator/>
                <MenuItem Command="{StaticResource ShowHexDumpCmd}"/>
            </MenuItem>
            <MenuItem Header="_Tools" SubmenuOpened="ToolsMenu_SubmenuOpened">
                <MenuItem Name="toggleInstructionChartMenuItem"
                          Command="{StaticResource ToggleInstructionChartCmd}" IsCheckable="True"/>
                <MenuItem Name="toggleAsciiChartMenuItem"
                          Command="{StaticResource ToggleAsciiChartCmd}" IsCheckable="True"/>
                <MenuItem Name="toggleApple2ScreenChartMenuItem"
                          Command="{StaticResource ToggleApple2ScreenChartCmd}" IsCheckable="True"/>
                <Separator/>
                <MenuItem Command="{StaticResource ShowFileHexDumpCmd}"/>
                <MenuItem Command="{StaticResource ConcatenateFilesCmd}"/>
                <MenuItem Command="{StaticResource SliceFilesCmd}"/>
                <MenuItem Command="{StaticResource ConvertOmfCmd}"/>
            </MenuItem>
            <MenuItem Header="_Help">
                <MenuItem Command="Help"/>
                <MenuItem Command="{StaticResource AboutCmd}"/>
            </MenuItem>
            <MenuItem Header="_DEBUG" Name="DebugMenu" SubmenuOpened="DebugMenu_SubmenuOpened"
                      Visibility="{Binding ShowDebugMenu, Converter={StaticResource BoolToVis}}">
                <MenuItem Command="Refresh" Header="Re-analyze"/>
                <MenuItem Command="{StaticResource Debug_SourceGenerationTestsCmd}"/>
                <Separator/>
                <MenuItem Name="debugAnalyzerOutputMenuItem"
                          Command="{StaticResource Debug_ShowAnalyzerOutputCmd}" IsCheckable="True"/>
                <MenuItem Name="debugAnalysisTimersMenuItem"
                          Command="{StaticResource Debug_ShowAnalysisTimersCmd}" IsCheckable="True"/>
                <MenuItem Name ="debugUndoRedoHistoryMenuItem"
                          Command="{StaticResource Debug_ShowUndoRedoHistoryCmd}" IsCheckable="True"/>
                <MenuItem Command="{StaticResource Debug_ExtensionScriptInfoCmd}"/>
                <Separator/>
                <MenuItem Name="debugCommentRulersMenuItem"
                          Command="{StaticResource Debug_ToggleCommentRulersCmd}" IsCheckable="True"/>
                <Separator/>
                <MenuItem Name="debugSecuritySandboxMenuItem"
                          Command="{StaticResource Debug_ToggleSecuritySandboxCmd}" IsCheckable="True"/>
                <MenuItem Name="debugKeepAliveHackMenuItem"
                          Command="{StaticResource Debug_ToggleKeepAliveHackCmd}" IsCheckable="True"/>
                <MenuItem Command="{StaticResource Debug_RebootSecuritySandboxCmd}"/>
                <Separator/>
                <MenuItem Command="{StaticResource Debug_ApplesoftToHtmlCmd}"/>
                <MenuItem Command="{StaticResource Debug_ExportEditCommandsCmd}"/>
                <MenuItem Command="{StaticResource Debug_ApplyEditCommandsCmd}"/>
                <MenuItem Command="{StaticResource Debug_ApplyExternalSymbolsCmd}"/>
            </MenuItem>
        </Menu>

        <ToolBarTray DockPanel.Dock="Top">
            <ToolBar RenderOptions.BitmapScalingMode="NearestNeighbor">
                <Button Command="{StaticResource NavigateBackwardCmd}"
                        ToolTip="Navigate backward (Alt+Left, Ctrl+Minus, or back button on mouse)">
                    <ContentControl Template="{StaticResource icon_StepBackwards}"/>
                </Button>
                <Button Command="{StaticResource NavigateForwardCmd}"
                        ToolTip="Navigate forward (Alt+Right or Ctrl+Shift+Minus)">
                    <ContentControl Template="{StaticResource icon_StepForward}"/>
                </Button>
                <Button Command="{StaticResource GotoLastChangeCmd}"
                        ToolTip="Go to Last Change">
                    <ContentControl Template="{StaticResource icon_DebugHistorySeekToFrame}"/>
                </Button>
                <Separator/>
                <Button Command="{StaticResource NewProjectCmd}" ToolTip="Create new project">
                    <ContentControl Template="{StaticResource icon_NewFile}"/>
                </Button>
                <Button Command="{StaticResource OpenCmd}" ToolTip="Open project">
                    <ContentControl Template="{StaticResource icon_OpenFile}"/>
                </Button>
                <Button Command="Save" ToolTip="Save project (Ctrl+S)">
                    <ContentControl Template="{StaticResource icon_SaveFile}"/>
                </Button>
                <Separator/>
                <Button Command="Copy" ToolTip="Copy to clipboard (Ctrl+C)">
                    <ContentControl Template="{StaticResource icon_CopyToClipboard}"/>
                </Button>
                <CheckBox IsChecked="{Binding DoShowCycleCounts}" ToolTip="Toggle display of cycle counts">
                    <ContentControl Template="{StaticResource icon_DomainType}"/>
                </CheckBox>
                <Separator/>
                <Button Command="Help" ToolTip="Help - open manual in browser (F1)">
                    <ContentControl Template="{StaticResource icon_F1Help}"/>
                </Button>
            </ToolBar>
        </ToolBarTray>

        <StatusBar Name="mainStatusBar" DockPanel.Dock="Bottom">
            <Grid Width="{Binding ActualWidth, RelativeSource={RelativeSource FindAncestor,
                        AncestorType={x:Type StatusBar}}}">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="{Binding StatusBarText, FallbackValue=Ready}"/>
                <TextBlock Grid.Column="1" HorizontalAlignment="Center"
                           Text="{Binding ByteCountText, FallbackValue=100KB: 30.0% code; 60.0% data; 10.0% junk}"/>
                <Button Grid.Column="2" Margin="4,0,20,0" Padding="4,0,4,0"
                        Content="{Binding MessageStatusText, FallbackValue=3 messages (1 warning/error)}"
                        Visibility="{Binding Path=CodeListVisibility}"
                        Click="MessageStatusButton_Click"/>
            </Grid>
        </StatusBar>

        <!-- Main part of the window.  Three side-by-side panels, only the middle of which changes
        size when the window is resized.  This needs to be the last thing defined in the
        DockPanel, so that LastChildFill will expand this to fill all available space. -->
        <Grid Name="triptychGrid" DockPanel.Dock="Top">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" MinWidth="100"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*" MinWidth="150"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*" MinWidth="100"/>
            </Grid.ColumnDefinitions>


            <GridSplitter Grid.Column="1" Width="4" HorizontalAlignment="Left"/>
            <GridSplitter Grid.Column="3" Width="4" HorizontalAlignment="Center"/>

            <Grid Name="leftPanel" Grid.Column="0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="2*" MinHeight="100"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*" MinHeight="100"/>
                </Grid.RowDefinitions>

                <GroupBox Grid.Row="0" Header="References">
                    <Grid>
                    <DataGrid Name="referencesGrid" IsReadOnly="True"
                              ItemsSource="{Binding ReferencesList}"
                              FontFamily="{StaticResource GeneralMonoFont}"
                              SnapsToDevicePixels="True"
                              GridLinesVisibility="Vertical"
                              VerticalGridLinesBrush="#FF7F7F7F"
                              AutoGenerateColumns="False"
                              HeadersVisibility="Column"
                              CanUserReorderColumns="False"
                              SelectionMode="Single"
                              MouseDoubleClick="ReferencesList_MouseDoubleClick">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Offset" Width="53" Binding="{Binding Offset}"/>
                            <DataGridTextColumn Header="Addr" Width="53" Binding="{Binding Addr}"/>
                            <DataGridTextColumn Header="Type" Width="119" Binding="{Binding Type}"/>
                        </DataGrid.Columns>
                    </DataGrid>
                    <Button Content="Copy Out" Width="70" Height="19" Margin="2"
                            HorizontalAlignment="Right" VerticalAlignment="Top"
                            IsEnabled="{Binding IsEnabledReferencesListCopyOut}"
                            Click="ReferencesListCopyOut_Click"/>
                    </Grid>
                </GroupBox>

                <GroupBox Grid.Row="2" Header="Notes">
                    <DataGrid Name="notesGrid"
                              ItemsSource="{Binding NotesList}"
                              IsReadOnly="True"
                              FontFamily="{StaticResource GeneralMonoFont}"
                              SnapsToDevicePixels="True"
                              GridLinesVisibility="Vertical"
                              VerticalGridLinesBrush="#FF7F7F7F"
                              AutoGenerateColumns="False"
                              HeadersVisibility="Column"
                              CanUserReorderColumns="False"
                              SelectionMode="Single"
                              MouseDoubleClick="NotesList_MouseDoubleClick">
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Offset" Width="53" Binding="{Binding Offset}"/>
                            <DataGridTextColumn Header="Note" Width="400" Binding="{Binding Note}">
                                <DataGridTextColumn.ElementStyle>
                                    <Style TargetType="{x:Type TextBlock}">
                                        <!-- The default highlight uses dark blue background with
                                        white text, but our highlight colors are meant to work
                                        with black text.  So override Foreground as well.  For
                                        non-highlighted entries we have to force (in code) the
                                        color to white to keep things consistent. -->
                                        <Setter Property="Background" Value="{Binding BackBrush}"/>
                                        <Setter Property="Foreground" Value="Black"/>
                                        <!--<Setter Property="Foreground"
                                                Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>-->
                                    </Style>
                                </DataGridTextColumn.ElementStyle>
                            </DataGridTextColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                </GroupBox>

                <GridSplitter Height="4" Grid.Row="1"
                              HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
            </Grid>

            <!-- Launch panel.  Either this or the code list panel will be visible. -->
            <Grid Grid.Column="2" Name="launchPanel" Visibility="{Binding Path=LaunchPanelVisibility}"
                  d:IsHidden="True">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>

                <StackPanel Grid.Row="0" Grid.ColumnSpan="2" Orientation="Horizontal">
                    <Image Source="/SourceGen;component/Res/Logo.png" Height="100"/>
                    <Grid Margin="8">
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Row="0" VerticalAlignment="Center"
                                   Text="6502bench SourceGen" FontSize="36"/>
                        <TextBlock Grid.Row="1" VerticalAlignment="Center"
                                   Text="{Binding ProgramVersionString, StringFormat={}Version {0},
                                       RelativeSource={RelativeSource FindAncestor, AncestorType=Window},
                                       FallbackValue=Version X.Y.Z-alpha1}"
                                   FontSize="24"/>
                    </Grid>
                </StackPanel>

                <!-- recents -->
                <StackPanel Grid.Column="0" Grid.Row="1" HorizontalAlignment="Left">
                    <Button Content="Start new project" Width="240" Height="50" Margin="10,30,10,10"
                            Command="{StaticResource NewProjectCmd}"/>
                    <Button Content="Open existing project" Width="240" Height="50" Margin="10"
                            Command="{StaticResource OpenCmd}"/>
                    <Button Width="240" Height="50" Margin="10" Visibility="{Binding RecentProjectVisibility1}"
                            ToolTip="{Binding RecentProjectPath1}" ToolTipService.InitialShowDelay="750"
                            Command="{DynamicResource RecentProjectCmd}" CommandParameter="0">
                        <Button.Content>
                            <StackPanel>
                                <TextBlock HorizontalAlignment="Center">Recent project #1</TextBlock>
                                <TextBlock Text="{Binding RecentProjectName1, FallbackValue=RECENT 1}" HorizontalAlignment="Center"/>
                            </StackPanel>
                        </Button.Content>
                    </Button>
                    <Button Width="240" Height="50" Margin="10" Visibility="{Binding RecentProjectVisibility2}"
                            ToolTip="{Binding RecentProjectPath2}" ToolTipService.InitialShowDelay="750"
                            Command="{DynamicResource RecentProjectCmd}" CommandParameter="1">
                        <Button.Content>
                            <StackPanel>
                                <TextBlock HorizontalAlignment="Center">Recent project #2</TextBlock>
                                <TextBlock Text="{Binding RecentProjectName2, FallbackValue=RECENT 1}" HorizontalAlignment="Center"/>
                            </StackPanel>
                        </Button.Content>
                    </Button>
                </StackPanel>

                <!-- daily tips -->
                <GroupBox Grid.Column="1" Grid.Row="1" Width="300" MinHeight="210" Padding="2,0" Margin="20,20,0,0"
                          VerticalAlignment="Top" Visibility="{Binding DailyTipVisibility}"
                          Header="Tip of the Day">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        
                        <TextBlock Grid.Row="0" TextWrapping="Wrap" VerticalAlignment="Center"
                                   Text="{Binding DailyTipText, FallbackValue=Tip text here!}"/>
                        <Image Grid.Row="1" Margin="0,4,0,0"
                               Source="{Binding DailyTipImage}"
                               RenderOptions.BitmapScalingMode="NearestNeighbor" Stretch="None"/>

                        <Grid Grid.Row="2" Margin="0,10,0,0">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Button Grid.Column="0" Width="70" HorizontalAlignment="Left"
                                    Content="Previous"
                                    IsEnabled="{Binding IsEnabledDailyTipPrev}"
                                    Click="DailyTipPrevious_Click"/>
                            <TextBlock Grid.Column="1" HorizontalAlignment="Center" Margin="0,2,0,0"
                                       Text="{Binding DailyTipPosStr, FallbackValue=?/?}"/>
                            <Button Grid.Column="2" Width="70" HorizontalAlignment="Right"
                                    Content="Next"
                                    IsEnabled="{Binding IsEnabledDailyTipNext}"
                                    Click="DailyTipNext_Click"/>
                        </Grid>
                        
                    </Grid>
                </GroupBox>
            </Grid>

            <!-- Code list panel.  Either this or the Launch panel will be visible. -->
            <Grid Grid.Column="2" Name="codeListGrid" Visibility="{Binding Path=CodeListVisibility}"
                  d:IsHidden="False">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <ListView Name="codeListView"
                          Style="{StaticResource codeListStyle}"
                          FontFamily="{StaticResource GeneralMonoFont}"
                          VirtualizingStackPanel.VirtualizationMode="Recycling"
                          ItemContainerStyle="{StaticResource codeListItemStyle}"
                          SelectionChanged="CodeListView_SelectionChanged"
                          MouseDoubleClick="CodeListView_MouseDoubleClick">
                    <ListView.Resources>
                        <Style TargetType="TextBlock">
                            <Setter Property="TextTrimming" Value="CharacterEllipsis"/>
                            <!-- <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=Text }" /> -->
                        </Style>
                    </ListView.Resources>
                    <ListView.View>
                        <GridView AllowsColumnReorder="False">
                            <GridViewColumn Header="Offset" Width="60"
                                            DisplayMemberBinding="{Binding Offset}"/>
                            <GridViewColumn Header="Addr" Width="60"
                                            CellTemplate="{StaticResource addrHighlightTemplate}"/>
                            <GridViewColumn Header="Bytes" Width="93"
                                            DisplayMemberBinding="{Binding Bytes}"/>
                            <GridViewColumn Header="Flags" Width="80"
                                            CellTemplate="{StaticResource flagsHighlightTemplate}"/>
                            <GridViewColumn Header="Attr" Width="54"
                                            DisplayMemberBinding="{Binding Attr}"/>
                            <GridViewColumn Header="Label" Width="73"
                                            CellTemplate="{StaticResource labelHighlightTemplate}"/>
                            <GridViewColumn Header="Opcode" Width="60"
                                            DisplayMemberBinding="{Binding Opcode}"/>
                            <GridViewColumn Header="Operand" Width="100"
                                            CellTemplate="{StaticResource operandHighlightTemplate}"/>
                            <GridViewColumn Header="Comment" Width="344"
                                            DisplayMemberBinding="{Binding Comment}"/>
                        </GridView>
                    </ListView.View>

                    <ListView.ContextMenu>
                        <!-- this is populated as a clone of the Actions menu during init -->
                        <ContextMenu/>
                    </ListView.ContextMenu>
                </ListView>

                <!-- A GridSplitter would be nice to make the height adjustable, but I had
                trouble making everything disappear cleanly, particularly w.r.t. the splitter
                working correctly after hide + re-show.  (This might have been due to issue #52...
                should revisit this someday.)  See
                https://stackoverflow.com/q/2502178/294248 for suggestions. -->
                <!--<GridSplitter Name="messageLogSplitter" Grid.Row="1" Height="4"
                              HorizontalAlignment="Stretch" VerticalAlignment="Center"
                              Visibility="{Binding MessageListVisibility}"/>-->

                <DockPanel Grid.Row="1" Visibility="{Binding MessageListVisibility}">
                    <Button DockPanel.Dock="Left" Content="Hide" Width="50" Margin="4,0,4,0"
                            VerticalAlignment="Bottom"
                            Click="HideMessageList_Click">
                        <Button.LayoutTransform>
                            <RotateTransform Angle="270"/>
                        </Button.LayoutTransform>
                    </Button>

                    <DataGrid DockPanel.Dock="Top" Name="messageGrid"
                              Height="100"
                              IsReadOnly="True"
                              ItemsSource="{Binding FormattedMessages}"
                              FontFamily="{StaticResource GeneralMonoFont}"
                              SnapsToDevicePixels="True"
                              GridLinesVisibility="Vertical"
                              VerticalGridLinesBrush="#FF7F7F7F"
                              AutoGenerateColumns="False"
                              HeadersVisibility="Column"
                              CanUserReorderColumns="False"
                              SelectionMode="Single"
                              VerticalScrollBarVisibility="Visible"
                              MouseDoubleClick="MessageGrid_MouseDoubleClick">
                        <!-- should probably add ellipsis: https://stackoverflow.com/a/12880111/294248 -->
                        <DataGrid.Columns>
                            <DataGridTextColumn Header="Severity" Width="64" Binding="{Binding Severity}"/>
                            <DataGridTextColumn Header="Offset" Width="53" Binding="{Binding Offset}"/>
                            <DataGridTextColumn Header="Type" Width="160" Binding="{Binding Type}"/>
                            <DataGridTextColumn Header="Context" Width="380" Binding="{Binding Context}"/>
                            <DataGridTextColumn Header="Resolution" Width="250" Binding="{Binding Resolution}"/>
                        </DataGrid.Columns>
                    </DataGrid>
                </DockPanel>
            </Grid>

            <Grid Name="rightPanel" Grid.Column="4">
                <Grid.RowDefinitions>
                    <RowDefinition Height="2*" MinHeight="100"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*" MinHeight="50"/>
                </Grid.RowDefinitions>

                <!-- symbols panel -->
                <GroupBox Grid.Row="0" Header="Symbols">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>
                        
                        <WrapPanel Grid.Row="0">
                            <ToggleButton Content="User" Width="40" Margin="2,2"
                                          IsChecked="{Binding SymFilterUserLabels}"/>
                            <ToggleButton Content="NonU" Width="40" Margin="2,2"
                                          IsChecked="{Binding SymFilterNonUniqueLabels}"/>
                            <ToggleButton Content="Proj" Width="40" Margin="2,2"
                                          IsChecked="{Binding SymFilterProjectSymbols}"/>
                            <ToggleButton Content="Plat" Width="40" Margin="2,2"
                                          IsChecked="{Binding SymFilterPlatformSymbols}"/>
                            <ToggleButton Content="PreL" Width="40" Margin="2,2"
                                          IsChecked="{Binding SymFilterAddrPreLabels}"/>
                            <ToggleButton Content="Auto" Width="40" Margin="2,2"
                                          IsChecked="{Binding SymFilterAutoLabels}"/>
                            <ToggleButton Content="Addr" Width="40" Margin="2,2"
                                          IsChecked="{Binding SymFilterAddresses}"/>
                            <ToggleButton Content="Cnst" Width="40" Margin="2,2"
                                          IsChecked="{Binding SymFilterConstants}"/>
                        </WrapPanel>

                        <DataGrid Grid.Row="1" Name="symbolsGrid"
                                  IsReadOnly="True"
                                  ItemsSource="{Binding Source={StaticResource SymbolTableSource}}"
                                  FontFamily="{StaticResource GeneralMonoFont}"
                                  SnapsToDevicePixels="True"
                                  GridLinesVisibility="Vertical"
                                  VerticalGridLinesBrush="#FF7F7F7F"
                                  AutoGenerateColumns="False"
                                  HeadersVisibility="Column"
                                  CanUserReorderColumns="False"
                                  SelectionMode="Single"
                                  Sorting="SymbolsList_Sorting"
                                  MouseDoubleClick="SymbolsList_MouseDoubleClick">
                            <DataGrid.Columns>
                                <DataGridTextColumn Header="Type" Width="36" Binding="{Binding Type}"/>
                                <DataGridTextColumn Header="Value" Width="66" Binding="{Binding Value}"/>
                                <DataGridTextColumn Header="Name" Width="120" Binding="{Binding Name}"/>
                            </DataGrid.Columns>
                        </DataGrid>
                    </Grid>
                </GroupBox>

                <!-- info panel -->
                <GroupBox Grid.Row="2" Header="Info">
                    <ScrollViewer>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>

                            <TextBlock Grid.Row="0" TextWrapping="Wrap"
                                       Text="{Binding InfoLineDescrText, FallbackValue=Line #1234: N bytes of data}"/>
                            <TextBlock Grid.Row="1" TextWrapping="Wrap" Foreground="DarkGray"
                                       Text="{Binding InfoOffsetText, FallbackValue=[offset: +123456]}"
                                       Visibility="{Binding InfoShowDebug, Converter={StaticResource BoolToVis}}"/>
                            <TextBlock Grid.Row="2" TextWrapping="Wrap"
                                       Text="{Binding InfoLabelDescrText, FallbackValue=Label FUBAR (local)}"/>

                            <StackPanel Grid.Row="3"
                                        Visibility="{Binding InfoFormatShowDashes, Converter={StaticResource BoolToVis}}">
                                <!-- For some reason putting the Visibility on the Border causes the
                                border to disappear even when it's supposed to be Visible.  So I'm
                                using a panel to contain it. -->
                                <Border BorderThickness="1" Padding="1" Margin="0,2">
                                    <!-- https://stackoverflow.com/a/47300149/294248 -->
                                    <Border.BorderBrush>
                                        <VisualBrush>
                                            <VisualBrush.Visual>
                                                <Rectangle StrokeDashArray="4 2" Stroke="{Binding InfoFormatBoxBrush}" StrokeThickness="1"
                                                  Width="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualWidth}"
                                                  Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, Path=ActualHeight}"/>
                                            </VisualBrush.Visual>
                                        </VisualBrush>
                                    </Border.BorderBrush>
                                    <TextBlock TextWrapping="Wrap"
                                               Text="{Binding InfoFormatText, FallbackValue=Format: good stuff}"/>
                                </Border>
                            </StackPanel>
                            <Border Grid.Row="3" BorderThickness="1" Padding="1" Margin="0,2"
                                    BorderBrush="{Binding InfoFormatBoxBrush}"
                                    Visibility="{Binding InfoFormatShowSolid, Converter={StaticResource BoolToVis}}">
                                <TextBlock TextWrapping="Wrap" Text="{Binding InfoFormatText}"/>
                            </Border>

                            <TextBox Grid.Row="4" Text="{Binding InfoPanelDetail1}" IsReadOnly="True"
                                     TextWrapping="Wrap" BorderThickness="0"/>

                            <!--<TextBox Grid.Row="5" Text="{Binding InfoPanelMonoContents}" IsReadOnly="True"
                                     FontFamily="{StaticResource GeneralMonoFont}"
                                     TextWrapping="Wrap" BorderThickness="0"/>-->
                        </Grid>
                    </ScrollViewer>
                </GroupBox>
                
                <GridSplitter Height="4" Grid.Row="1"
                              HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
            </Grid>
        </Grid>
    </DockPanel>
</Window>
