<framework:ModalDialogUserControl
  x:Class="NuGet.WebMatrix.SourceManagerView"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:self="clr-namespace:NuGet.WebMatrix"
  xmlns:framework="clr-namespace:Microsoft.WebMatrix.Core;assembly=Microsoft.WebMatrix.Core"
  xmlns:converters="clr-namespace:Microsoft.WebMatrix.Core.Converters;assembly=Microsoft.WebMatrix.Core"
  mc:Ignorable="d"
  x:ClassModifier="internal"
  StandardSize="Medium">
  <UserControl.Resources>
    <converters:InverseBoolOrVisibilityToVisibilityCollapsedConverter
      x:Key="inverseVisibilityConverter" />
    <converters:NullToVisibilityConverter
      x:Key="nullToVisibilityConverter" />

    <BooleanToVisibilityConverter
      x:Key="BoolToVis" />
    <self:FixUrlConverter
      x:Key="urlConverter" />
    <self:ColorToBrushConverter
      x:Key="colorToBrushConverter" />

    <Style
      x:Key="GridViewColumnHeaderStyle"
      TargetType="{x:Type GridViewColumnHeader}">
      <Setter
        Property="HorizontalContentAlignment"
        Value="Left" />

      <Setter
        Property="Padding"
        Value="5 3 3 3" />
    </Style>

    <LinearGradientBrush
      x:Key="GridViewColumnHeaderPressBackground"
      EndPoint="0,1"
      StartPoint="0,0">
      <GradientStop
        Color="#FF8DD6F7"
        Offset="0" />

      <GradientStop
        Color="#FF8AD1F5"
        Offset="1" />
    </LinearGradientBrush>


    <ControlTemplate
      x:Key="Template_ListViewItem"
      TargetType='{x:Type ListViewItem}'>
      <StackPanel
        Orientation="Horizontal">
        <GridViewRowPresenter
          Content="{TemplateBinding Content}"
          Columns="{TemplateBinding GridView.ColumnCollection}" />
        <Button
          Content="{x:Static self:Resources.String_Delete}"
          Command="{Binding  RelativeSource={RelativeSource AncestorType={x:Type ListView}}, Path=DataContext.DeleteCommand}"
          CommandParameter="{Binding Path=.}"
          Visibility="{Binding Path=IsBuiltIn, Mode=OneWay, Converter={StaticResource inverseVisibilityConverter}}" />
      </StackPanel>
      <ControlTemplate.Triggers>
        <Trigger
          Property="Selector.IsSelected"
          Value="True">
          <Setter
            Property="Background"
            Value="{StaticResource GridViewColumnHeaderPressBackground}" />
        </Trigger>
      </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style
      x:Key="Style_ListViewItem"
      TargetType="{x:Type ListViewItem}">
      <Setter
        Property="BorderBrush"
        Value="#FFE4E4E4" />

      <Setter
        Property="BorderThickness"
        Value="0,0,0,1" />

      <Setter
        Property="Margin"
        Value="0 4 0 0" />

      <Setter
        Property="Template"
        Value="{StaticResource Template_ListViewItem}" />

      <Setter
        Property="AutomationProperties.Name">
        <Setter.Value>
          <MultiBinding
            StringFormat="{} {0} {1}">
            <Binding
              Source="{x:Static self:Resources.String_Name}" />

            <Binding
              Path="Name" />

            <Binding
              Source="{x:Static self:Resources.String_URL}" />

            <Binding
              Path="SourceUrl" />

          </MultiBinding>
        </Setter.Value>
      </Setter>
    </Style>
  </UserControl.Resources>

  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition
        Height="Auto" />
      <RowDefinition
        Height="*" />
    </Grid.RowDefinitions>
    <GroupBox
      Grid.Row="0"
      Header="{x:Static self:Resources.String_AddSource}"
      Padding="7">
      <StackPanel
        Orientation="Vertical">
        <TextBlock
          Text="{x:Static self:Resources.String_Name}" />
        <TextBox
          Margin="0,3,0,0"
          Text="{Binding NewSourceName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
          MaxLength="256"
          MaxWidth="{Binding Path=ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type StackPanel}}}"
          KeyDown="TextBox_KeyDown"
          AutomationProperties.AutomationId="newSourceName" />
        <TextBlock
          Text="{x:Static self:Resources.String_URL}"
          Margin="0,3,0,0" />
        <TextBox
          Margin="0,3,0,0"
          MaxWidth="{Binding Path=ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type StackPanel}}}"
          KeyDown="TextBox_KeyDown"
          AutomationProperties.AutomationId="newSourceUrl">
          <Binding
            Path="NewSourceUrl"
            UpdateSourceTrigger="PropertyChanged"
            Mode="TwoWay">
            <Binding.ValidationRules>
              <framework:UrlValidationRule
                ValidatesOnTargetUpdated="True"
                ValidationStep="CommittedValue"
                AllowedSchemes="http;https;file"
                DisableDefaultSchemeHelper="True" />
            </Binding.ValidationRules>
          </Binding>
        </TextBox>
        <Button
          HorizontalAlignment="Right"
          x:Name="_addButton"
          Command="{Binding AddCommand, Mode=OneWay}"
          Content="{x:Static self:Resources.String_Add}"
          Margin="0,3,0,0" />
      </StackPanel>
    </GroupBox>
    <ListView
      Grid.Row="1"
      ItemsSource="{Binding FeedSources}"
      BorderThickness="0,0,0,1"
      BorderBrush="#FFE5E5E5"
      Margin="0"
      ItemContainerStyle="{StaticResource Style_ListViewItem}"
      SelectionMode="Single"
      Height="180"
      MaxWidth="478"
      HorizontalAlignment="Left"
      VerticalAlignment="Center"
      AutomationProperties.AutomationId="existingSources">
      <ListView.View>
        <GridView>
          <GridViewColumn
            Header="{x:Static self:Resources.String_Name}"
            Width="150"
            HeaderContainerStyle="{StaticResource GridViewColumnHeaderStyle}">
            <GridViewColumn.CellTemplate>
              <DataTemplate>
                <TextBlock
                  Text="{Binding Path=Name, Mode=OneWay}"
                  TextTrimming="CharacterEllipsis" />
              </DataTemplate>
            </GridViewColumn.CellTemplate>
          </GridViewColumn>
          <GridViewColumn
            Header="{x:Static self:Resources.String_URL}"
            Width="250"
            HeaderContainerStyle="{StaticResource GridViewColumnHeaderStyle}">
            <GridViewColumn.CellTemplate>
              <DataTemplate>
                <TextBlock
                  Text="{Binding Path=SourceUrl, Mode=OneWay}"
                  TextTrimming="CharacterEllipsis"
                  ToolTip="{Binding Path=SourceUrl}" />
              </DataTemplate>
            </GridViewColumn.CellTemplate>
          </GridViewColumn>
        </GridView>
      </ListView.View>
    </ListView>
  </Grid>
</framework:ModalDialogUserControl>