Browse Source

Add AssemblyInfoProvider to read and write assembly info file. Bind assembly info to panel.

pull/624/head
olegbevz 11 years ago
parent
commit
d1b8ff41ce
  1. 2
      data/resources/StringResources.resx
  2. 10
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  3. 47
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfo.cs
  4. 69
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoPanel.xaml
  5. 201
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoProvider.cs
  6. 29
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfoPanel.xaml.cs

2
data/resources/StringResources.resx

@ -8404,7 +8404,7 @@ Press Esc to cancel this operation.</value> @@ -8404,7 +8404,7 @@ Press Esc to cancel this operation.</value>
<data name="Dialog.ProjectOptions.AssemblyInfo.NeutralLanguage" xml:space="preserve">
<value>Neutral language:</value>
</data>
<data name="Dialog.ProjectOptions.AssemblyInfo.Poduct" xml:space="preserve">
<data name="Dialog.ProjectOptions.AssemblyInfo.Product" xml:space="preserve">
<value>Product:</value>
</data>
<data name="Dialog.ProjectOptions.AssemblyInfo.Title" xml:space="preserve">

10
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -303,9 +303,11 @@ @@ -303,9 +303,11 @@
<DependentUpon>OutputWindowOptionsPanel.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\AssemblyInfoPanel.xaml.cs">
<Compile Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\AssemblyInfo\AssemblyInfo.cs" />
<Compile Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\AssemblyInfo\AssemblyInfoPanel.xaml.cs">
<DependentUpon>AssemblyInfoPanel.xaml</DependentUpon>
</Compile>
<Compile Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\AssemblyInfo\AssemblyInfoProvider.cs" />
<Compile Include="Src\Gui\Pads\CompilerMessageView\MessageViewCategoryTextWriter.cs" />
<Compile Include="Src\Gui\Pads\TaskList\TaskViewResources.xaml.cs">
<DependentUpon>TaskViewResources.xaml</DependentUpon>
@ -914,7 +916,7 @@ @@ -914,7 +916,7 @@
<Page Include="Src\Gui\Dialogs\OptionPanels\IDEOptions\TaskListOptionsPanel.xaml" />
<Page Include="Src\Gui\Dialogs\OptionPanels\OutputWindowOptionsPanel.xaml" />
<Page Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\ApplicationSettings.xaml" />
<Page Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\AssemblyInfoPanel.xaml">
<Page Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\AssemblyInfo\AssemblyInfoPanel.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
@ -947,6 +949,10 @@ @@ -947,6 +949,10 @@
<Name>ICSharpCode.NRefactory.Cecil</Name>
<Private>False</Private>
</ProjectReference>
<ProjectReference Include="..\..\..\Libraries\NRefactory\ICSharpCode.NRefactory.CSharp\ICSharpCode.NRefactory.CSharp.csproj">
<Project>{53dca265-3c3c-42f9-b647-f72ba678122b}</Project>
<Name>ICSharpCode.NRefactory.CSharp</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Libraries\NRefactory\ICSharpCode.NRefactory.Xml\ICSharpCode.NRefactory.Xml.csproj">
<Project>{DC393B66-92ED-4CAD-AB25-CFEF23F3D7C6}</Project>
<Name>ICSharpCode.NRefactory.Xml</Name>

47
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfo.cs

@ -0,0 +1,47 @@ @@ -0,0 +1,47 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
{
public class AssemblyInfo
{
public string Title { get; set; }
public string Description { get; set; }
public string Company { get; set; }
public string Product { get; set; }
public string Copyright { get; set; }
public string Trademark { get; set; }
public Version AssemblyVersion { get; set; }
public Version FileVersion { get; set; }
public Guid Guid { get; set; }
public string NeutralLanguage { get; set; }
public bool ComVisible { get; set; }
}
}

69
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoPanel.xaml

@ -0,0 +1,69 @@ @@ -0,0 +1,69 @@
<optionPanels:ProjectOptionPanel
x:Class="ICSharpCode.SharpDevelop.Gui.OptionPanels.AssemblyInfoPanel"
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:core="http://icsharpcode.net/sharpdevelop/core"
xmlns:optionPanels="clr-namespace:ICSharpCode.SharpDevelop.Gui.OptionPanels"
mc:Ignorable="d">
<ScrollViewer VerticalScrollBarVisibility="Auto">
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type Label}">
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Height" Value="20"/>
<Setter Property="Margin" Value="4"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<EventSetter Event="TextChanged" Handler="OnPanelOptionsChanged"/>
</Style>
<Style TargetType="{x:Type CheckBox}">
<Setter Property="Margin" Value="4"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<EventSetter Event="Checked" Handler="OnPanelOptionsChanged"/>
<EventSetter Event="Unchecked" Handler="OnPanelOptionsChanged"/>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.Title}" Grid.Column="0" Grid.Row="0"/>
<TextBox Text="{Binding Title}" Grid.Column="1" Grid.Row="0"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.Description}" Grid.Column="0" Grid.Row="1"/>
<TextBox Text="{Binding Description}" Grid.Column="1" Grid.Row="1"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.Company}" Grid.Column="0" Grid.Row="2"/>
<TextBox Text="{Binding Company}" Grid.Column="1" Grid.Row="2"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.Product}" Grid.Column="0" Grid.Row="3"/>
<TextBox Text="{Binding Product}" Grid.Column="1" Grid.Row="3"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.Copyright}" Grid.Column="0" Grid.Row="4"/>
<TextBox Text="{Binding Copyright}" Grid.Column="1" Grid.Row="4"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.Trademark}" Grid.Column="0" Grid.Row="5"/>
<TextBox Text="{Binding Trademark}" Grid.Column="1" Grid.Row="5"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.AssemblyVersion}" Grid.Column="0" Grid.Row="6"/>
<TextBox Text="{Binding AssemblyVersion}" Grid.Column="1" Grid.Row="6"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.FileVersion}" Grid.Column="0" Grid.Row="7"/>
<TextBox Text="{Binding FileVersion}" Grid.Column="1" Grid.Row="7"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.GUID}" Grid.Column="0" Grid.Row="8"/>
<TextBox Text="{Binding Guid}" Grid.Column="1" Grid.Row="8"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.NeutralLanguage}" Grid.Column="0" Grid.Row="9"/>
<TextBox Text="{Binding NeutralLanguage}" Grid.Column="1" Grid.Row="9"/>
<CheckBox Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.MakeAssemblyCOMVisible}" IsChecked="{Binding ComVisible}" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="10"/>
</Grid>
</ScrollViewer>
</optionPanels:ProjectOptionPanel>

201
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoProvider.cs

@ -0,0 +1,201 @@ @@ -0,0 +1,201 @@
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.IO;
using System.Linq;
using ICSharpCode.NRefactory.CSharp;
using Mono.CSharp;
using Attribute = ICSharpCode.NRefactory.CSharp.Attribute;
using CSharpParser = ICSharpCode.NRefactory.CSharp.CSharpParser;
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
{
public class AssemblyInfoProvider
{
public AssemblyInfo Read(string fileName)
{
var syntaxTree = ReadSyntaxTree(fileName);
if (syntaxTree == null)
throw new Exception("Can't read assembly info syntax tree.");
var assemblyInfo = new AssemblyInfo();
foreach (var attributeSection in syntaxTree.Children.OfType<AttributeSection>())
{
foreach (var attribute in attributeSection.Attributes)
{
var attributeType = attribute.Type as SimpleType;
if (attributeType == null)
continue;
switch (attributeType.Identifier)
{
case "AssemblyTitle":
assemblyInfo.Title = GetAttributeValueAsString(attribute);
break;
case "AssemblyDescription":
assemblyInfo.Description = GetAttributeValueAsString(attribute);
break;
case "AssemblyConfigurtation":
break;
case "AssemblyCompany":
assemblyInfo.Company = GetAttributeValueAsString(attribute);
break;
case "AssemblyProduct":
assemblyInfo.Product = GetAttributeValueAsString(attribute);
break;
case "AssemblyCopyright":
assemblyInfo.Copyright = GetAttributeValueAsString(attribute);
break;
case "AssemblyTrademark":
assemblyInfo.Trademark = GetAttributeValueAsString(attribute);
break;
case "AssemblyCulture":
break;
case "ComVisible":
assemblyInfo.ComVisible = GetAttributeValueAsBool(attribute);
break;
case "Guid":
assemblyInfo.Guid = GetAttributeValueAsGuid(attribute);
break;
case "AssemblyVersion":
assemblyInfo.AssemblyVersion = GetAttributeValueAsVersion(attribute);
break;
case "AssemblyFileVersion":
assemblyInfo.FileVersion = GetAttributeValueAsVersion(attribute);
break;
case "NeutralResourcesLanguageAttribute":
assemblyInfo.NeutralLanguage = GetAttributeValueAsString(attribute);
break;
}
}
}
return assemblyInfo;
}
public void Write(string fileName, AssemblyInfo assemblyInfo)
{
var syntaxTree = ReadSyntaxTree(fileName);
if (syntaxTree == null)
throw new Exception("Can't read assembly info syntax tree.");
SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyTitle", assemblyInfo.Title);
SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyDescription", assemblyInfo.Description);
SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyCompany", assemblyInfo.Company);
SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyProduct", assemblyInfo.Product);
SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyCopyright", assemblyInfo.Copyright);
SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyTrademark", assemblyInfo.Trademark);
SetAttributeValueOrAddAttribute(syntaxTree, "ComVisible", assemblyInfo.ComVisible);
SetAttributeValueOrAddAttribute(syntaxTree, "Guid", assemblyInfo.Guid.ToString());
SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyVersion", assemblyInfo.AssemblyVersion.ToString());
SetAttributeValueOrAddAttribute(syntaxTree, "AssemblyFileVersion", assemblyInfo.FileVersion.ToString());
SetAttributeValueOrAddAttribute(syntaxTree, "NeutralResourcesLanguageAttribute", assemblyInfo.NeutralLanguage);
WriteSyntaxTree(syntaxTree, fileName);
}
private SyntaxTree ReadSyntaxTree(string fileName)
{
using (var fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
using (var streamReader = new StreamReader(fileStream))
{
var codeParser = new CSharpParser();
return codeParser.Parse(streamReader);
}
}
}
private void WriteSyntaxTree(SyntaxTree syntaxTree, string fileName)
{
File.WriteAllText(fileName, syntaxTree.ToString());
}
private string GetAttributeValueAsString(Attribute attribute)
{
var attributeArguments = attribute.Arguments.OfType<PrimitiveExpression>().ToArray();
if (attributeArguments.Length == 1)
return attributeArguments[0].Value as string;
return string.Empty;
}
private bool GetAttributeValueAsBool(Attribute attribute)
{
var attributeArguments = attribute.Arguments.OfType<PrimitiveExpression>().ToArray();
if (attributeArguments.Length == 1)
return (bool)attributeArguments[0].Value;
return false;
}
private Guid GetAttributeValueAsGuid(Attribute attribute)
{
var attributeArguments = attribute.Arguments.OfType<PrimitiveExpression>().ToArray();
if (attributeArguments.Length == 1)
return Guid.Parse(attributeArguments[0].Value as string);
return Guid.Empty;
}
private Version GetAttributeValueAsVersion(Attribute attribute)
{
var attributeArguments = attribute.Arguments.OfType<PrimitiveExpression>().ToArray();
if (attributeArguments.Length == 1)
{
var versionString = attributeArguments[0].Value as string;
var versionParts = versionString.Split('.');
if (versionParts.Length == 4)
{
return new Version(
int.Parse(versionParts[0]),
int.Parse(versionParts[1]),
int.Parse(versionParts[2]),
int.Parse(versionParts[3]));
}
}
return null;
}
private void SetAttributeValueOrAddAttribute(SyntaxTree syntaxTree, string attributeName, object value)
{
var attribute = syntaxTree.Children.OfType<AttributeSection>().SelectMany(x => x.Attributes)
.FirstOrDefault(x => x.Type is SimpleType && ((SimpleType)x.Type).Identifier == attributeName);
if (attribute != null)
{
attribute.Arguments.Clear();
attribute.Arguments.Add(new PrimitiveExpression(value));
}
else
{
attribute = new Attribute() { Type = new SimpleType(attributeName) };
attribute.Arguments.Add(new PrimitiveExpression(value));
var attributeSection = new AttributeSection(attribute) { AttributeTarget = "assembly" };
syntaxTree.AddChild(attributeSection, new NRefactory.Role<AttributeSection>("Member"));
}
}
}
}

29
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfoPanel.xaml.cs

@ -1,29 +0,0 @@ @@ -1,29 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ICSharpCode.SharpDevelop.Gui.OptionPanels;
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
{
/// <summary>
/// Interaction logic for AssemblyInfo.xaml
/// </summary>
public partial class AssemblyInfoPanel : ProjectOptionPanel
{
public AssemblyInfoPanel()
{
InitializeComponent();
}
}
}
Loading…
Cancel
Save