Browse Source

Allow user to choose configuration and platform in the project options. (part of SD2-425)

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@503 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
76d0e4da6c
  1. 2
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/OptionPanels/BuildOptions.cs
  2. 4
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Project/CSharpProject.cs
  3. 2
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/BuildOptions.cs
  4. 11
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/VBNetProject.cs
  5. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  6. 2
      src/Main/Base/Project/Src/Gui/ContentInterfaces/ICanBeDirty.cs
  7. 2
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AbstractBuildOptions.cs
  8. 2
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.cs
  9. 2
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/BuildEvents.cs
  10. 2
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/DebugOptions.cs
  11. 2
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ReferencePaths.cs
  12. 2
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/Signing.cs
  13. 289
      src/Main/Base/Project/Src/Project/AbstractProject.cs
  14. 86
      src/Main/Base/Project/Src/Project/ConfigurationGuiBinding.cs
  15. 186
      src/Main/Base/Project/Src/Project/ConfigurationGuiHelper.cs
  16. 6
      src/Main/Base/Project/Src/Project/IProject.cs
  17. 36
      src/Main/Base/Project/Src/Project/MSBuildEnums.cs
  18. 184
      src/Main/Base/Project/Src/Project/MSBuildProject.cs
  19. 16
      src/Main/Base/Project/Src/Project/PropertyGroup.cs
  20. BIN
      src/Main/StartUp/Project/Resources/StringResources.resources

2
src/AddIns/BackendBindings/CSharpBinding/Project/Src/OptionPanels/BuildOptions.cs

@ -45,6 +45,8 @@ namespace CSharpBinding.OptionPanels @@ -45,6 +45,8 @@ namespace CSharpBinding.OptionPanels
new StringPair("4096", "4096"),
new StringPair("8192", "8192"));
InitWarnings();
helper.AddConfigurationSelector(this);
}
}
}

4
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Project/CSharpProject.cs

@ -54,8 +54,8 @@ namespace CSharpBinding @@ -54,8 +54,8 @@ namespace CSharpBinding
{
base.Create(information);
imports.Add(@"$(MSBuildBinPath)\Microsoft.CSharp.Targets");
configurations["Debug|AnyCPU"]["CheckForOverflowUnderflow"] = "True";
configurations["Release|AnyCPU"]["CheckForOverflowUnderflow"] = "False";
SetProperty("Debug", null, "CheckForOverflowUnderflow", "True", PropertyStorageLocations.ConfigurationSpecific);
SetProperty("Release", null, "CheckForOverflowUnderflow", "False", PropertyStorageLocations.ConfigurationSpecific);
}
public override bool CanCompile(string fileName)

2
src/AddIns/BackendBindings/VBNetBinding/Project/Src/OptionPanels/BuildOptions.cs

@ -45,6 +45,8 @@ namespace VBNetBinding.OptionPanels @@ -45,6 +45,8 @@ namespace VBNetBinding.OptionPanels
InitXmlDoc();
InitAdvanced();
InitWarnings();
helper.AddConfigurationSelector(this);
}
public override bool StorePanelContents()

11
src/AddIns/BackendBindings/VBNetBinding/Project/Src/Project/VBNetProject.cs

@ -24,18 +24,9 @@ using ICSharpCode.Core; @@ -24,18 +24,9 @@ using ICSharpCode.Core;
namespace VBNetBinding
{
public enum WarningsAsErrors {
None,
Specific,
All
}
/// <summary>
/// Description of CSharpProject.
/// </summary>
public class VBNetProject : MSBuildProject
{
public override void SetProperty<T>(string configurationName, string platform, string property, T value, PropertyStorageLocation location)
public override void SetProperty<T>(string configurationName, string platform, string property, T value, PropertyStorageLocations location)
{
base.SetProperty(configurationName, platform, property, value, location);
if (property == "OutputType") {

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

@ -704,6 +704,7 @@ @@ -704,6 +704,7 @@
<Compile Include="Src\Gui\Components\StringListEditor.cs" />
<Compile Include="Src\Dom\Implementations\NullReturnType.cs" />
<Compile Include="Src\Dom\Implementations\AnonymousMethodReturnType.cs" />
<Compile Include="Src\Project\ConfigurationGuiBinding.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Libraries\DockPanel_Src\WinFormsUI\WinFormsUI.csproj">

2
src/Main/Base/Project/Src/Gui/ContentInterfaces/ICanBeDirty.cs

@ -10,7 +10,7 @@ using System; @@ -10,7 +10,7 @@ using System;
namespace ICSharpCode.SharpDevelop.Gui
{
/// <summary>
/// Description of ICanBeDirty.
/// Interface for classes that implement the IsDirty property and the DirtyChanged event.
/// </summary>
public interface ICanBeDirty
{

2
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/AbstractBuildOptions.cs

@ -87,7 +87,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -87,7 +87,7 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
if (bool.Parse(Get("false"))) {
all.Checked = true;
} else {
PropertyStorageLocation tmp;
PropertyStorageLocations tmp;
if (this.Helper.GetProperty("WarningsAsErrors", "", out tmp).Length > 0) {
specific.Checked = true;
} else {

2
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ApplicationSettings.cs

@ -53,6 +53,8 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -53,6 +53,8 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
Get<TextBox>("projectFile").ReadOnly = true;
RefreshOutputNameTextBox(null, EventArgs.Empty);
helper.AddConfigurationSelector(this);
}
void RefreshOutputNameTextBox(object sender, EventArgs e)

2
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/BuildEvents.cs

@ -33,6 +33,8 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -33,6 +33,8 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
helper.BindString("preBuildEventTextBox", "PreBuildEvent");
helper.BindString("postBuildEventTextBox", "PostBuildEvent");
helper.BindEnum<RunPostBuildEvent>("runPostBuildEventComboBox", "RunPostBuildEvent");
helper.AddConfigurationSelector(this);
}
}
}

2
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/DebugOptions.cs

@ -41,6 +41,8 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -41,6 +41,8 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
helper.BindString("workingDirectoryTextBox", "StartWorkingDirectory");
UpdateEnabledStates(this, EventArgs.Empty);
helper.AddConfigurationSelector(this);
}
void UpdateEnabledStates(object sender, EventArgs e)

2
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ReferencePaths.cs

@ -29,6 +29,8 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -29,6 +29,8 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
editor.ListChanged += delegate { IsDirty = true; };
helper.AddBinding("ReferencePath", new SemicolonSeparatedStringListBinding(editor));
this.Controls.Add(editor);
helper.AddConfigurationSelector(this);
}
public class SemicolonSeparatedStringListBinding : ConfigurationGuiBinding

2
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/ProjectOptions/Signing.cs

@ -53,6 +53,8 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels @@ -53,6 +53,8 @@ namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
helper.BindBoolean("delaySignOnlyCheckBox", "DelaySign", false);
UpdateEnabledStates(this, EventArgs.Empty);
helper.AddConfigurationSelector(this);
}
void FindKeys(string directory)

289
src/Main/Base/Project/Src/Project/AbstractProject.cs

@ -27,12 +27,60 @@ namespace ICSharpCode.SharpDevelop.Project @@ -27,12 +27,60 @@ namespace ICSharpCode.SharpDevelop.Project
protected Dictionary<string, PropertyGroup> configurations = new Dictionary<string, PropertyGroup>();
protected Dictionary<string, PropertyGroup> userConfigurations = new Dictionary<string, PropertyGroup>();
protected List<ProjectItem> items = new List<ProjectItem>();
protected List<string> imports = new List<string>();
protected List<ProjectItem> items = new List<ProjectItem>();
protected List<string> imports = new List<string>();
protected string fileName;
protected string language;
public string[] GetConfigurationNames()
{
List<string> configurationNames = new List<string>();
foreach (string key in configurations.Keys) {
int pos = key.IndexOf('|');
string configuration = key.Substring(0, pos);
if (configuration != "*" && !configurationNames.Contains(configuration)) {
configurationNames.Add(configuration);
}
}
foreach (string key in userConfigurations.Keys) {
int pos = key.IndexOf('|');
string configuration = key.Substring(0, pos);
if (configuration != "*" && !configurationNames.Contains(configuration)) {
configurationNames.Add(configuration);
}
}
if (!configurationNames.Contains(this.Configuration)) {
configurationNames.Add(this.Configuration);
}
configurationNames.Sort();
return configurationNames.ToArray();
}
public string[] GetPlatformNames()
{
List<string> platformNames = new List<string>();
foreach (string key in configurations.Keys) {
int pos = key.LastIndexOf('|');
string platform = key.Substring(pos + 1);
if (platform != "*" && !platformNames.Contains(platform)) {
platformNames.Add(platform);
}
}
foreach (string key in userConfigurations.Keys) {
int pos = key.LastIndexOf('|');
string platform = key.Substring(pos + 1);
if (platform != "*" && !platformNames.Contains(platform)) {
platformNames.Add(platform);
}
}
if (!platformNames.Contains(this.Platform)) {
platformNames.Add(this.Platform);
}
platformNames.Sort();
return platformNames.ToArray();
}
/// <summary>
/// Import options from an attribute collection. This is used to read the template options.
/// </summary>
@ -62,23 +110,21 @@ namespace ICSharpCode.SharpDevelop.Project @@ -62,23 +110,21 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
PropertyGroup baseConfiguration = new PropertyGroup();
[Browsable(false)]
public PropertyGroup BaseConfiguration {
get {
if (!configurations.ContainsKey("")) {
configurations[""] = new PropertyGroup();
}
return configurations[""];
return baseConfiguration;
}
}
PropertyGroup userBaseConfiguration = new PropertyGroup();
[Browsable(false)]
public PropertyGroup ActiveConfiguration {
public PropertyGroup UserBaseConfiguration {
get {
if (Platform != null && Platform.Length > 0) {
return configurations[Configuration + "|" + Platform];
}
return configurations[Configuration];
return userBaseConfiguration;
}
}
@ -286,121 +332,184 @@ namespace ICSharpCode.SharpDevelop.Project @@ -286,121 +332,184 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
/*
public string GetOutputPath(string configurationName, string platform)
public string GetProperty(string property)
{
return GetConfiguration(configurationName, platform)["OutputPath"];
return GetProperty(property, "");
}
public void SetOutputPath(string configurationName, string platform, string val)
public T GetProperty<T>(string property, T defaultValue)
{
GetConfiguration(configurationName, platform)["OutputPath"] = val;
PropertyStorageLocations tmp;
return GetProperty(this.Configuration, this.Platform, property, defaultValue, out tmp);
}
*/
public string GetProperty(string property)
public T GetProperty<T>(string configurationName, string platform, string property, T defaultValue, out PropertyStorageLocations location)
{
return GetProperty(property, "");
location = PropertyStorageLocations.UserFile;
PropertyGroup pg = FindProperty(configurationName, platform, property,
UserBaseConfiguration, userConfigurations, ref location);
if (pg != null) {
return pg.Get(property, defaultValue);
}
location = PropertyStorageLocations.Base;
pg = FindProperty(configurationName, platform, property,
BaseConfiguration, configurations, ref location);
if (pg != null) {
return pg.Get(property, defaultValue);
} else {
location = PropertyStorageLocations.Unknown;
return defaultValue;
}
}
public T GetProperty<T>(string property, T defaultValue)
public PropertyStorageLocations FindProperty(string configurationName, string platform, string property)
{
PropertyStorageLocation tmp;
return GetProperty(this.Configuration, this.Platform, property, defaultValue, out tmp);
PropertyStorageLocations location = PropertyStorageLocations.Unknown;
FindProperty(configurationName, platform, property,
UserBaseConfiguration, userConfigurations, ref location);
if (location != PropertyStorageLocations.Unknown) {
return location | PropertyStorageLocations.UserFile;
}
FindProperty(configurationName, platform, property,
BaseConfiguration, configurations, ref location);
return location;
}
public T GetProperty<T>(string configurationName, string platform, string property, T defaultValue, out PropertyStorageLocation location)
/// <summary>
/// Searches a property in a set of configurations (either project file OR user file).
/// Returns the property group that contains the property, or null, if it is not found.
/// The value of <paramref name="location"/> is OR'ed with PropertyStorageLocations.Base,
/// ConfigurationSpecific, PlatformSpecific, or not changed depending on if/where the property
/// was found.
/// </summary>
static PropertyGroup FindProperty(string configurationName, string platform,
string property,
PropertyGroup baseConfig, Dictionary<string, PropertyGroup> configurations,
ref PropertyStorageLocations location)
{
string configurationKey = platform != null ? configurationName + "|" + platform : configurationName;
PropertyGroup pg;
if (userConfigurations.TryGetValue(configurationKey, out pg)) {
if (pg.IsSet(property)) {
location = PropertyStorageLocation.UserSpecificConfiguration;
return pg.Get(property, defaultValue);
if (configurationName != null && platform != null) {
if (configurations.TryGetValue(configurationName + "|" + platform, out pg)) {
if (pg.IsSet(property)) {
location |= PropertyStorageLocations.ConfigurationAndPlatformSpecific;
return pg;
}
}
}
if (configurations.TryGetValue(configurationKey, out pg)) {
if (pg.IsSet(property)) {
location = PropertyStorageLocation.SpecificConfiguration;
return pg.Get(property, defaultValue);
if (configurationName != null) {
if (configurations.TryGetValue(configurationName + "|*", out pg)) {
if (pg.IsSet(property)) {
location |= PropertyStorageLocations.ConfigurationSpecific;
return pg;
}
}
}
if (platform != null) {
if (configurations.TryGetValue("*|" + platform, out pg)) {
if (pg.IsSet(property)) {
location |= PropertyStorageLocations.PlatformSpecific;
return pg;
}
}
}
if (BaseConfiguration.IsSet(property)) {
location = PropertyStorageLocation.BaseConfiguration;
return BaseConfiguration.Get(property, defaultValue);
if (baseConfig.IsSet(property)) {
location |= PropertyStorageLocations.Base;
return baseConfig;
}
location = PropertyStorageLocation.Unchanged;
return defaultValue;
return null;
}
public void SetProperty<T>(string property, T value)
{
SetProperty(this.Configuration, this.Platform, property, value, PropertyStorageLocation.Unchanged);
SetProperty(this.Configuration, this.Platform, property, value, PropertyStorageLocations.Unchanged);
}
public void SetProperty<T>(string property, T value, PropertyStorageLocation location)
public void SetProperty<T>(string property, T value, PropertyStorageLocations location)
{
SetProperty(this.Configuration, this.Platform, property, value, location);
}
public virtual void SetProperty<T>(string configurationName, string platform, string property, T value, PropertyStorageLocation location)
public virtual void SetProperty<T>(string configurationName, string platform, string property, T value, PropertyStorageLocations location)
{
string configurationKey = platform != null ? configurationName + "|" + platform : configurationName;
PropertyGroup pg;
// default value is default(T) except for strings, where it is string.Empty
T defaultValue = (typeof(T) == typeof(string)) ? (T)(object)string.Empty : default(T);
switch (location) {
case PropertyStorageLocation.Unchanged:
if (userConfigurations.TryGetValue(configurationKey, out pg)) {
if (pg.IsSet(property)) {
pg.Set(property, defaultValue, value);
return;
}
}
if (configurations.TryGetValue(configurationKey, out pg)) {
if (pg.IsSet(property)) {
pg.Set(property, defaultValue, value);
return;
}
}
BaseConfiguration.Set(property, defaultValue, value);
return;
case PropertyStorageLocation.BaseConfiguration:
if (!BaseConfiguration.IsSet(property)) {
RemoveProperty(configurations, property);
RemoveProperty(userConfigurations, property);
}
BaseConfiguration.Set(property, defaultValue, value);
return;
case PropertyStorageLocation.SpecificConfiguration:
if (BaseConfiguration.IsSet(property)) {
BaseConfiguration.Remove(property);
}
RemoveProperty(userConfigurations, property);
if (!configurations.TryGetValue(configurationKey, out pg)) {
configurations[configurationKey] = pg = new PropertyGroup();
}
pg.Set(property, defaultValue, value);
return;
case PropertyStorageLocation.UserSpecificConfiguration:
if (BaseConfiguration.IsSet(property)) {
BaseConfiguration.Remove(property);
}
RemoveProperty(configurations, property);
if (!userConfigurations.TryGetValue(configurationKey, out pg)) {
userConfigurations[configurationKey] = pg = new PropertyGroup();
}
pg.Set(property, defaultValue, value);
return;
if (location == PropertyStorageLocations.Unchanged) {
location = FindProperty(configurationName, platform, property);
if (location == PropertyStorageLocations.Unknown) {
location = PropertyStorageLocations.Base;
}
}
PropertyGroup baseConfiguration = this.BaseConfiguration;
Dictionary<string, PropertyGroup> configs = this.configurations;
if ((location & PropertyStorageLocations.UserFile) == PropertyStorageLocations.UserFile) {
baseConfiguration = this.UserBaseConfiguration;
configurations = this.userConfigurations;
}
PropertyGroup targetGroup;
switch (location & PropertyStorageLocations.ConfigurationAndPlatformSpecific) {
case PropertyStorageLocations.ConfigurationAndPlatformSpecific:
targetGroup = GetOrCreateGroup(configs, configurationName + "|" + platform);
break;
case PropertyStorageLocations.ConfigurationSpecific:
targetGroup = GetOrCreateGroup(configs, configurationName + "|*");
break;
case PropertyStorageLocations.PlatformSpecific:
targetGroup = GetOrCreateGroup(configs, "*|" + platform);
break;
default:
throw new InvalidEnumArgumentException("location", (int)location, typeof(PropertyStorageLocation));
targetGroup = baseConfiguration;
break;
}
if (!targetGroup.IsSet(property)) {
RemoveProperty(property, location); // clear property from other groups
}
targetGroup.Set(property, defaultValue, value);
}
static PropertyGroup GetOrCreateGroup(Dictionary<string, PropertyGroup> configs, string groupName)
{
PropertyGroup pg;
if (!configs.TryGetValue(groupName, out pg)) {
pg = new PropertyGroup();
configs.Add(groupName, pg);
}
return pg;
}
void RemoveProperty(string property, PropertyStorageLocations except)
{
if (except != PropertyStorageLocations.Base) {
if (BaseConfiguration.IsSet(property))
BaseConfiguration.Remove(property);
}
if (except != (PropertyStorageLocations.Base | PropertyStorageLocations.UserFile)) {
if (UserBaseConfiguration.IsSet(property))
UserBaseConfiguration.Remove(property);
}
RemoveProperty(property, except, configurations);
RemoveProperty(property, except, userConfigurations);
}
static void RemoveProperty(Dictionary<string, PropertyGroup> dict, string property)
static void RemoveProperty(string property, PropertyStorageLocations except, Dictionary<string, PropertyGroup> configs)
{
foreach (PropertyGroup pg in dict.Values) {
if (pg.IsSet(property)) {
pg.Remove(property);
except &= PropertyStorageLocations.ConfigurationAndPlatformSpecific;
foreach (KeyValuePair<string, PropertyGroup> pair in configs) {
if (pair.Value.IsSet(property)) {
// skip if this property group is in "except"
if (pair.Key.StartsWith("*|")) {
if (except == PropertyStorageLocations.PlatformSpecific) {
continue;
}
} else if (pair.Key.EndsWith("|*")) {
if (except == PropertyStorageLocations.ConfigurationSpecific) {
continue;
}
} else {
if (except == PropertyStorageLocations.ConfigurationAndPlatformSpecific) {
continue;
}
}
pair.Value.Remove(property);
}
}
}

86
src/Main/Base/Project/Src/Project/ConfigurationGuiBinding.cs

@ -0,0 +1,86 @@ @@ -0,0 +1,86 @@
// <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Windows.Forms;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.SharpDevelop.Project
{
public abstract class ConfigurationGuiBinding
{
ConfigurationGuiHelper helper;
string property;
public MSBuildProject Project {
get {
return helper.Project;
}
}
public ConfigurationGuiHelper Helper {
get {
return helper;
}
internal set {
helper = value;
}
}
public string Property {
get {
return property;
}
internal set {
property = value;
}
}
PropertyStorageLocations defaultLocation = PropertyStorageLocations.Base;
public PropertyStorageLocations DefaultLocation {
get {
return defaultLocation;
}
set {
defaultLocation = value;
}
}
PropertyStorageLocations location;
public PropertyStorageLocations Location {
get {
return location;
}
set {
location = value;
}
}
public T Get<T>(T defaultValue)
{
T result = helper.GetProperty(property, defaultValue, out location);
if (location == PropertyStorageLocations.Unknown) {
location = defaultLocation;
}
return result;
}
public void Set<T>(T value)
{
helper.SetProperty(property, value, location);
}
public abstract void Load();
public abstract bool Save();
}
}

186
src/Main/Base/Project/Src/Project/ConfigurationGuiHelper.cs

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
using ICSharpCode.Core;
@ -15,75 +16,6 @@ using ICSharpCode.SharpDevelop.Gui; @@ -15,75 +16,6 @@ using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.SharpDevelop.Project
{
public abstract class ConfigurationGuiBinding
{
ConfigurationGuiHelper helper;
string property;
public MSBuildProject Project {
get {
return helper.Project;
}
}
public ConfigurationGuiHelper Helper {
get {
return helper;
}
internal set {
helper = value;
}
}
public string Property {
get {
return property;
}
internal set {
property = value;
}
}
PropertyStorageLocation defaultLocation = PropertyStorageLocation.BaseConfiguration;
public PropertyStorageLocation DefaultLocation {
get {
return defaultLocation;
}
set {
defaultLocation = value;
}
}
PropertyStorageLocation location;
public PropertyStorageLocation Location {
get {
return location;
}
set {
location = value;
}
}
public T Get<T>(T defaultValue)
{
T result = helper.GetProperty(property, defaultValue, out location);
if (location == PropertyStorageLocation.Unchanged) {
location = defaultLocation;
}
return result;
}
public void Set<T>(T value)
{
helper.SetProperty(property, value, location);
}
public abstract void Load();
public abstract bool Save();
}
/// <summary>
/// Class that helps connecting configuration GUI controls to MsBuild properties.
/// </summary>
@ -97,8 +29,8 @@ namespace ICSharpCode.SharpDevelop.Project @@ -97,8 +29,8 @@ namespace ICSharpCode.SharpDevelop.Project
{
this.project = project;
this.controlDictionary = controlDictionary;
configuration = project.Configuration;
platform = project.Platform;
this.configuration = project.Configuration;
this.platform = project.Platform;
}
public MSBuildProject Project {
@ -107,12 +39,13 @@ namespace ICSharpCode.SharpDevelop.Project @@ -107,12 +39,13 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
public T GetProperty<T>(string property, T defaultValue, out PropertyStorageLocation location)
#region Manage bindings
public T GetProperty<T>(string property, T defaultValue, out PropertyStorageLocations location)
{
return project.GetProperty(configuration, platform, property, defaultValue, out location);
}
public void SetProperty<T>(string property, T value, PropertyStorageLocation location)
public void SetProperty<T>(string property, T value, PropertyStorageLocations location)
{
project.SetProperty(configuration, platform, property, value, location);
}
@ -129,6 +62,14 @@ namespace ICSharpCode.SharpDevelop.Project @@ -129,6 +62,14 @@ namespace ICSharpCode.SharpDevelop.Project
bindings.Add(binding);
}
public void Load()
{
foreach (ConfigurationGuiBinding binding in bindings) {
binding.Load();
}
IsDirty = false;
}
public bool Save()
{
foreach (ConfigurationGuiBinding binding in bindings) {
@ -488,5 +429,104 @@ namespace ICSharpCode.SharpDevelop.Project @@ -488,5 +429,104 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
#endregion
#endregion
/// <summary>
/// Gets the height of the configuration selector in pixel.
/// </summary>
public const int ConfigurationSelectorHeight = 30;
public Control CreateConfigurationSelector()
{
return new ConfigurationSelector(this);
}
public void AddConfigurationSelector(Control parent)
{
foreach (Control ctl in parent.Controls) {
ctl.Top += ConfigurationSelectorHeight;
}
Control sel = CreateConfigurationSelector();
sel.Width = parent.ClientSize.Width;
parent.Controls.Add(sel);
parent.Controls.SetChildIndex(sel, 0);
sel.Anchor |= AnchorStyles.Right;
}
sealed class ConfigurationSelector : Panel
{
ConfigurationGuiHelper helper;
Label configurationLabel = new Label();
ComboBox configurationComboBox = new ComboBox();
Label platformLabel = new Label();
ComboBox platformComboBox = new ComboBox();
Control line = new Control();
public ConfigurationSelector(ConfigurationGuiHelper helper)
{
const int marginTop = 4;
const int marginLeft = 4;
this.helper = helper;
this.Height = ConfigurationSelectorHeight;
configurationLabel.Text = StringParser.Parse("${res:Dialog.ProjectOptions.Configuration}:");
configurationLabel.TextAlign = ContentAlignment.MiddleRight;
configurationLabel.Location = new Point(marginLeft, marginTop);
configurationLabel.Width = 80;
configurationComboBox.Location = new Point(4 + configurationLabel.Right, marginTop);
configurationComboBox.Width = 120;
configurationComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
platformLabel.Text = StringParser.Parse("${res:Dialog.ProjectOptions.Platform}:");
platformLabel.TextAlign = ContentAlignment.MiddleRight;
platformLabel.Location = new Point(4 + configurationComboBox.Right, marginTop);
platformLabel.Width = 68;
platformComboBox.Location = new Point(4 + platformLabel.Right, marginTop);
platformComboBox.Width = 120;
platformComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
line.Bounds = new Rectangle(marginLeft, ConfigurationSelectorHeight - 2, Width - marginLeft * 2, ConfigurationSelectorHeight - 2);
line.BackColor = SystemColors.ControlDark;
this.Controls.AddRange(new Control[] { configurationLabel, configurationComboBox, platformLabel, platformComboBox, line });
line.Anchor |= AnchorStyles.Right;
FillBoxes();
configurationComboBox.SelectedIndexChanged += ConfigurationChanged;
platformComboBox.SelectedIndexChanged += ConfigurationChanged;
}
void FillBoxes()
{
configurationComboBox.Items.Clear();
configurationComboBox.Items.AddRange(helper.Project.GetConfigurationNames());
platformComboBox.Items.Clear();
platformComboBox.Items.AddRange(helper.Project.GetPlatformNames());
ResetIndex();
}
bool resettingIndex;
void ResetIndex()
{
resettingIndex = true;
configurationComboBox.SelectedIndex = configurationComboBox.Items.IndexOf(helper.Configuration);
platformComboBox.SelectedIndex = platformComboBox.Items.IndexOf(helper.Platform);
resettingIndex = false;
}
void ConfigurationChanged(object sender, EventArgs e)
{
if (resettingIndex) return;
if (helper.IsDirty) {
if (!MessageService.AskQuestion("${res:Dialog.ProjectOptions.ContinueSwitchConfiguration}")) {
ResetIndex();
return;
}
if (!helper.Save()) {
ResetIndex();
return;
}
}
helper.Configuration = (string)configurationComboBox.SelectedItem;
helper.Platform = (string)platformComboBox.SelectedItem;
helper.Load();
}
}
}
}

6
src/Main/Base/Project/Src/Project/IProject.cs

@ -22,14 +22,10 @@ namespace ICSharpCode.SharpDevelop.Project @@ -22,14 +22,10 @@ namespace ICSharpCode.SharpDevelop.Project
Library,
[Description("${res:Dialog.Options.PrjOptions.Configuration.CompileTarget.Module}")]
Module
};
}
public interface IProject : ISolutionFolder, IDisposable, IMementoCapable
{
PropertyGroup BaseConfiguration {
get;
}
List<ProjectItem> Items {
get;
}

36
src/Main/Base/Project/Src/Project/MSBuildEnums.cs

@ -37,24 +37,38 @@ namespace ICSharpCode.SharpDevelop.Project @@ -37,24 +37,38 @@ namespace ICSharpCode.SharpDevelop.Project
/// <summary>
/// Specifies the possible locations where a property can be stored.
/// </summary>
public enum PropertyStorageLocation
[Flags]
public enum PropertyStorageLocations
{
Unchanged,
/// <summary>
/// Store the property where the property was previously stored.
/// This is the same value as <see cref="Unknown"/>.
/// </summary>
Unchanged = 0,
/// <summary>
/// Returned from GetProperty/FindProperty when the property does not exist.
/// This is the same value as <see cref="Unchanged"/>.
/// </summary>
Unknown = 0,
/// <summary>
/// Store the property globally for all configurations in the project file.
/// </summary>
BaseConfiguration,
Base = 1,
/// <summary>
/// Store the property in the configuration-specific section.
/// </summary>
ConfigurationSpecific = 2,
/// <summary>
/// Store the property in the platform-specific section.
/// </summary>
PlatformSpecific = 4,
/// <summary>
/// Store the property in the configuration-specific section(s) in the project file.
/// The combination of the ConfigurationSpecific and PlatformSpecific flags.
/// </summary>
SpecificConfiguration,
///// <summary>
///// Store the property globally for all configurations in the user file.
///// </summary>
//UserBaseConfiguration,
ConfigurationAndPlatformSpecific = ConfigurationSpecific | PlatformSpecific,
/// <summary>
/// Store the property in the configuration-specific section(s) in the user file.
/// Store the property in the user file.
/// </summary>
UserSpecificConfiguration,
UserFile = 8
}
}

184
src/Main/Base/Project/Src/Project/MSBuildProject.cs

@ -23,16 +23,17 @@ namespace ICSharpCode.SharpDevelop.Project @@ -23,16 +23,17 @@ namespace ICSharpCode.SharpDevelop.Project
{
public class MSBuildProject : AbstractProject
{
List<string> unknownXmlSections = new List<string>();
List<string> userUnknownXmlSections = new List<string>();
protected char BuildConstantSeparator = ';';
public MSBuildProject()
{
}
protected char BuildConstantSeparator = ';';
protected virtual void Create(ProjectCreateInformation information)
{
Name = information.ProjectName;
configurations[""] = new PropertyGroup();
IdGuid = "{" + Guid.NewGuid().ToString().ToUpper() + "}";
BaseConfiguration["OutputType"] = "Exe";
BaseConfiguration["RootNamespace"] = information.ProjectName;
@ -42,19 +43,19 @@ namespace ICSharpCode.SharpDevelop.Project @@ -42,19 +43,19 @@ namespace ICSharpCode.SharpDevelop.Project
BaseConfiguration["Platform"] = "AnyCPU";
BaseConfiguration.SetIsGuarded("Platform", true);
configurations["Debug|AnyCPU"] = new PropertyGroup();
configurations["Debug|AnyCPU"]["OutputPath"] = @"bin\Debug\";
configurations["Debug|AnyCPU"]["Optimize"] = "False";
configurations["Debug|AnyCPU"]["DefineConstants"] = "DEBUG" + BuildConstantSeparator + "TRACE";
configurations["Debug|AnyCPU"]["DebugSymbols"] = "True";
configurations["Debug|AnyCPU"]["DebugType"] = "Full";
configurations["Debug|*"] = new PropertyGroup();
configurations["Debug|*"]["OutputPath"] = @"bin\Debug\";
configurations["Debug|*"]["Optimize"] = "False";
configurations["Debug|*"]["DefineConstants"] = "DEBUG" + BuildConstantSeparator + "TRACE";
configurations["Debug|*"]["DebugSymbols"] = "True";
configurations["Debug|*"]["DebugType"] = "Full";
configurations["Release|AnyCPU"] = new PropertyGroup();
configurations["Release|AnyCPU"]["OutputPath"] = @"bin\Release\";
configurations["Release|AnyCPU"]["Optimize"] = "True";
configurations["Release|AnyCPU"]["DefineConstants"] = "TRACE";
configurations["Release|AnyCPU"]["DebugSymbols"] = "False";
configurations["Release|AnyCPU"]["DebugType"] = "None";
configurations["Release|*"] = new PropertyGroup();
configurations["Release|*"]["OutputPath"] = @"bin\Release\";
configurations["Release|*"]["Optimize"] = "True";
configurations["Release|*"]["DefineConstants"] = "TRACE";
configurations["Release|*"]["DebugSymbols"] = "False";
configurations["Release|*"]["DebugType"] = "None";
fileName = information.OutputProjectFileName;
}
@ -65,14 +66,14 @@ namespace ICSharpCode.SharpDevelop.Project @@ -65,14 +66,14 @@ namespace ICSharpCode.SharpDevelop.Project
}
#region Xml reading routines
static PropertyGroup ReadPropertyGroup(XmlTextReader reader)
static PropertyGroup ReadPropertyGroup(XmlReader reader)
{
PropertyGroup properties = new PropertyGroup();
PropertyGroup.ReadProperties(reader, properties, "PropertyGroup");
return properties;
}
readonly static Regex configurationRegEx = new Regex(@"\s*'.*'\s*==\s*'(?<configuration>.*)'", RegexOptions.Compiled);
readonly static Regex configurationRegEx = new Regex(@"\s*'(?<property>[^']*)'\s*==\s*'(?<value>[^']*)'", RegexOptions.Compiled);
protected void SetupProject(string projectFileName)
{
@ -85,29 +86,11 @@ namespace ICSharpCode.SharpDevelop.Project @@ -85,29 +86,11 @@ namespace ICSharpCode.SharpDevelop.Project
SetupProject(projectFileName);
return;
}
do {
while (reader.Read()) {
if (reader.IsStartElement()) {
switch (reader.LocalName) {
case "PropertyGroup":
string condition = reader.GetAttribute("Condition");
PropertyGroup propertyGroup = ReadPropertyGroup(reader);
if (condition == null) {
condition = String.Empty;
}
string configuration;
Match match = configurationRegEx.Match(condition);
if (match.Success) {
configuration = match.Result("${configuration}");
} else {
configuration = condition;
}
if (!configurations.ContainsKey(configuration)) {
configurations[configuration] = propertyGroup;
} else {
configurations[configuration].Merge(propertyGroup);
}
LoadPropertyGroup(reader, false);
break;
case "ItemGroup":
ProjectItem.ReadItemGroup(reader, this, Items);
@ -116,36 +99,26 @@ namespace ICSharpCode.SharpDevelop.Project @@ -116,36 +99,26 @@ namespace ICSharpCode.SharpDevelop.Project
string import = reader.GetAttribute("Project");
Imports.Add(import);
break;
default:
unknownXmlSections.Add(reader.ReadOuterXml());
break;
}
}
} while (reader.Read());
}
}
string userSettingsFileName = projectFileName + ".user";
if (File.Exists(userSettingsFileName)) {
using (XmlTextReader reader = new XmlTextReader(userSettingsFileName)) {
reader.Read();
while (reader.Read()){
if (reader.IsStartElement()) {
switch (reader.LocalName) {
case "PropertyGroup":
string condition = reader.GetAttribute("Condition");
PropertyGroup propertyGroup = ReadPropertyGroup(reader);
if (condition == null) {
condition = String.Empty;
}
string configuration;
Match match = configurationRegEx.Match(condition);
if (match.Success) {
configuration = match.Result("${configuration}");
} else {
configuration = condition;
}
if (!userConfigurations.ContainsKey(configuration)) {
userConfigurations[configuration] = propertyGroup;
} else {
userConfigurations[configuration].Merge(propertyGroup);
}
LoadPropertyGroup(reader, true);
break;
default:
userUnknownXmlSections.Add(reader.ReadOuterXml());
break;
}
}
@ -154,6 +127,47 @@ namespace ICSharpCode.SharpDevelop.Project @@ -154,6 +127,47 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
void LoadPropertyGroup(XmlReader reader, bool isUserFile)
{
string condition = reader.GetAttribute("Condition");
if (condition == null) {
if (isUserFile)
UserBaseConfiguration.Merge(ReadPropertyGroup(reader));
else
BaseConfiguration.Merge(ReadPropertyGroup(reader));
return;
}
Match match = configurationRegEx.Match(condition);
if (match.Success) {
Dictionary<string, PropertyGroup> configurations = isUserFile ? this.userConfigurations : this.configurations;
string conditionProperty = match.Result("${property}");
string configuration = match.Result("${value}");
if (conditionProperty == "$(Configuration)|$(Platform)") {
// configuration is ok
} else if (conditionProperty == "$(Configuration)") {
configuration += "|*";
} else if (conditionProperty == "$(Platform)") {
configuration = "*|" + configuration;
} else {
configuration = null;
}
if (configuration != null) {
PropertyGroup propertyGroup = ReadPropertyGroup(reader);
if (!configurations.ContainsKey(configuration)) {
configurations[configuration] = propertyGroup;
} else {
configurations[configuration].Merge(propertyGroup);
}
return;
}
}
if (isUserFile)
userUnknownXmlSections.Add(reader.ReadOuterXml());
else
unknownXmlSections.Add(reader.ReadOuterXml());
}
public override void Save(string fileName)
{
string outputDirectory = Path.GetDirectoryName(fileName);
@ -169,18 +183,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -169,18 +183,7 @@ namespace ICSharpCode.SharpDevelop.Project
writer.WriteAttributeString("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
BaseConfiguration["ProjectGuid"] = IdGuid;
foreach (KeyValuePair<string, PropertyGroup> entry in configurations) {
writer.WriteStartElement("PropertyGroup");
if (entry.Key != null && entry.Key.Length > 0) {
if (entry.Key.Contains("|")) {
writer.WriteAttributeString("Condition", " '$(Configuration)|$(Platform)' == '" + entry.Key + "' ");
} else {
writer.WriteAttributeString("Condition", " '$(Configuration)' == '" + entry.Key + "' ");
}
}
entry.Value.WriteProperties(writer);
writer.WriteEndElement();
}
SaveProperties(writer, BaseConfiguration, configurations);
List<ProjectItem> references = new List<ProjectItem>();
List<ProjectItem> imports = new List<ProjectItem>();
@ -222,6 +225,8 @@ namespace ICSharpCode.SharpDevelop.Project @@ -222,6 +225,8 @@ namespace ICSharpCode.SharpDevelop.Project
ProjectItem.WriteItemGroup(writer, other);
}
SaveUnknownXmlSections(writer, unknownXmlSections);
foreach (string import in Imports) {
writer.WriteStartElement("Import");
writer.WriteAttributeString("Project", import);
@ -231,30 +236,45 @@ namespace ICSharpCode.SharpDevelop.Project @@ -231,30 +236,45 @@ namespace ICSharpCode.SharpDevelop.Project
writer.WriteEndElement();
}
if (userConfigurations.Count > 0) {
string userSettingsFileName = fileName + ".user";
string userSettingsFileName = fileName + ".user";
if (userConfigurations.Count > 0 || UserBaseConfiguration.PropertyCount > 0 || File.Exists(userSettingsFileName)) {
using (XmlTextWriter writer = new XmlTextWriter(userSettingsFileName, Encoding.UTF8)) {
writer.Formatting = Formatting.Indented;
writer.WriteStartElement("Project");
writer.WriteAttributeString("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
foreach (KeyValuePair<string, PropertyGroup> entry in userConfigurations) {
writer.WriteStartElement("PropertyGroup");
if (entry.Key != null && entry.Key.Length > 0) {
if (entry.Key.Contains("|")) {
writer.WriteAttributeString("Condition", " '$(Configuration)|$(Platform)' == '" + entry.Key + "' ");
} else {
writer.WriteAttributeString("Condition", " '$(Configuration)' == '" + entry.Key + "' ");
}
}
entry.Value.WriteProperties(writer);
writer.WriteEndElement();
}
SaveProperties(writer, UserBaseConfiguration, userConfigurations);
SaveUnknownXmlSections(writer, userUnknownXmlSections);
writer.WriteEndElement();
}
}
}
static void SaveProperties(XmlWriter writer, PropertyGroup baseConfiguration, Dictionary<string, PropertyGroup> configurations)
{
writer.WriteStartElement("PropertyGroup");
baseConfiguration.WriteProperties(writer);
writer.WriteEndElement();
foreach (KeyValuePair<string, PropertyGroup> entry in configurations) {
writer.WriteStartElement("PropertyGroup");
if (entry.Key.StartsWith("*|")) {
writer.WriteAttributeString("Condition", " '$(Platform)' == '" + entry.Key.Substring(2) + "' ");
} else if (entry.Key.EndsWith("|*")) {
writer.WriteAttributeString("Condition", " '$(Configuration)' == '" + entry.Key.Substring(0, entry.Key.Length - 2) + "' ");
} else {
writer.WriteAttributeString("Condition", " '$(Configuration)|$(Platform)' == '" + entry.Key + "' ");
}
entry.Value.WriteProperties(writer);
writer.WriteEndElement();
}
}
static void SaveUnknownXmlSections(XmlWriter writer, List<string> unknownElements)
{
}
#endregion
#region Start / Run

16
src/Main/Base/Project/Src/Project/PropertyGroup.cs

@ -22,6 +22,15 @@ namespace ICSharpCode.SharpDevelop.Project @@ -22,6 +22,15 @@ namespace ICSharpCode.SharpDevelop.Project
Dictionary<string, bool> isGuardedProperty = new Dictionary<string, bool>();
Dictionary<string, string> properties = new Dictionary<string, string>();
/// <summary>
/// Gets the number of properties in this group.
/// </summary>
public int PropertyCount {
get {
return properties.Count;
}
}
public string this[string property] {
get {
return Get(property, String.Empty);
@ -89,6 +98,9 @@ namespace ICSharpCode.SharpDevelop.Project @@ -89,6 +98,9 @@ namespace ICSharpCode.SharpDevelop.Project
foreach (KeyValuePair<string, string> entry in group.properties) {
properties[entry.Key] = entry.Value;
}
foreach (KeyValuePair<string, bool> entry in group.isGuardedProperty) {
isGuardedProperty[entry.Key] = entry.Value;
}
}
public override string ToString()
@ -105,7 +117,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -105,7 +117,7 @@ namespace ICSharpCode.SharpDevelop.Project
return sb.ToString();
}
internal static void ReadProperties(XmlTextReader reader, PropertyGroup properties, string endElement)
internal static void ReadProperties(XmlReader reader, PropertyGroup properties, string endElement)
{
if (reader.IsEmptyElement) {
return;
@ -138,7 +150,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -138,7 +150,7 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
internal void WriteProperties(XmlTextWriter writer)
internal void WriteProperties(XmlWriter writer)
{
foreach (KeyValuePair<string, string> entry in properties) {
writer.WriteStartElement(entry.Key);

BIN
src/Main/StartUp/Project/Resources/StringResources.resources

Binary file not shown.
Loading…
Cancel
Save