Browse Source

Version Editor should allow other patterns

Do range checking.
AssemblyVersion can have "1.0.*".
AssemblyInformationalVersion can be arbitrary.
pull/642/head
Linquize 11 years ago
parent
commit
0e7db49105
  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
public string DefaultAlias { get; set; } 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; } public string InformationalVersion { get; set; }

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

@ -88,10 +88,10 @@
<TextBox Text="{Binding DefaultAlias, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="6"/> <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"/> <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"/> <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"/> <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"/> <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
break; break;
case AssemblyVersion: case AssemblyVersion:
case AssemblyVersion + Attribute: case AssemblyVersion + Attribute:
assemblyInfo.AssemblyVersion = GetAttributeValueAsVersion(attribute); assemblyInfo.AssemblyVersion = GetAttributeValue<string>(attribute);
break; break;
case AssemblyFileVersion: case AssemblyFileVersion:
case AssemblyFileVersion + Attribute: case AssemblyFileVersion + Attribute:
assemblyInfo.AssemblyFileVersion = GetAttributeValueAsVersion(attribute); assemblyInfo.AssemblyFileVersion = GetAttributeValue<string>(attribute);
break; break;
case AssemblyInformationalVersion: case AssemblyInformationalVersion:
case AssemblyInformationalVersion + Attribute: case AssemblyInformationalVersion + Attribute:
@ -268,23 +268,6 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
return null; 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) private AssemblyNameFlags GetAssemblyFlagsFromAttribute(Attribute attribute)
{ {
if (attribute.Arguments.Count == 1) 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
set { assemblyInfo.DefaultAlias = value; OnPropertyChanged(); } set { assemblyInfo.DefaultAlias = value; OnPropertyChanged(); }
} }
public Version AssemblyVersion public string AssemblyVersion
{ {
get { return assemblyInfo.AssemblyVersion; } get { return assemblyInfo.AssemblyVersion; }
set { assemblyInfo.AssemblyVersion = value; OnPropertyChanged(); } set { assemblyInfo.AssemblyVersion = value; OnPropertyChanged(); }
} }
public Version AssemblyFileVersion public string AssemblyFileVersion
{ {
get { return assemblyInfo.AssemblyFileVersion; } get { return assemblyInfo.AssemblyFileVersion; }
set { assemblyInfo.AssemblyFileVersion = value; OnPropertyChanged(); } set { assemblyInfo.AssemblyFileVersion = value; OnPropertyChanged(); }

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

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

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

@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
@ -30,26 +31,129 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ProjectOptions
public partial class VersionEditor public partial class VersionEditor
{ {
public static DependencyProperty VersionProperty = 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() public VersionEditor()
{ {
InitializeComponent(); InitializeComponent();
} }
public Version Version public string Version
{ {
get { return GetValue(VersionProperty) as Version; } get { return GetValue(VersionProperty) as string; }
set { SetValue(VersionProperty, value); } set { SetValue(VersionProperty, value); }
} }
private void OnTextBoxPreviewTextInput(object sender, TextCompositionEventArgs e) public VersionType Type
{ {
// Block any non-character input get { return (VersionType)GetValue(TypeProperty); }
if (!e.Text.All(char.IsDigit)) 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)
{
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()
{ {
e.Handled = true; 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) private void OnTextChanged(object sender, TextChangedEventArgs e)
@ -60,39 +164,67 @@ namespace ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ProjectOptions
string buildPart = buildTextBox.Text; string buildPart = buildTextBox.Text;
string revisionPart = revisionTextBox.Text; string revisionPart = revisionTextBox.Text;
int majorVersion = 0, minorVersion = 0, build = 0, revision = 0; AllowedType[] type = GetAllowedType(new string[] { majorPart, minorPart, buildPart, revisionPart });
if (type == null)
var majorVersionWasSet = !string.IsNullOrEmpty(majorPart) && int.TryParse(majorPart, out majorVersion); type = GetAllowedType(new string[] { majorPart, minorPart, buildPart, "" });
var minorVersionWasSet = !string.IsNullOrEmpty(minorPart) && int.TryParse(minorPart, out minorVersion); if (type == null)
var buildWasSet = !string.IsNullOrEmpty(buildPart) && int.TryParse(buildPart, out build); type = GetAllowedType(new string[] { majorPart, minorPart, "", "" });
var revisionWasSet = !string.IsNullOrEmpty(revisionPart) && int.TryParse(revisionPart, out revision); if (type == null)
type = GetAllowedType(new string[] { majorPart, "", "", "" });
Version newVersion;
if (revisionWasSet) string newVersion;
newVersion = new Version(majorVersion, minorVersion, build, revision); if (type != null)
else if (buildWasSet) {
newVersion = new Version(majorVersion, minorVersion, build); if (type[3] != AllowedType.Empty)
else if (majorVersionWasSet || minorVersionWasSet) newVersion = majorPart + "." + minorPart + "." + buildPart + "." + revisionPart;
newVersion = new Version(majorVersion, minorVersion); 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 else
newVersion = new Version(); newVersion = "";
if (!newVersion.Equals(Version)) if (!newVersion.Equals(Version))
Version = newVersion; 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) private static void OnVersionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{ {
var versionEditor = d as VersionEditor; var versionEditor = d as VersionEditor;
var newVersion = e.NewValue as Version; var newVersion = e.NewValue as string;
if (versionEditor != null && newVersion != null) if (versionEditor != null && newVersion != null)
{ {
var parts = SplitNParts(newVersion, '.', 4);
// Update textboxes values when version property changes // Update textboxes values when version property changes
versionEditor.majorTextBox.Text = newVersion.Major >= 0 ? newVersion.Major.ToString() : string.Empty; versionEditor.majorTextBox.Text = parts.Length > 0 ? parts[0] : string.Empty;
versionEditor.minorTextBox.Text = newVersion.Minor >= 0 ? newVersion.Minor.ToString() : string.Empty; versionEditor.minorTextBox.Text = parts.Length > 1 ? parts[1] : string.Empty;
versionEditor.buildTextBox.Text = newVersion.Build >= 0 ? newVersion.Build.ToString() : string.Empty; versionEditor.buildTextBox.Text = parts.Length > 2 ? parts[2] : string.Empty;
versionEditor.revisionTextBox.Text = newVersion.Revision >= 0 ? newVersion.Revision.ToString() : string.Empty; versionEditor.revisionTextBox.Text = parts.Length > 3 ? parts[3] : string.Empty;
} }
} }
} }

Loading…
Cancel
Save