Browse Source

Remove code duplication.

pull/16/merge
Matt Ward 14 years ago
parent
commit
c9968cd1f8
  1. 5
      src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj
  2. 30
      src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementViewModels.cs
  3. 138
      src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourcesUserControl.xaml
  4. 26
      src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourcesUserControl.xaml.cs
  5. 134
      src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourcesView.xaml
  6. 134
      src/AddIns/Misc/PackageManagement/Project/Src/RegisteredProjectTemplatePackageSourcesView.xaml

5
src/AddIns/Misc/PackageManagement/Project/PackageManagement.csproj

@ -226,6 +226,10 @@ @@ -226,6 +226,10 @@
<Compile Include="Src\PackageManagementOptions.cs" />
<Compile Include="Src\Process.cs" />
<Compile Include="Src\RegisteredPackageSourceSettings.cs" />
<Compile Include="Src\RegisteredPackageSourcesUserControl.xaml.cs">
<DependentUpon>RegisteredPackageSourcesUserControl.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\RegisteredPackageSourcesView.xaml.cs">
<DependentUpon>RegisteredPackageSourcesView.xaml</DependentUpon>
<SubType>Code</SubType>
@ -337,6 +341,7 @@ @@ -337,6 +341,7 @@
<Page Include="Src\AddPackageReferenceView.xaml" />
<Page Include="Src\LicenseAcceptanceView.xaml" />
<Page Include="Src\PackageManagementOptionsView.xaml" />
<Page Include="Src\RegisteredPackageSourcesUserControl.xaml" />
<Page Include="Src\RegisteredPackageSourcesView.xaml" />
<Page Include="Src\PackagesView.xaml" />
<Page Include="Src\PagedResultsView.xaml" />

30
src/AddIns/Misc/PackageManagement/Project/Src/PackageManagementViewModels.cs

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
using System;
using ICSharpCode.PackageManagement.Design;
using ICSharpCode.PackageManagement.Scripting;
using NuGet;
namespace ICSharpCode.PackageManagement
{
@ -69,8 +70,7 @@ namespace ICSharpCode.PackageManagement @@ -69,8 +70,7 @@ namespace ICSharpCode.PackageManagement
public RegisteredPackageSourcesViewModel RegisteredPackageSourcesViewModel {
get {
if (registeredPackageSourcesViewModel == null) {
RegisteredPackageSources packageSources =
PackageManagementServices.Options.PackageSources;
RegisteredPackageSources packageSources = GetRegisteredPackageSources();
registeredPackageSourcesViewModel =
CreateRegisteredPackageSourcesViewModel(packageSources);
}
@ -78,6 +78,20 @@ namespace ICSharpCode.PackageManagement @@ -78,6 +78,20 @@ namespace ICSharpCode.PackageManagement
}
}
RegisteredPackageSources GetRegisteredPackageSources()
{
if (IsInDesignMode()) {
return CreateDesignTimeRegisteredPackageSources();
} else {
return PackageManagementServices.Options.PackageSources;
}
}
RegisteredPackageSources CreateDesignTimeRegisteredPackageSources()
{
return new RegisteredPackageSources(new PackageSource[0]);
}
RegisteredPackageSourcesViewModel CreateRegisteredPackageSourcesViewModel(RegisteredPackageSources packageSources)
{
CreateRegisteredPackageRepositories();
@ -91,8 +105,7 @@ namespace ICSharpCode.PackageManagement @@ -91,8 +105,7 @@ namespace ICSharpCode.PackageManagement
public RegisteredPackageSourcesViewModel RegisteredProjectTemplatePackageSourcesViewModel {
get {
if (registeredProjectTemplatePackageSourcesViewModel == null) {
RegisteredPackageSources packageSources =
PackageManagementServices.ProjectTemplatePackageSources;
RegisteredPackageSources packageSources = GetProjectTemplatePackageSources();
registeredProjectTemplatePackageSourcesViewModel =
CreateRegisteredPackageSourcesViewModel(packageSources);
}
@ -100,6 +113,15 @@ namespace ICSharpCode.PackageManagement @@ -100,6 +113,15 @@ namespace ICSharpCode.PackageManagement
}
}
RegisteredPackageSources GetProjectTemplatePackageSources()
{
if (IsInDesignMode()) {
return CreateDesignTimeRegisteredPackageSources();
} else {
return PackageManagementServices.ProjectTemplatePackageSources;
}
}
public PackageManagementOptionsViewModel PackageManagementOptionsViewModel {
get {
if (packageManagementOptionsViewModel == null) {

138
src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourcesUserControl.xaml

@ -0,0 +1,138 @@ @@ -0,0 +1,138 @@
<UserControl
x:Class="ICSharpCode.PackageManagement.RegisteredPackageSourcesUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pm="clr-namespace:ICSharpCode.PackageManagement"
xmlns:pmd="clr-namespace:ICSharpCode.PackageManagement.Design"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="300">
<Grid d:DataContext="{d:DesignInstance pmd:DesignTimeRegisteredPackageSourcesViewModel, IsDesignTimeCreatable=True}">
<Grid.Resources>
<Style
x:Key="ListBoxItemStyle"
TargetType="{x:Type ListBoxItem}">
<Style.Resources>
<SolidColorBrush
x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}" />
</Style.Resources>
<Setter
Property="Background"
Value="LightGray"/>
<Style.Triggers>
<Trigger
Property="ItemsControl.AlternationIndex"
Value="0">
<Setter
Property="Background"
Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
<DataTemplate x:Key="PackageSourceListBoxTemplate">
<StackPanel
x:Name="PackageSourceStackPanel"
Margin="4">
<TextBlock Text="{Binding Path=Name}"/>
<TextBlock>
<Hyperlink>
<TextBlock Text="{Binding Path=SourceUrl}"/>
</Hyperlink>
</TextBlock>
</StackPanel>
</DataTemplate>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ListBox
Grid.Row="0"
HorizontalContentAlignment="Stretch"
AlternationCount="2"
pm:ListBoxBehaviour.IsSelectedItemScrolledIntoView="True"
ItemContainerStyle="{StaticResource ListBoxItemStyle}"
ItemTemplate="{StaticResource PackageSourceListBoxTemplate}"
ItemsSource="{Binding Path=PackageSourceViewModels}"
SelectedItem="{Binding Path=SelectedPackageSourceViewModel}"/>
<Grid
Grid.Row="1"
Margin="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="4"
Text="Name:"/>
<TextBox
Grid.Row="0"
Grid.Column="1"
Text="{Binding Path=NewPackageSourceName, UpdateSourceTrigger=PropertyChanged}"
Margin="4, 2"/>
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="4"
Text="Source:"/>
<TextBox
Grid.Row="1"
Grid.Column="1"
Text="{Binding Path=NewPackageSourceUrl, UpdateSourceTrigger=PropertyChanged}"
Margin="4,2"/>
</Grid>
<StackPanel
Grid.Column="1"
Grid.Row="0">
<Button
Content="Move Up"
Command="{Binding Path=MovePackageSourceUpCommand}"
Margin="4, 2"
Padding="7, 0"/>
<Button
Content="Move Down"
Command="{Binding Path=MovePackageSourceDownCommand}"
Margin="4, 2"
Padding="7, 0"/>
<Button
Content="Remove"
Command="{Binding Path=RemovePackageSourceCommand}"
Margin="4, 2"
Padding="7, 0"/>
</StackPanel>
<StackPanel
Grid.Column="1"
Grid.Row="1">
<Button
Content="Add"
Command="{Binding Path=AddPackageSourceCommand}"
Margin="4, 6, 4, 4"
Padding="7, 0"/>
<Button
Content="..."
Command="{Binding Path=BrowsePackageFolderCommand}"
HorizontalAlignment="Left"
Margin="4, 4"
Padding="7, 0"/>
</StackPanel>
</Grid>
</UserControl>

26
src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourcesUserControl.xaml.cs

@ -0,0 +1,26 @@ @@ -0,0 +1,26 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
namespace ICSharpCode.PackageManagement
{
/// <summary>
/// Interaction logic for RegisteredPackageSourcesUserControl.xaml
/// </summary>
public partial class RegisteredPackageSourcesUserControl : UserControl
{
public RegisteredPackageSourcesUserControl()
{
InitializeComponent();
}
}
}

134
src/AddIns/Misc/PackageManagement/Project/Src/RegisteredPackageSourcesView.xaml

@ -1,140 +1,26 @@ @@ -1,140 +1,26 @@
<gui:OptionPanel
x:Class="ICSharpCode.PackageManagement.RegisteredPackageSourcesView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pm="clr-namespace:ICSharpCode.PackageManagement"
xmlns:pmd="clr-namespace:ICSharpCode.PackageManagement.Design"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="300"
Height="300">
<Grid x:Name="MainGrid">
<Grid.Resources>
<pm:PackageManagementViewModels x:Key="ViewModels"/>
<Style
x:Key="ListBoxItemStyle"
TargetType="{x:Type ListBoxItem}">
<Style.Resources>
<SolidColorBrush
x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}" />
</Style.Resources>
<Setter
Property="Background"
Value="LightGray"/>
<Style.Triggers>
<Trigger
Property="ItemsControl.AlternationIndex"
Value="0">
<Setter
Property="Background"
Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
<DataTemplate x:Key="PackageSourceListBoxTemplate">
<StackPanel
x:Name="PackageSourceStackPanel"
Margin="4">
<TextBlock Text="{Binding Path=Name}"/>
<TextBlock>
<Hyperlink>
<TextBlock Text="{Binding Path=SourceUrl}"/>
</Hyperlink>
</TextBlock>
</StackPanel>
</DataTemplate>
<pm:PackageManagementViewModels x:Key="ViewModels"/>
</Grid.Resources>
<Grid.DataContext>
<Binding Source="{StaticResource ViewModels}" Path="RegisteredPackageSourcesViewModel"/>
</Grid.DataContext>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ListBox
Grid.Row="0"
HorizontalContentAlignment="Stretch"
AlternationCount="2"
pm:ListBoxBehaviour.IsSelectedItemScrolledIntoView="True"
ItemContainerStyle="{StaticResource ListBoxItemStyle}"
ItemTemplate="{StaticResource PackageSourceListBoxTemplate}"
ItemsSource="{Binding Path=PackageSourceViewModels}"
SelectedItem="{Binding Path=SelectedPackageSourceViewModel}"/>
<Grid
Grid.Row="1"
Margin="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="4"
Text="Name:"/>
<TextBox
Grid.Row="0"
Grid.Column="1"
Text="{Binding Path=NewPackageSourceName, UpdateSourceTrigger=PropertyChanged}"
Margin="4, 2"/>
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="4"
Text="Source:"/>
<TextBox
Grid.Row="1"
Grid.Column="1"
Text="{Binding Path=NewPackageSourceUrl, UpdateSourceTrigger=PropertyChanged}"
Margin="4,2"/>
</Grid>
<StackPanel
Grid.Column="1"
Grid.Row="0">
<Button
Content="Move Up"
Command="{Binding Path=MovePackageSourceUpCommand}"
Margin="4, 2"
Padding="7, 0"/>
<Button
Content="Move Down"
Command="{Binding Path=MovePackageSourceDownCommand}"
Margin="4, 2"
Padding="7, 0"/>
<Button
Content="Remove"
Command="{Binding Path=RemovePackageSourceCommand}"
Margin="4, 2"
Padding="7, 0"/>
</StackPanel>
<StackPanel
Grid.Column="1"
Grid.Row="1">
<Button
Content="Add"
Command="{Binding Path=AddPackageSourceCommand}"
Margin="4, 6, 4, 4"
Padding="7, 0"/>
<Button
Content="..."
Command="{Binding Path=BrowsePackageFolderCommand}"
HorizontalAlignment="Left"
Margin="4, 4"
Padding="7, 0"/>
</StackPanel>
<pm:RegisteredPackageSourcesUserControl/>
</Grid>
</gui:OptionPanel>

134
src/AddIns/Misc/PackageManagement/Project/Src/RegisteredProjectTemplatePackageSourcesView.xaml

@ -1,140 +1,26 @@ @@ -1,140 +1,26 @@
<gui:OptionPanel
x:Class="ICSharpCode.PackageManagement.RegisteredProjectTemplatePackageSourcesView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui;assembly=ICSharpCode.SharpDevelop"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pm="clr-namespace:ICSharpCode.PackageManagement"
xmlns:pmd="clr-namespace:ICSharpCode.PackageManagement.Design"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="300"
Height="300">
<Grid x:Name="MainGrid">
<Grid.Resources>
<pm:PackageManagementViewModels x:Key="ViewModels"/>
<Style
x:Key="ListBoxItemStyle"
TargetType="{x:Type ListBoxItem}">
<Style.Resources>
<SolidColorBrush
x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}" />
</Style.Resources>
<Setter
Property="Background"
Value="LightGray"/>
<Style.Triggers>
<Trigger
Property="ItemsControl.AlternationIndex"
Value="0">
<Setter
Property="Background"
Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
<DataTemplate x:Key="PackageSourceListBoxTemplate">
<StackPanel
x:Name="PackageSourceStackPanel"
Margin="4">
<TextBlock Text="{Binding Path=Name}"/>
<TextBlock>
<Hyperlink>
<TextBlock Text="{Binding Path=SourceUrl}"/>
</Hyperlink>
</TextBlock>
</StackPanel>
</DataTemplate>
<pm:PackageManagementViewModels x:Key="ViewModels"/>
</Grid.Resources>
<Grid.DataContext>
<Binding Source="{StaticResource ViewModels}" Path="RegisteredProjectTemplatePackageSourcesViewModel"/>
</Grid.DataContext>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ListBox
Grid.Row="0"
HorizontalContentAlignment="Stretch"
AlternationCount="2"
pm:ListBoxBehaviour.IsSelectedItemScrolledIntoView="True"
ItemContainerStyle="{StaticResource ListBoxItemStyle}"
ItemTemplate="{StaticResource PackageSourceListBoxTemplate}"
ItemsSource="{Binding Path=PackageSourceViewModels}"
SelectedItem="{Binding Path=SelectedPackageSourceViewModel}"/>
<Grid
Grid.Row="1"
Margin="4">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
Grid.Row="0"
Grid.Column="0"
Margin="4"
Text="Name:"/>
<TextBox
Grid.Row="0"
Grid.Column="1"
Text="{Binding Path=NewPackageSourceName, UpdateSourceTrigger=PropertyChanged}"
Margin="4, 2"/>
<TextBlock
Grid.Row="1"
Grid.Column="0"
Margin="4"
Text="Source:"/>
<TextBox
Grid.Row="1"
Grid.Column="1"
Text="{Binding Path=NewPackageSourceUrl, UpdateSourceTrigger=PropertyChanged}"
Margin="4,2"/>
</Grid>
<StackPanel
Grid.Column="1"
Grid.Row="0">
<Button
Content="Move Up"
Command="{Binding Path=MovePackageSourceUpCommand}"
Margin="4, 2"
Padding="7, 0"/>
<Button
Content="Move Down"
Command="{Binding Path=MovePackageSourceDownCommand}"
Margin="4, 2"
Padding="7, 0"/>
<Button
Content="Remove"
Command="{Binding Path=RemovePackageSourceCommand}"
Margin="4, 2"
Padding="7, 0"/>
</StackPanel>
<StackPanel
Grid.Column="1"
Grid.Row="1">
<Button
Content="Add"
Command="{Binding Path=AddPackageSourceCommand}"
Margin="4, 6, 4, 4"
Padding="7, 0"/>
<Button
Content="..."
Command="{Binding Path=BrowsePackageFolderCommand}"
HorizontalAlignment="Left"
Margin="4, 4"
Padding="7, 0"/>
</StackPanel>
<pm:RegisteredPackageSourcesUserControl/>
</Grid>
</gui:OptionPanel>
Loading…
Cancel
Save