Browse Source

add VersionEditor control to Assembly Info panel for assembly versions editing

pull/631/head
olegbevz 11 years ago
parent
commit
8d24d35310
  1. 8
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  2. 14
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/AssemblyInfoPanel.xaml
  3. 19
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/VersionEditor.xaml
  4. 99
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/VersionEditor.xaml.cs
  5. 66
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AssemblyInfo/VersionToStringConverter.cs

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

@ -303,7 +303,9 @@ @@ -303,7 +303,9 @@
</Compile>
<Compile Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\AssemblyInfo\AssemblyInfoProvider.cs" />
<Compile Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\AssemblyInfo\AssemblyInfoViewModel.cs" />
<Compile Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\AssemblyInfo\VersionToStringConverter.cs" />
<Compile Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\AssemblyInfo\VersionEditor.xaml.cs">
<DependentUpon>VersionEditor.xaml</DependentUpon>
</Compile>
<Compile Include="Src\Gui\Pads\CompilerMessageView\MessageViewCategoryTextWriter.cs" />
<Compile Include="Src\Gui\Pads\TaskList\TaskViewResources.xaml.cs">
<DependentUpon>TaskViewResources.xaml</DependentUpon>
@ -915,6 +917,10 @@ @@ -915,6 +917,10 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\AssemblyInfo\VersionEditor.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\BuildAdvanced.xaml" />
<Page Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\BuildEvents.xaml" />
<Page Include="Src\Gui\Dialogs\OptionPanels\ProjectOptions\BuildOutput.xaml" />

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

@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:core="http://icsharpcode.net/sharpdevelop/core"
xmlns:optionPanels="clr-namespace:ICSharpCode.SharpDevelop.Gui.OptionPanels"
xmlns:projectOptions="clr-namespace:ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ProjectOptions"
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type={x:Type optionPanels:AssemblyInfoViewModel}}">
<ScrollViewer VerticalScrollBarVisibility="Auto">
@ -36,7 +37,10 @@ @@ -36,7 +37,10 @@
<Setter Property="Padding" Value="4,0,4,0"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<optionPanels:VersionToStringConverter x:Key="VersionToStringConverter"/>
<Style TargetType="{x:Type projectOptions:VersionEditor}">
<Setter Property="HorizontalAlignment" Value="Left"/>
<Setter Property="Width" Value="300"/>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
@ -84,14 +88,14 @@ @@ -84,14 +88,14 @@
<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"/>
<TextBox Text="{Binding AssemblyVersion, Converter={StaticResource VersionToStringConverter}, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="7"/>
<projectOptions:VersionEditor Version="{Binding AssemblyVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="7"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.FileVersion}" Grid.Column="0" Grid.Row="8"/>
<TextBox Text="{Binding AssemblyFileVersion, Converter={StaticResource VersionToStringConverter}, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="8"/>
<projectOptions:VersionEditor Version="{Binding AssemblyFileVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 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, Converter={StaticResource VersionToStringConverter}, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="9"/>
<projectOptions:VersionEditor Version="{Binding InformationalVersion, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="9"/>
<Label Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.GUID}" Grid.Column="0" Grid.Row="10"/>
<TextBox Text="{Binding Guid, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1" Grid.Row="10"/>
<Button Content="{core:Localize Dialog.ProjectOptions.AssemblyInfo.NewGUID}" Command="{Binding NewGuidCommand}" Grid.Column="2" Grid.Row="10"/>

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

@ -0,0 +1,19 @@ @@ -0,0 +1,19 @@
<UserControl x:Class="ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ProjectOptions.VersionEditor"
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"
mc:Ignorable="d">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<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"/>
</Grid>
</UserControl>

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

@ -0,0 +1,99 @@ @@ -0,0 +1,99 @@
// 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.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace ICSharpCode.SharpDevelop.Gui.Dialogs.OptionPanels.ProjectOptions
{
/// <summary>
/// Interaction logic for VersionEditor.xaml
/// </summary>
public partial class VersionEditor
{
public static DependencyProperty VersionProperty =
DependencyProperty.Register("Version", typeof(Version), typeof(VersionEditor), new PropertyMetadata(OnVersionChanged));
public VersionEditor()
{
InitializeComponent();
}
public Version Version
{
get { return GetValue(VersionProperty) as Version; }
set { SetValue(VersionProperty, value); }
}
private void OnTextBoxPreviewTextInput(object sender, TextCompositionEventArgs e)
{
// Block any non-character input
if (!e.Text.All(char.IsDigit))
{
e.Handled = true;
}
}
private void OnTextChanged(object sender, TextChangedEventArgs e)
{
// Get new Version class instance from textboxes
string majorPart = majorTextBox.Text;
string minorPart = minorTextBox.Text;
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);
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);
else
newVersion = new Version();
if (!newVersion.Equals(Version))
Version = newVersion;
}
private static void OnVersionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var versionEditor = d as VersionEditor;
var newVersion = e.NewValue as Version;
if (versionEditor != null && newVersion != null)
{
// 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;
}
}
}
}

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

@ -1,66 +0,0 @@ @@ -1,66 +0,0 @@
// 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.Windows;
using System.Windows.Data;
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
{
[ValueConversion(typeof(Version), typeof(string))]
public class VersionToStringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
try
{
var version = value as Version;
if (version != null)
return version.ToString();
return DependencyProperty.UnsetValue;
}
catch
{
return DependencyProperty.UnsetValue;
}
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
try
{
var versionString = value as string;
if (versionString != null)
{
Version version;
if (Version.TryParse(versionString, out version))
{
return version;
}
}
return DependencyProperty.UnsetValue;
}
catch
{
return DependencyProperty.UnsetValue;
}
}
}
}
Loading…
Cancel
Save