Browse Source

Merge pull request #642 from linquize/assembly-info

Version Editor should allow other patterns
pull/651/head
Andreas Weizel 11 years ago
parent
commit
69aa9f3375
  1. 4
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfo.cs
  2. 4
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoPanel.xaml
  3. 21
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoProvider.cs
  4. 4
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoViewModel.cs
  5. 8
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/VersionEditor.xaml
  6. 186
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/VersionEditor.xaml.cs

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

@ -39,9 +39,9 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -39,9 +39,9 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
public string DefaultAlias { get; set; }
public Version AssemblyVersion { get; set; }
public string AssemblyVersion { get; set; }
public Version AssemblyFileVersion { get; set; }
public string AssemblyFileVersion { get; set; }
public string InformationalVersion { get; set; }

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

@ -88,10 +88,10 @@ @@ -88,10 +88,10 @@
<TextBox Text="{Binding DefaultAlias, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="6"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.AssemblyVersion}" Grid.Column="0" Grid.Row="7"/>
<projectOptions:VersionEditor Version="{Binding AssemblyVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="7"/>
<projectOptions:VersionEditor Version="{Binding AssemblyVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Type="Assembly" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="7"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.FileVersion}" Grid.Column="0" Grid.Row="8"/>
<projectOptions:VersionEditor Version="{Binding AssemblyFileVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="8"/>
<projectOptions:VersionEditor Version="{Binding AssemblyFileVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Type="File" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="8"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.InformationalVersion}" Grid.Column="0" Grid.Row="9"/>
<TextBox Text="{Binding InformationalVersion, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="9"/>

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

@ -122,11 +122,11 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -122,11 +122,11 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
break;
case AssemblyVersion:
case AssemblyVersion + Attribute:
assemblyInfo.AssemblyVersion = GetAttributeValueAsVersion(attribute);
assemblyInfo.AssemblyVersion = GetAttributeValue<string>(attribute);
break;
case AssemblyFileVersion:
case AssemblyFileVersion + Attribute:
assemblyInfo.AssemblyFileVersion = GetAttributeValueAsVersion(attribute);
assemblyInfo.AssemblyFileVersion = GetAttributeValue<string>(attribute);
break;
case AssemblyInformationalVersion:
case AssemblyInformationalVersion + Attribute:
@ -268,23 +268,6 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -268,23 +268,6 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
return null;
}
private Version GetAttributeValueAsVersion(Attribute attribute)
{
var attributeArguments = attribute.Arguments.OfType<PrimitiveExpression>().ToArray();
if (attributeArguments.Length == 1)
{
var versionString = attributeArguments[0].Value as string;
if (!string.IsNullOrEmpty(versionString))
{
Version version;
if (Version.TryParse(versionString, out version))
return version;
}
}
return null;
}
private AssemblyNameFlags GetAssemblyFlagsFromAttribute(Attribute attribute)
{
if (attribute.Arguments.Count == 1)

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

@ -92,13 +92,13 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -92,13 +92,13 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
set { assemblyInfo.DefaultAlias = value; OnPropertyChanged(); }
}
public Version AssemblyVersion
public string AssemblyVersion
{
get { return assemblyInfo.AssemblyVersion; }
set { assemblyInfo.AssemblyVersion = value; OnPropertyChanged(); }
}
public Version AssemblyFileVersion
public string AssemblyFileVersion
{
get { return assemblyInfo.AssemblyFileVersion; }
set { assemblyInfo.AssemblyFileVersion = value; OnPropertyChanged(); }

8
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/VersionEditor.xaml

@ -11,9 +11,9 @@ @@ -11,9 +11,9 @@
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBox Name="majorTextBox" Grid.Column="0" PreviewTextInput="OnTextBoxPreviewTextInput" TextChanged="OnTextChanged"/>
<TextBox Name="minorTextBox" Grid.Column="1" PreviewTextInput="OnTextBoxPreviewTextInput" TextChanged="OnTextChanged"/>
<TextBox Name="buildTextBox" Grid.Column="2" PreviewTextInput="OnTextBoxPreviewTextInput" TextChanged="OnTextChanged"/>
<TextBox Name="revisionTextBox" Grid.Column="3" PreviewTextInput="OnTextBoxPreviewTextInput" TextChanged="OnTextChanged"/>
<TextBox Name="majorTextBox" Grid.Column="0" TextChanged="OnTextChanged"/>
<TextBox Name="minorTextBox" Grid.Column="1" TextChanged="OnTextChanged"/>
<TextBox Name="buildTextBox" Grid.Column="2" TextChanged="OnTextChanged"/>
<TextBox Name="revisionTextBox" Grid.Column="3" TextChanged="OnTextChanged"/>
</Grid>
</UserControl>

186
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/VersionEditor.xaml.cs

@ -17,6 +17,7 @@ @@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
@ -30,26 +31,129 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ProjectOptions @@ -30,26 +31,129 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ProjectOptions
public partial class VersionEditor
{
public static DependencyProperty VersionProperty =
DependencyProperty.Register("Version", typeof(Version), typeof(VersionEditor), new PropertyMetadata(OnVersionChanged));
DependencyProperty.Register("Version", typeof(string), typeof(VersionEditor), new PropertyMetadata(OnVersionChanged));
public static DependencyProperty TypeProperty =
DependencyProperty.Register("Type", typeof(VersionType), typeof(VersionEditor));
public VersionEditor()
{
InitializeComponent();
}
public Version Version
public string Version
{
get { return GetValue(VersionProperty) as Version; }
get { return GetValue(VersionProperty) as string; }
set { SetValue(VersionProperty, value); }
}
private void OnTextBoxPreviewTextInput(object sender, TextCompositionEventArgs e)
public VersionType Type
{
// Block any non-character input
if (!e.Text.All(char.IsDigit))
get { return (VersionType)GetValue(TypeProperty); }
set { SetValue(TypeProperty, value); }
}
public enum VersionType
{
Assembly,
File,
Info,
}
enum AllowedType
{
Integer,
Star,
Empty,
String,
}
static readonly AllowedType[][] assemblyVersionTypes =
{
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Integer, AllowedType.Integer },
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Integer, AllowedType.Empty },
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Integer, AllowedType.Star },
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Empty, AllowedType.Empty },
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Star, AllowedType.Empty },
new [] { AllowedType.Integer, AllowedType.Empty, AllowedType.Empty, AllowedType.Empty },
new [] { AllowedType.Integer, AllowedType.Star, AllowedType.Empty, AllowedType.Empty },
};
static readonly AllowedType[][] fileVersionTypes =
{
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Integer, AllowedType.Integer },
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Integer, AllowedType.Empty },
new [] { AllowedType.Integer, AllowedType.Integer, AllowedType.Empty, AllowedType.Empty },
new [] { AllowedType.Integer, AllowedType.Empty, AllowedType.Empty, AllowedType.Empty },
};
static readonly AllowedType[][] infoVersionTypes =
{
new [] { AllowedType.String, AllowedType.String, AllowedType.String, AllowedType.String },
new [] { AllowedType.String, AllowedType.String, AllowedType.String, AllowedType.Empty },
new [] { AllowedType.String, AllowedType.String, AllowedType.Empty, AllowedType.Empty },
new [] { AllowedType.String, AllowedType.Empty, AllowedType.Empty, AllowedType.Empty },
};
static readonly int[] assemblyVersionRange = { 0, 65534 };
static readonly int[] fileVersionRange = { 0, 65535 };
AllowedType[] GetAllowedType(string[] parts)
{
AllowedType[][] types = GetAllowedTypes();
int[] range = GetAllowedRange();
bool allowed = false;
foreach (var element in types)
{
e.Handled = true;
allowed = true;
for (int i = 0; i < parts.Length; i++)
{
int t;
switch (element[i])
{
case AllowedType.Integer:
if (!int.TryParse(parts[i], out t))
allowed = false;
if (range != null && (t < range[0] || t > range[1]))
allowed = false;
break;
case AllowedType.Star:
if (parts[i] != "*")
allowed = false;
break;
case AllowedType.Empty:
if (!string.IsNullOrEmpty(parts[i]))
allowed = false;
break;
case AllowedType.String:
if (string.IsNullOrEmpty(parts[i]))
allowed = false;
break;
}
if (!allowed)
break;
}
if (allowed)
return element;
}
return null;
}
AllowedType[][] GetAllowedTypes()
{
if (this.Type == VersionType.Assembly)
return assemblyVersionTypes;
if (this.Type == VersionType.File)
return fileVersionTypes;
return infoVersionTypes;
}
int[] GetAllowedRange()
{
if (this.Type == VersionType.Assembly)
return assemblyVersionRange;
if (this.Type == VersionType.File)
return fileVersionRange;
return null;
}
private void OnTextChanged(object sender, TextChangedEventArgs e)
@ -60,39 +164,67 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ProjectOptions @@ -60,39 +164,67 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ProjectOptions
string buildPart = buildTextBox.Text;
string revisionPart = revisionTextBox.Text;
int majorVersion = 0, minorVersion = 0, build = 0, revision = 0;
var majorVersionWasSet = !string.IsNullOrEmpty(majorPart) && int.TryParse(majorPart, out majorVersion);
var minorVersionWasSet = !string.IsNullOrEmpty(minorPart) && int.TryParse(minorPart, out minorVersion);
var buildWasSet = !string.IsNullOrEmpty(buildPart) && int.TryParse(buildPart, out build);
var revisionWasSet = !string.IsNullOrEmpty(revisionPart) && int.TryParse(revisionPart, out revision);
AllowedType[] type = GetAllowedType(new string[] { majorPart, minorPart, buildPart, revisionPart });
if (type == null)
type = GetAllowedType(new string[] { majorPart, minorPart, buildPart, "" });
if (type == null)
type = GetAllowedType(new string[] { majorPart, minorPart, "", "" });
if (type == null)
type = GetAllowedType(new string[] { majorPart, "", "", "" });
Version newVersion;
if (revisionWasSet)
newVersion = new Version(majorVersion, minorVersion, build, revision);
else if (buildWasSet)
newVersion = new Version(majorVersion, minorVersion, build);
else if (majorVersionWasSet || minorVersionWasSet)
newVersion = new Version(majorVersion, minorVersion);
string newVersion;
if (type != null)
{
if (type[3] != AllowedType.Empty)
newVersion = majorPart + "." + minorPart + "." + buildPart + "." + revisionPart;
else if (type[2] != AllowedType.Empty)
newVersion = majorPart + "." + minorPart + "." + buildPart;
else if (type[1] != AllowedType.Empty)
newVersion = majorPart + "." + minorPart;
else if (type[0] != AllowedType.Empty)
newVersion = majorPart;
else
newVersion = "";
}
else
newVersion = new Version();
newVersion = "";
if (!newVersion.Equals(Version))
Version = newVersion;
}
static string[] SplitNParts(string s, char c, int count)
{
var parts = new List<string>();
int pos = 0;
for (int i = 0; i < s.Length; i++)
{
if (s[i] == c)
{
if (parts.Count + 1 == count)
break;
parts.Add(s.Substring(pos, i - pos));
pos = i + 1;
}
}
parts.Add(s.Substring(pos));
return parts.ToArray();
}
private static void OnVersionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var versionEditor = d as VersionEditor;
var newVersion = e.NewValue as Version;
var newVersion = e.NewValue as string;
if (versionEditor != null && newVersion != null)
{
var parts = SplitNParts(newVersion, '.', 4);
// Update textboxes values when version property changes
versionEditor.majorTextBox.Text = newVersion.Major >= 0 ? newVersion.Major.ToString() : string.Empty;
versionEditor.minorTextBox.Text = newVersion.Minor >= 0 ? newVersion.Minor.ToString() : string.Empty;
versionEditor.buildTextBox.Text = newVersion.Build >= 0 ? newVersion.Build.ToString() : string.Empty;
versionEditor.revisionTextBox.Text = newVersion.Revision >= 0 ? newVersion.Revision.ToString() : string.Empty;
versionEditor.majorTextBox.Text = parts.Length > 0 ? parts[0] : string.Empty;
versionEditor.minorTextBox.Text = parts.Length > 1 ? parts[1] : string.Empty;
versionEditor.buildTextBox.Text = parts.Length > 2 ? parts[2] : string.Empty;
versionEditor.revisionTextBox.Text = parts.Length > 3 ? parts[3] : string.Empty;
}
}
}

Loading…
Cancel
Save