<?xml version="1.0" encoding="utf-8"?>
<Window x:Class="QC.QMine.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:QC.QMine" xmlns:conv="clr-namespace:QC.QMine.QMineInterface;assembly=QMineInterface" Height="350" Width="525" WindowState="Maximized" Icon="/QMineUI;component/Images/App.png" DataContext="{Binding RelativeSource={RelativeSource Self}}" Title="{Binding MainWindowTitle}" Loaded="Window_Loaded" Closing="MainWindow_Closing">
  <FrameworkElement.Resources>
    <ResourceDictionary>
      <conv:BoolToVisibilityConverter x:Key="boolToVisibilityConverter" />
    </ResourceDictionary>
  </FrameworkElement.Resources>
  <UIElement.CommandBindings>
    <CommandBinding Command="{x:Static local:CustomRoutedCommands.RunDataMinerCommand}" Executed="CommandBinding_RunReport" />
    <CommandBinding Command="{x:Static local:CustomRoutedCommands.RunSelectedDataMinerCommand}" Executed="CommandBinding_RunSelectedReport" />
    <CommandBinding Command="{x:Static local:CustomRoutedCommands.OpenPluginSettingsCommand}" Executed="CommandBinding_OpenPluginSettings" />
    <CommandBinding Command="{x:Static local:CustomRoutedCommands.ClosePluginSettingsCommand}" Executed="CommandBinding_ClosePluginSettings" />
    <CommandBinding Command="{x:Static local:CustomRoutedCommands.NewPluginSettingsCommand}" Executed="CommandBinding_NewPluginSettings" />
    <CommandBinding Command="{x:Static local:CustomRoutedCommands.SavePluginSettingsCommand}" Executed="CommandBinding_SavePluginSettings" CanExecute="SavePluginSettingsCommand_CanExecute" />
    <CommandBinding Command="{x:Static local:CustomRoutedCommands.SaveAsPluginSettingsCommand}" Executed="CommandBinding_SaveAsPluginSettings" />
    <CommandBinding Command="{x:Static local:CustomRoutedCommands.ResetPluginSettingsCommand}" Executed="CommandBinding_ResetPluginSettings" />
    <CommandBinding Command="{x:Static local:CustomRoutedCommands.ChangeDatabaseCommand}" Executed="CommandBinding_ChangeDatabase" />
  </UIElement.CommandBindings>
  <Grid Name="mainWindowGrid">
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
      <RowDefinition Name="queryPluginRowDefinition" Height="*" />
      <RowDefinition Name="pluginGridSplitterRowDefinition" Height="3" />
      <RowDefinition Name="resultPluginRowDefinition" Height="*" />
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Menu Grid.Row="0">
      <MenuItem Header="File">
        <MenuItem Header="Create New plugin settings" Command="{x:Static local:CustomRoutedCommands.NewPluginSettingsCommand}">
          <MenuItem.Icon>
            <Image Source="/QMineUI;component/Images/New.png" Width="20" Height="20" />
          </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="Open existing plugin settings" Command="{x:Static local:CustomRoutedCommands.OpenPluginSettingsCommand}">
          <MenuItem.Icon>
            <Image Source="/QMineUI;component/Images/open.png" Width="20" Height="20" />
          </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="Save plugin settings" Command="{x:Static local:CustomRoutedCommands.SavePluginSettingsCommand}">
          <MenuItem.Icon>
            <Image Source="/QMineUI;component/Images/save.png" Width="20" Height="20" />
          </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="Save plugin settings As" Command="{x:Static local:CustomRoutedCommands.SaveAsPluginSettingsCommand}">
          <MenuItem.Icon>
            <Image Source="/QMineUI;component/Images/SaveAs.png" Width="20" Height="20" />
          </MenuItem.Icon>
        </MenuItem>
        <MenuItem Header="Reset plugin settings" Command="{x:Static local:CustomRoutedCommands.ResetPluginSettingsCommand}">
          <MenuItem.Icon>
            <Image Source="/QMineUI;component/Images/reset.png" Width="20" Height="20" />
          </MenuItem.Icon>
        </MenuItem>
        <Separator />
        <MenuItem Name="menuItemRecentFile" Header="Recently opened qmine settings" ItemsSource="{Binding RecentQMineSettingsFilePathCollection}">
          <ItemsControl.ItemContainerStyle>
            <Style>
              <Setter Property="HeaderedItemsControl.Header" Value="{Binding FilePath}" />
              <Setter Property="FrameworkElement.ToolTip" Value="{Binding FilePath}" />
              <Setter Property="MenuItem.Command" Value="{x:Static local:CustomRoutedCommands.OpenPluginSettingsCommand}" />
              <Setter Property="MenuItem.CommandParameter" Value="{Binding FilePath}" />
              <Setter Property="MenuItem.CommandTarget" Value="{Binding ElementName=mainWindowGrid}" />
              <Setter Property="MenuItem.InputGestureText" Value=" " />
            </Style>
          </ItemsControl.ItemContainerStyle>
        </MenuItem>
        <Separator />
        <MenuItem Header="Exit" Click="Exit_Click">
          <MenuItem.Icon>
            <Image Source="/QMineUI;component/Images/exit.png" Width="20" Height="20" />
          </MenuItem.Icon>
        </MenuItem>
      </MenuItem>
      <MenuItem Header="Report">
        <MenuItem Header="Generate report with current result plugin" Command="{x:Static local:CustomRoutedCommands.RunDataMinerCommand}">
          <MenuItem.Icon>
            <Image Source="/QMineUI;component/Images/run.png" Width="20" Height="20" />
          </MenuItem.Icon>
        </MenuItem>
      </MenuItem>
      <MenuItem Header="Tools">
        <MenuItem Header="Kill">
          <MenuItem Header="All Excel, PowerPoint and Dataminer Processes" Click="KillAll_Click" />
          <Separator />
          <MenuItem Header="All Excel Processes" Click="KillExcel_Click" />
          <MenuItem Header="All PowerPoint Processes" Click="KillPPT_Click" />
          <MenuItem Header="All DataMiner Processes" Click="KillDataMiner_Click" />
        </MenuItem>
        <Separator />
        <MenuItem Header="Change Database" Command="{x:Static local:CustomRoutedCommands.ChangeDatabaseCommand}" Visibility="{Binding Source={x:Static Application.Current}, Path=SecurityConfig.EnableFullQMine, Converter={StaticResource boolToVisibilityConverter}}">
          <MenuItem.Icon>
            <Image Source="/QMineUI;component/Images/database.png" Width="20" Height="20" />
          </MenuItem.Icon>
        </MenuItem>
      </MenuItem>
      <MenuItem Header="About">
        <MenuItem Header="QMine help" Visibility="{Binding Source={x:Static Application.Current}, Path=SecurityConfig.EnableFullQMine, Converter={StaticResource boolToVisibilityConverter}}" Click="Help_Click" />
        <MenuItem Header="QMine Command Line help" Visibility="{Binding Source={x:Static Application.Current}, Path=SecurityConfig.EnableFullQMine, Converter={StaticResource boolToVisibilityConverter}}" Click="CommandLineHelp_Click" />
        <MenuItem Header="Submit a bug" Visibility="{Binding Source={x:Static Application.Current}, Path=SecurityConfig.EnableFullQMine, Converter={StaticResource boolToVisibilityConverter}}" Click="Bug_Click" />
        <MenuItem Header="About" Click="About_Click" />
      </MenuItem>
    </Menu>
    <ToolBar Grid.Row="1">
      <Button Command="{x:Static local:CustomRoutedCommands.NewPluginSettingsCommand}" ToolTip="Create new plugin settings">
        <Image Source="/QMineUI;component/Images/New.png" Width="20" Height="20" />
      </Button>
      <Button Command="{x:Static local:CustomRoutedCommands.OpenPluginSettingsCommand}" ToolTip="Open existing plugin settings">
        <Image Source="/QMineUI;component/Images/open.png" Width="20" Height="20" />
      </Button>
      <Button Command="{x:Static local:CustomRoutedCommands.SavePluginSettingsCommand}" ToolTip="Save current plugin settings">
        <Image Source="/QMineUI;component/Images/save.png" Width="20" Height="20" />
      </Button>
      <Button Command="{x:Static local:CustomRoutedCommands.SaveAsPluginSettingsCommand}" ToolTip="Save current plugin settings to a new file">
        <Image Source="/QMineUI;component/Images/SaveAs.png" Width="20" Height="20" />
      </Button>
      <Separator />
      <Button Command="{x:Static local:CustomRoutedCommands.ResetPluginSettingsCommand}" ToolTip="Reset plugin settings to default settings">
        <Image Source="/QMineUI;component/Images/reset.png" Width="20" Height="20" />
      </Button>
      <Separator />
      <Button Command="{x:Static local:CustomRoutedCommands.RunDataMinerCommand}" ToolTip="Generate report with current result plugin (F5)">
        <Image Source="/QMineUI;component/Images/run.png" Width="20" Height="20" />
      </Button>
      <Separator />
      <Button Command="{x:Static local:CustomRoutedCommands.ChangeDatabaseCommand}" ToolTip="Change Database" Visibility="{Binding Source={x:Static Application.Current}, Path=SecurityConfig.EnableFullQMine, Converter={StaticResource boolToVisibilityConverter}}">
        <Image Source="/QMineUI;component/Images/database.png" Width="20" Height="20" />
      </Button>
    </ToolBar>
    <DockPanel Grid.Row="2" Margin="0,2,0,2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" LastChildFill="True">
      <Border BorderThickness="2" CornerRadius="3" DockPanel.Dock="Top" Background="#FFF5F5DC">
        <DockPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
          <TextBlock DockPanel.Dock="Left" Text="Query Plugins" FontWeight="Bold" FontStyle="Italic" />
          <Button ToolTip="Maximize Query plugins" DockPanel.Dock="Right" MaxWidth="30" HorizontalAlignment="Right" Margin="2,0,2,0" Click="QueryPluginMaximize_Click">
            <Image Source="/QMineUI;component/Images/Maximize.png" Width="10" Height="10" />
          </Button>
          <Button ToolTip="Restore Query plugins" DockPanel.Dock="Right" MaxWidth="50" HorizontalAlignment="Right" Margin="2,0,2,0" Click="QueryPluginRestore_Click">
            <Image Source="/QMineUI;component/Images/Restore.png" Width="10" Height="10" />
          </Button>
          <Button ToolTip="Minimize Query plugins" DockPanel.Dock="Right" MaxWidth="30" HorizontalAlignment="Right" Margin="2,0,2,0" Click="QueryPluginMinimize_Click">
            <Image Source="/QMineUI;component/Images/Minimize.png" Width="10" Height="10" />
          </Button>
        </DockPanel>
      </Border>
      <TabControl Name="queryPluginTabControl" DockPanel.Dock="Bottom" ItemsSource="{Binding QueryPluginList}">
        <ItemsControl.ItemContainerStyle>
          <Style TargetType="{x:Type TabItem}">
            <Setter Property="TabItem.IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
          </Style>
        </ItemsControl.ItemContainerStyle>
        <ItemsControl.ItemTemplate>
          <DataTemplate>
            <TextBlock Text="{Binding PluginName}" />
          </DataTemplate>
        </ItemsControl.ItemTemplate>
        <TabControl.ContentTemplate>
          <DataTemplate>
            <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
              <ContentPresenter Content="{Binding UserInterface}" />
            </ScrollViewer>
          </DataTemplate>
        </TabControl.ContentTemplate>
      </TabControl>
    </DockPanel>
    <GridSplitter Grid.Row="3" Height="3" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ShowsPreview="True" />
    <DockPanel Grid.Row="4" Margin="0,2,0,2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" LastChildFill="True">
      <Border BorderThickness="2" CornerRadius="3" DockPanel.Dock="Top" Background="#FFF5F5DC">
        <DockPanel VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
          <TextBlock DockPanel.Dock="Left" Text="Result Plugins" FontWeight="Bold" FontStyle="Italic" />
          <Button ToolTip="Maximize Result plugins" DockPanel.Dock="Right" MaxWidth="30" HorizontalAlignment="Right" Margin="2,0,2,0" Click="ResultPluginMaximize_Click">
            <Image Source="/QMineUI;component/Images/Maximize.png" Width="10" Height="10" />
          </Button>
          <Button ToolTip="Restore Result plugins" DockPanel.Dock="Right" MaxWidth="50" HorizontalAlignment="Right" Margin="2,0,2,0" Click="ResultPluginRestore_Click">
            <Image Source="/QMineUI;component/Images/Restore.png" Width="10" Height="10" />
          </Button>
          <Button ToolTip="Minimize Result plugins" DockPanel.Dock="Right" MaxWidth="30" HorizontalAlignment="Right" Margin="2,0,2,0" Click="ResultPluginMinize_Click">
            <Image Source="/QMineUI;component/Images/Minimize.png" Width="10" Height="10" />
          </Button>
        </DockPanel>
      </Border>
      <TabControl Name="resultPluginTabControl" DockPanel.Dock="Bottom" ItemsSource="{Binding ResultsPluginList}">
        <ItemsControl.ItemContainerStyle>
          <Style TargetType="{x:Type TabItem}">
            <Setter Property="TabItem.IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
          </Style>
        </ItemsControl.ItemContainerStyle>
        <ItemsControl.ItemTemplate>
          <DataTemplate>
            <StackPanel Orientation="Horizontal">
              <TextBlock Text="{Binding PluginName}" />
              <RadioButton GroupName="ProcessMessage" Margin="3" IsChecked="{Binding CanProcessMessages, Mode=TwoWay}" />
            </StackPanel>
          </DataTemplate>
        </ItemsControl.ItemTemplate>
        <TabControl.ContentTemplate>
          <DataTemplate>
            <ContentPresenter Content="{Binding UserInterface}" />
          </DataTemplate>
        </TabControl.ContentTemplate>
      </TabControl>
    </DockPanel>
    <StatusBar Grid.Row="5">
      <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
          <Grid ShowGridLines="True">
            <Grid.RowDefinitions>
              <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="Auto" />
              <ColumnDefinition Width="Auto" />
              <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
          </Grid>
        </ItemsPanelTemplate>
      </ItemsControl.ItemsPanel>
      <StatusBarItem Margin="2,0,2,0" Grid.Column="0">
        <TextBlock Text="{Binding QMineStatusText}" />
      </StatusBarItem>
      <StatusBarItem Margin="2,0,2,0" Grid.Column="1">
        <TextBlock Text="{Binding QueryPluginStatusText}" />
      </StatusBarItem>
      <StatusBarItem Margin="2,0,2,0" Grid.Column="2">
        <TextBlock Text="{Binding ResultPluginStatusText}" />
      </StatusBarItem>
      <StatusBarItem Margin="2,0,2,0" Grid.Column="3">
        <TextBlock Text="{Binding ServerName}" ToolTip="{Binding ServerName}" />
      </StatusBarItem>
      <StatusBarItem Margin="2,0,2,0" Grid.Column="4">
        <TextBlock Text="{Binding DatabaseName}" ToolTip="{Binding DatabaseName}" />
      </StatusBarItem>
      <StatusBarItem Margin="2,0,2,0" Grid.Column="5">
        <Button ToolTip="Click to launch output window" Click="OpenOutputLogButton_Click">
          <Image Source="/QMineUI;component/Images/info.png" Height="10" />
        </Button>
      </StatusBarItem>
    </StatusBar>
  </Grid>
</Window>