Browse Source

Implemented SD2-1212: Solution configuration editor

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2120 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 19 years ago
parent
commit
2be71f98f3
  1. BIN
      data/resources/StringResources.cz.resources
  2. BIN
      data/resources/StringResources.de.resources
  3. BIN
      data/resources/StringResources.es-mx.resources
  4. BIN
      data/resources/StringResources.es.resources
  5. BIN
      data/resources/StringResources.hu.resources
  6. BIN
      data/resources/StringResources.nl.resources
  7. BIN
      data/resources/StringResources.pt-br.resources
  8. 4
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  9. 2
      src/Main/Base/Project/Src/Commands/BuildCommands.cs
  10. 145
      src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/AddNewConfigurationDialog.Designer.cs
  11. 88
      src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/AddNewConfigurationDialog.cs
  12. 1
      src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/EditAvailableConfigurationsDialog.Designer.cs
  13. 131
      src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/EditAvailableConfigurationsDialog.cs
  14. 46
      src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/SolutionConfigurationEditor.Designer.cs
  15. 103
      src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/SolutionConfigurationEditor.cs
  16. 19
      src/Main/Base/Project/Src/Project/IProject.cs
  17. 222
      src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs
  18. 305
      src/Main/Base/Project/Src/Project/Solution/Solution.cs
  19. BIN
      src/Main/StartUp/Project/Resources/StringResources.resources

BIN
data/resources/StringResources.cz.resources

Binary file not shown.

BIN
data/resources/StringResources.de.resources

Binary file not shown.

BIN
data/resources/StringResources.es-mx.resources

Binary file not shown.

BIN
data/resources/StringResources.es.resources

Binary file not shown.

BIN
data/resources/StringResources.hu.resources

Binary file not shown.

BIN
data/resources/StringResources.nl.resources

Binary file not shown.

BIN
data/resources/StringResources.pt-br.resources

Binary file not shown.

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

@ -54,6 +54,10 @@ @@ -54,6 +54,10 @@
<Reference Include="Microsoft.Build.Engine" />
</ItemGroup>
<ItemGroup>
<Compile Include="Src\Gui\Dialogs\SolutionConfiguration\AddNewConfigurationDialog.cs" />
<Compile Include="Src\Gui\Dialogs\SolutionConfiguration\AddNewConfigurationDialog.Designer.cs">
<DependentUpon>AddNewConfigurationDialog.cs</DependentUpon>
</Compile>
<Compile Include="Src\Internal\ExternalTool\ExternalTool.cs" />
<Compile Include="Src\Internal\Templates\CodeTemplate.cs" />
<Compile Include="Src\Internal\Templates\Project\ProjectTemplate.cs" />

2
src/Main/Base/Project/Src/Commands/BuildCommands.cs

@ -234,7 +234,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands @@ -234,7 +234,7 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
{
using (SolutionConfigurationEditor sce = new SolutionConfigurationEditor()) {
sce.ShowDialog();
ProjectService.OpenSolution.Save();
ProjectService.SaveSolution();
ProjectService.OpenSolution.ApplySolutionConfigurationAndPlatformToProjects();
ProjectBrowserPad.Instance.ProjectBrowserControl.RefreshView();
}

145
src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/AddNewConfigurationDialog.Designer.cs generated

@ -0,0 +1,145 @@ @@ -0,0 +1,145 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision: 1965 $</version>
// </file>
namespace ICSharpCode.SharpDevelop.Gui
{
partial class AddNewConfigurationDialog : System.Windows.Forms.Form
{
/// <summary>
/// Designer variable used to keep track of non-visual components.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Disposes resources used by the form.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.nameTextBox = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.copyFromComboBox = new System.Windows.Forms.ComboBox();
this.createInAllCheckBox = new System.Windows.Forms.CheckBox();
this.okButton = new System.Windows.Forms.Button();
this.cancelButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(237, 23);
this.label1.TabIndex = 0;
this.label1.Text = "${res:Dialog.NewProject.NameLabelText}";
//
// nameTextBox
//
this.nameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.nameTextBox.Location = new System.Drawing.Point(12, 26);
this.nameTextBox.Name = "nameTextBox";
this.nameTextBox.Size = new System.Drawing.Size(237, 20);
this.nameTextBox.TabIndex = 1;
//
// label2
//
this.label2.Location = new System.Drawing.Point(12, 49);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(237, 23);
this.label2.TabIndex = 2;
this.label2.Text = "Copy &settings from:";
//
// copyFromComboBox
//
this.copyFromComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.copyFromComboBox.FormattingEnabled = true;
this.copyFromComboBox.Location = new System.Drawing.Point(12, 65);
this.copyFromComboBox.Name = "copyFromComboBox";
this.copyFromComboBox.Size = new System.Drawing.Size(237, 21);
this.copyFromComboBox.TabIndex = 3;
//
// createInAllCheckBox
//
this.createInAllCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.createInAllCheckBox.Location = new System.Drawing.Point(12, 92);
this.createInAllCheckBox.Name = "createInAllCheckBox";
this.createInAllCheckBox.Size = new System.Drawing.Size(237, 24);
this.createInAllCheckBox.TabIndex = 4;
this.createInAllCheckBox.Text = "&Create this configuration in all projects";
this.createInAllCheckBox.UseVisualStyleBackColor = true;
//
// okButton
//
this.okButton.Enabled = false;
this.okButton.Location = new System.Drawing.Point(93, 127);
this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(75, 23);
this.okButton.TabIndex = 5;
this.okButton.Text = "${res:Global.OKButtonText}";
this.okButton.UseVisualStyleBackColor = true;
this.okButton.Click += new System.EventHandler(this.OkButtonClick);
//
// cancelButton
//
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.Location = new System.Drawing.Point(174, 127);
this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 23);
this.cancelButton.TabIndex = 6;
this.cancelButton.Text = "${res:Global.CancelButtonText}";
this.cancelButton.UseVisualStyleBackColor = true;
//
// AddNewConfigurationDialog
//
this.AcceptButton = this.okButton;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(263, 162);
this.Controls.Add(this.cancelButton);
this.Controls.Add(this.okButton);
this.Controls.Add(this.createInAllCheckBox);
this.Controls.Add(this.copyFromComboBox);
this.Controls.Add(this.label2);
this.Controls.Add(this.nameTextBox);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "AddNewConfigurationDialog";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "AddNewConfigurationDialog";
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.Button okButton;
private System.Windows.Forms.CheckBox createInAllCheckBox;
private System.Windows.Forms.ComboBox copyFromComboBox;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox nameTextBox;
private System.Windows.Forms.Label label1;
}
}

88
src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/AddNewConfigurationDialog.cs

@ -0,0 +1,88 @@ @@ -0,0 +1,88 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Gui
{
/// <summary>
/// Dialog for adding a new configuration or platform to a solution or project.
/// </summary>
public partial class AddNewConfigurationDialog
{
Predicate<string> checkNameValid;
public AddNewConfigurationDialog(bool solution, bool editPlatforms,
IEnumerable<string> availableSourceItems,
Predicate<string> checkNameValid)
{
this.checkNameValid = checkNameValid;
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
foreach (Control ctl in this.Controls) {
ctl.Text = StringParser.Parse(ctl.Text);
}
createInAllCheckBox.Visible = solution;
nameTextBox.TextChanged += delegate {
okButton.Enabled = nameTextBox.TextLength > 0;
};
copyFromComboBox.Items.Add("<Empty>");
copyFromComboBox.Items.AddRange(Linq.ToArray(availableSourceItems));
copyFromComboBox.SelectedIndex = 0;
if (solution) {
if (editPlatforms)
this.Text = "Add Solution Platform";
else
this.Text = "Add Solution Configuration";
} else {
if (editPlatforms)
this.Text = "Add Project Platform";
else
this.Text = "Add Project Configuration";
}
}
public bool CreateInAllProjects {
get {
return createInAllCheckBox.Checked;
}
}
public string CopyFrom {
get {
if (copyFromComboBox.SelectedIndex <= 0)
return null;
else
return copyFromComboBox.SelectedItem.ToString();
}
}
public string NewName {
get {
return nameTextBox.Text;
}
}
void OkButtonClick(object sender, EventArgs e)
{
if (checkNameValid(nameTextBox.Text)) {
this.DialogResult = DialogResult.OK;
Close();
}
}
}
}

1
src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/EditAvailableConfigurationsDialog.Designer.cs generated

@ -110,6 +110,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -110,6 +110,7 @@ namespace ICSharpCode.SharpDevelop.Gui
this.Controls.Add(this.listBox);
this.MinimumSize = new System.Drawing.Size(230, 165);
this.Name = "EditAvailableConfigurationsDialog";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "EditAvailableConfigurationsDialog";
this.ResumeLayout(false);

131
src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/EditAvailableConfigurationsDialog.cs

@ -21,12 +21,29 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -21,12 +21,29 @@ namespace ICSharpCode.SharpDevelop.Gui
IProject project;
bool editPlatforms;
private EditAvailableConfigurationsDialog()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
foreach (Control ctl in this.Controls) {
ctl.Text = StringParser.Parse(ctl.Text);
}
}
public EditAvailableConfigurationsDialog(Solution solution, bool editPlatforms)
: this()
{
this.solution = solution;
this.editPlatforms = editPlatforms;
InitList();
if (editPlatforms)
this.Text = "Edit Solution Platforms";
else
this.Text = "Edit Solution Configurations";
}
public EditAvailableConfigurationsDialog(IProject project, bool editPlatforms)
@ -36,6 +53,11 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -36,6 +53,11 @@ namespace ICSharpCode.SharpDevelop.Gui
this.solution = project.ParentSolution;
this.editPlatforms = editPlatforms;
InitList();
if (editPlatforms)
this.Text = "Edit Project Platforms";
else
this.Text = "Edit Project Configurations";
}
void InitList()
@ -66,18 +88,6 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -66,18 +88,6 @@ namespace ICSharpCode.SharpDevelop.Gui
listBox.SelectedIndex = Math.Max(Array.IndexOf(array, activeItem), 0);
}
private EditAvailableConfigurationsDialog()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
foreach (Control ctl in this.Controls) {
ctl.Text = StringParser.Parse(ctl.Text);
}
}
void RemoveButtonClick(object sender, EventArgs e)
{
if (listBox.Items.Count == 1) {
@ -92,23 +102,33 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -92,23 +102,33 @@ namespace ICSharpCode.SharpDevelop.Gui
} else {
Remove(solution, name, editPlatforms);
}
InitList();
}
}
static void Remove(IProject project, string name, bool isPlatform)
{
throw new NotImplementedException();
if (isPlatform) {
project.ParentSolution.RemoveProjectPlatform(project, name);
} else {
project.ParentSolution.RemoveProjectConfiguration(project, name);
}
}
static void Remove(Solution solution, string name, bool isPlatform)
{
throw new NotImplementedException();
if (isPlatform) {
solution.RemoveSolutionPlatform(name);
} else {
solution.RemoveSolutionConfiguration(name);
}
}
void RenameButtonClick(object sender, EventArgs e)
{
string oldName = listBox.SelectedItem.ToString();
string newName = MessageService.ShowInputBox("Rename", "Enter the new name:", oldName);
string newName = MessageService.ShowInputBox("${res:SharpDevelop.Refactoring.Rename}",
"Enter the new name:", oldName);
if (string.IsNullOrEmpty(newName) || newName == oldName)
return;
if (!EnsureCorrectName(ref newName))
@ -118,8 +138,14 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -118,8 +138,14 @@ namespace ICSharpCode.SharpDevelop.Gui
} else {
if (editPlatforms) {
solution.RenameSolutionPlatform(oldName, newName);
if (solution.Preferences.ActivePlatform == oldName) {
solution.Preferences.ActivePlatform = newName;
}
} else {
solution.RenameSolutionConfiguration(oldName, newName);
if (solution.Preferences.ActiveConfiguration == oldName) {
solution.Preferences.ActiveConfiguration = newName;
}
}
// Solution platform name => project platform name
foreach (IProject p in solution.Projects) {
@ -131,11 +157,15 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -131,11 +157,15 @@ namespace ICSharpCode.SharpDevelop.Gui
void Rename(IProject project, string oldName, string newName)
{
}
void AddButtonClick(object sender, EventArgs e)
{
throw new NotImplementedException();
if (editPlatforms) {
if (project.PlatformNames.Contains(newName))
return;
solution.RenameProjectPlatform(project, oldName, newName);
} else {
if (project.ConfigurationNames.Contains(newName))
return;
solution.RenameProjectConfiguration(project, oldName, newName);
}
}
bool EnsureCorrectName(ref string newName)
@ -143,11 +173,14 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -143,11 +173,14 @@ namespace ICSharpCode.SharpDevelop.Gui
newName = newName.Trim();
if (editPlatforms && string.Equals(newName, "AnyCPU", StringComparison.InvariantCultureIgnoreCase))
newName = "Any CPU";
if (listBox.Items.Contains(newName)) {
MessageService.ShowMessage("Duplicate name.");
return false;
foreach (string item in listBox.Items) {
if (string.Equals(item, newName, StringComparison.InvariantCultureIgnoreCase)) {
MessageService.ShowMessage("Duplicate name.");
return false;
}
}
if (!FileUtility.IsValidDirectoryName(newName)
if (MSBuildInternals.Escape(newName) != newName
|| !FileUtility.IsValidDirectoryName(newName)
|| newName.Contains("'"))
{
MessageService.ShowMessage("The name was invalid.");
@ -155,5 +188,55 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -155,5 +188,55 @@ namespace ICSharpCode.SharpDevelop.Gui
}
return true;
}
void AddButtonClick(object sender, EventArgs e)
{
IEnumerable<string> availableSourceItems;
if (project != null) {
if (editPlatforms) {
availableSourceItems = project.PlatformNames;
} else {
availableSourceItems = project.ConfigurationNames;
}
} else {
if (editPlatforms) {
availableSourceItems = solution.GetPlatformNames();
} else {
availableSourceItems = solution.GetConfigurationNames();
}
}
using (AddNewConfigurationDialog dlg = new AddNewConfigurationDialog
(project == null, editPlatforms,
availableSourceItems,
delegate (string name) { return EnsureCorrectName(ref name); }
))
{
if (dlg.ShowDialog(this) == DialogResult.OK) {
string newName = dlg.NewName;
// fix up the new name
if (!EnsureCorrectName(ref newName))
return;
if (project != null) {
IProjectAllowChangeConfigurations pacc = project as IProjectAllowChangeConfigurations;
if (pacc != null) {
if (editPlatforms) {
pacc.AddProjectPlatform(newName, dlg.CopyFrom);
} else {
pacc.AddProjectConfiguration(newName, dlg.CopyFrom);
}
}
} else {
if (editPlatforms) {
solution.AddSolutionPlatform(newName, dlg.CopyFrom, dlg.CreateInAllProjects);
} else {
solution.AddSolutionConfiguration(newName, dlg.CopyFrom, dlg.CreateInAllProjects);
}
}
InitList();
}
}
}
}
}

46
src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/SolutionConfigurationEditor.Designer.cs generated

@ -41,11 +41,11 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -41,11 +41,11 @@ namespace ICSharpCode.SharpDevelop.Gui
this.configurationComboBox = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.grid = new System.Windows.Forms.DataGridView();
this.panel2 = new System.Windows.Forms.Panel();
this.okButton = new System.Windows.Forms.Button();
this.projectNameColumn = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.configurationColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
this.platformColumn = new System.Windows.Forms.DataGridViewComboBoxColumn();
this.panel2 = new System.Windows.Forms.Panel();
this.okButton = new System.Windows.Forms.Button();
this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.grid)).BeginInit();
this.panel2.SuspendLayout();
@ -79,7 +79,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -79,7 +79,7 @@ namespace ICSharpCode.SharpDevelop.Gui
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 23);
this.label2.TabIndex = 2;
this.label2.Text = "Platform:";
this.label2.Text = "${res:Dialog.ProjectOptions.Platform}:";
this.label2.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// configurationComboBox
@ -98,7 +98,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -98,7 +98,7 @@ namespace ICSharpCode.SharpDevelop.Gui
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(138, 23);
this.label1.TabIndex = 0;
this.label1.Text = "Solution configuration:";
this.label1.Text = "${res:Dialog.Options.CombineOptions.Configurations.SolutionConfiguration}";
this.label1.TextAlign = System.Drawing.ContentAlignment.TopRight;
//
// grid
@ -119,6 +119,24 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -119,6 +119,24 @@ namespace ICSharpCode.SharpDevelop.Gui
this.grid.TabIndex = 1;
this.grid.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.GridCellValueChanged);
this.grid.DataError += new System.Windows.Forms.DataGridViewDataErrorEventHandler(this.GridDataError);
this.grid.EditingControlShowing += new System.Windows.Forms.DataGridViewEditingControlShowingEventHandler(this.GridEditingControlShowing);
//
// projectNameColumn
//
this.projectNameColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.projectNameColumn.HeaderText = "${res:Dialog.SelectReferenceDialog.ProjectReferencePanel.NameHeader}";
this.projectNameColumn.Name = "projectNameColumn";
this.projectNameColumn.ReadOnly = true;
//
// configurationColumn
//
this.configurationColumn.HeaderText = "${res:Dialog.Options.CombineOptions.Configurations.ConfigurationColumnHeader}";
this.configurationColumn.Name = "configurationColumn";
//
// platformColumn
//
this.platformColumn.HeaderText = "${res:Dialog.Options.CombineOptions.Configurations.PlatformColumnHeader}";
this.platformColumn.Name = "platformColumn";
//
// panel2
//
@ -140,23 +158,6 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -140,23 +158,6 @@ namespace ICSharpCode.SharpDevelop.Gui
this.okButton.Text = "${res:Global.OKButtonText}";
this.okButton.UseVisualStyleBackColor = true;
//
// projectNameColumn
//
this.projectNameColumn.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.projectNameColumn.HeaderText = "Project Name";
this.projectNameColumn.Name = "projectNameColumn";
this.projectNameColumn.ReadOnly = true;
//
// configurationColumn
//
this.configurationColumn.HeaderText = "Configuration";
this.configurationColumn.Name = "configurationColumn";
//
// platformColumn
//
this.platformColumn.HeaderText = "Platform";
this.platformColumn.Name = "platformColumn";
//
// SolutionConfigurationEditor
//
this.AcceptButton = this.okButton;
@ -168,7 +169,8 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -168,7 +169,8 @@ namespace ICSharpCode.SharpDevelop.Gui
this.Controls.Add(this.panel1);
this.MinimumSize = new System.Drawing.Size(457, 145);
this.Name = "SolutionConfigurationEditor";
this.Text = "Configuration Editor";
this.ShowInTaskbar = false;
this.Text = "${res:Dialog.Options.CombineOptions.Configurations.ConfigurationEditor}";
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.grid)).EndInit();
this.panel2.ResumeLayout(false);

103
src/Main/Base/Project/Src/Gui/Dialogs/SolutionConfiguration/SolutionConfigurationEditor.cs

@ -38,17 +38,12 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -38,17 +38,12 @@ namespace ICSharpCode.SharpDevelop.Gui
label1.Text = StringParser.Parse(label1.Text);
label2.Text = StringParser.Parse(label2.Text);
okButton.Text = StringParser.Parse(okButton.Text);
//cancelButton.Text = StringParser.Parse(cancelButton.Text);
projectNameColumn.HeaderText = StringParser.Parse(projectNameColumn.HeaderText);
configurationColumn.HeaderText = StringParser.Parse(configurationColumn.HeaderText);
platformColumn.HeaderText = StringParser.Parse(platformColumn.HeaderText);
inUpdate = true;
SetItems(configurationComboBox.Items, solution.GetConfigurationNames());
SetItems(platformComboBox.Items, solution.GetPlatformNames());
SelectElement(configurationComboBox, solution.Preferences.ActiveConfiguration);
SelectElement(platformComboBox, solution.Preferences.ActivePlatform);
configurationComboBoxEditIndex = configurationComboBox.Items.Add("<Edit>");
platformComboBoxEditIndex = platformComboBox.Items.Add("<Edit>");
UpdateAvailableSolutionConfigurationPlatforms();
foreach (IProject p in solution.Projects) {
DataGridViewRow row = grid.Rows[grid.Rows.Add()];
@ -59,6 +54,17 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -59,6 +54,17 @@ namespace ICSharpCode.SharpDevelop.Gui
UpdateGrid();
}
void UpdateAvailableSolutionConfigurationPlatforms()
{
SetItems(configurationComboBox.Items, solution.GetConfigurationNames());
SetItems(platformComboBox.Items, solution.GetPlatformNames());
SelectElement(configurationComboBox, solution.Preferences.ActiveConfiguration);
SelectElement(platformComboBox, solution.Preferences.ActivePlatform);
configurationComboBoxEditIndex = configurationComboBox.Items.Add("<Edit>");
platformComboBoxEditIndex = platformComboBox.Items.Add("<Edit>");
}
void SetItems(IList items, IEnumerable<string> elements)
{
items.Clear();
@ -82,6 +88,16 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -82,6 +88,16 @@ namespace ICSharpCode.SharpDevelop.Gui
}
}
sealed class EditTag
{
public static readonly EditTag Instance = new EditTag();
public override string ToString()
{
return "<Edit>";
}
}
void UpdateGrid()
{
inUpdate = true;
@ -106,11 +122,13 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -106,11 +122,13 @@ namespace ICSharpCode.SharpDevelop.Gui
c1.Tag = matching;
SetItems(c1.Items, p.ConfigurationNames);
SelectElement(c1, matching.Configuration);
c1.Items.Add(EditTag.Instance);
DataGridViewComboBoxCell c2 = (DataGridViewComboBoxCell)row.Cells[2];
c2.Tag = matching;
SetItems(c2.Items, p.PlatformNames);
SelectElement(c2, matching.Platform);
c2.Items.Add(EditTag.Instance);
}
inUpdate = false;
}
@ -123,7 +141,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -123,7 +141,7 @@ namespace ICSharpCode.SharpDevelop.Gui
using (Form dlg = new EditAvailableConfigurationsDialog(solution, false)) {
dlg.ShowDialog(this);
}
SelectElement(configurationComboBox, solution.Preferences.ActiveConfiguration);
UpdateAvailableSolutionConfigurationPlatforms();
}
UpdateGrid();
}
@ -137,7 +155,7 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -137,7 +155,7 @@ namespace ICSharpCode.SharpDevelop.Gui
using (Form dlg = new EditAvailableConfigurationsDialog(solution, true)) {
dlg.ShowDialog(this);
}
SelectElement(platformComboBox, solution.Preferences.ActivePlatform);
UpdateAvailableSolutionConfigurationPlatforms();
}
UpdateGrid();
}
@ -160,13 +178,72 @@ namespace ICSharpCode.SharpDevelop.Gui @@ -160,13 +178,72 @@ namespace ICSharpCode.SharpDevelop.Gui
} else {
matching.Platform = cell.Value.ToString();
}
if (matching.Platform == "AnyCPU") {
matching.Platform = "Any CPU";
}
if (matching.SolutionItem == null) {
matching.SolutionItem = solution.CreateMatchingItem(configurationComboBox.Text,
platformComboBox.Text,
matching.Project);
matching.Project, "");
}
matching.SolutionItem.Location = matching.Configuration + "|" + matching.Platform;
matching.SetProjectConfigurationPlatform(solution.GetProjectConfigurationsSection(),
matching.Configuration, matching.Platform);
}
}
}
ComboBox gridEditingControl;
public ComboBox GridEditingControl {
get { return gridEditingControl; }
set {
if (gridEditingControl == value) return;
if (gridEditingControl != null) {
gridEditingControl.SelectedIndexChanged -= GridEditingControlSelectedIndexChanged;
}
gridEditingControl = value;
if (gridEditingControl != null) {
gridEditingControl.SelectedIndexChanged += GridEditingControlSelectedIndexChanged;
}
}
}
void GridEditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
GridEditingControl = e.Control as ComboBox;
}
void GridEditingControlSelectedIndexChanged(object sender, EventArgs e)
{
if (gridEditingControl.SelectedItem == EditTag.Instance) {
DataGridViewComboBoxCell cell = grid.CurrentCell as DataGridViewComboBoxCell;
if (cell == null) return;
Solution.ProjectConfigurationPlatformMatching matching = cell.Tag as Solution.ProjectConfigurationPlatformMatching;
if (matching != null) {
inUpdate = true;
using (Form dlg = new EditAvailableConfigurationsDialog(matching.Project,
cell.ColumnIndex != configurationColumn.Index))
{
dlg.ShowDialog(this);
}
grid.EndEdit();
inUpdate = true;
// end edit to allow updating the grid
grid.EndEdit();
// we need to change the current cell because otherwise UpdateGrid cannot change the
// list of combobox items in this cell
grid.CurrentCell = grid.Rows[cell.RowIndex].Cells[0];
// remove cell.Value because otherwise the grid view crashes in UpdateGrid
cell.Value = null;
UpdateAvailableSolutionConfigurationPlatforms();
UpdateGrid();
}
}
}

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

@ -18,6 +18,8 @@ namespace ICSharpCode.SharpDevelop.Project @@ -18,6 +18,8 @@ namespace ICSharpCode.SharpDevelop.Project
/// <summary>
/// Base interface for projects.
/// Thread-safe members lock on the SyncRoot. Non-thread-safe members may only be called from the main thread.
///
/// When you implement IProject, you should also implement IProjectItemListProvider and IProjectAllowChangeConfigurations
/// </summary>
public interface IProject
: ISolutionFolder, IDisposable, IMementoCapable, ICanBeDirty
@ -215,6 +217,8 @@ namespace ICSharpCode.SharpDevelop.Project @@ -215,6 +217,8 @@ namespace ICSharpCode.SharpDevelop.Project
/// Interface for adding and removing items from a project. Not part of the IProject
/// interface because in nearly all cases, ProjectService.Add/RemoveProjectItem should
/// be used instead!
/// So IProject implementors should implement this interface, but only the SharpDevelop methods
/// ProjectService.AddProjectItem and RemoveProjectItem may call the interface members.
/// </summary>
public interface IProjectItemListProvider
{
@ -235,4 +239,19 @@ namespace ICSharpCode.SharpDevelop.Project @@ -235,4 +239,19 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary>
bool RemoveProjectItem(ProjectItem item);
}
/// <summary>
/// Interface for changing project or solution configuration.
/// IProject implementors should implement this interface, but only the SharpDevelop methods
/// Solution.RenameProjectPlatform etc. may call the interface members.
/// </summary>
public interface IProjectAllowChangeConfigurations
{
bool RenameProjectConfiguration(string oldName, string newName);
bool RenameProjectPlatform(string oldName, string newName);
bool AddProjectConfiguration(string newName, string copyFrom);
bool AddProjectPlatform(string newName, string copyFrom);
bool RemoveProjectConfiguration(string name);
bool RemoveProjectPlatform(string name);
}
}

222
src/Main/Base/Project/Src/Project/MSBuildBasedProject.cs

@ -22,7 +22,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -22,7 +22,7 @@ namespace ICSharpCode.SharpDevelop.Project
/// <summary>
/// A project that is based on an MSBuild project file.
/// </summary>
public class MSBuildBasedProject : AbstractProject, IProjectItemListProvider
public class MSBuildBasedProject : AbstractProject, IProjectItemListProvider, IProjectAllowChangeConfigurations
{
/// <summary>
/// The underlying MSBuild project.
@ -61,6 +61,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -61,6 +61,7 @@ namespace ICSharpCode.SharpDevelop.Project
MSBuildInternals.EnsureCorrectTempProject(project, null, null, ref evaluatingTempProject);
}
#region CreateProjectItem
/// <summary>
/// Creates a new projectItem for the passed itemType
/// </summary>
@ -109,7 +110,9 @@ namespace ICSharpCode.SharpDevelop.Project @@ -109,7 +110,9 @@ namespace ICSharpCode.SharpDevelop.Project
return false;
}
}
#endregion
#region Create new project
protected virtual void Create(ProjectCreateInformation information)
{
InitializeMSBuildProject(project);
@ -156,6 +159,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -156,6 +159,7 @@ namespace ICSharpCode.SharpDevelop.Project
project.AddNewImport(projectFile, condition);
CreateItemsListFromMSBuild();
}
#endregion
#region Get Property
/// <summary>
@ -610,7 +614,21 @@ namespace ICSharpCode.SharpDevelop.Project @@ -610,7 +614,21 @@ namespace ICSharpCode.SharpDevelop.Project
/// <summary>
/// Creates an MSBuild condition string.
/// configuration and platform may be only if they are not required (as specified by the
/// At most one of configuration and platform can be null.
/// </summary>
static string CreateCondition(string configuration, string platform)
{
if (configuration == null)
return CreateCondition(configuration, platform, PropertyStorageLocations.PlatformSpecific);
else if (platform == null)
return CreateCondition(configuration, platform, PropertyStorageLocations.ConfigurationSpecific);
else
return CreateCondition(configuration, platform, PropertyStorageLocations.ConfigurationAndPlatformSpecific);
}
/// <summary>
/// Creates an MSBuild condition string.
/// configuration and platform may be only <c>null</c> if they are not required (as specified by the
/// storage location), otherwise an ArgumentNullException is thrown.
/// </summary>
static string CreateCondition(string configuration, string platform, PropertyStorageLocations location)
@ -946,5 +964,205 @@ namespace ICSharpCode.SharpDevelop.Project @@ -946,5 +964,205 @@ namespace ICSharpCode.SharpDevelop.Project
this.platformNames = platformNames.AsReadOnly();
}
#endregion
#region IProjectAllowChangeConfigurations interface implementation
bool IProjectAllowChangeConfigurations.RenameProjectConfiguration(string oldName, string newName)
{
lock (SyncRoot) {
foreach (MSBuild.BuildPropertyGroup g in project.PropertyGroups) {
if (g.IsImported) {
continue;
}
MSBuild.BuildProperty prop = MSBuildInternals.GetProperty(g, "Configuration");
if (prop != null && prop.Value == oldName) {
prop.Value = newName;
}
string gConfiguration, gPlatform;
MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition,
out gConfiguration,
out gPlatform);
if (gConfiguration == oldName) {
g.Condition = CreateCondition(newName, gPlatform);
}
}
LoadConfigurationPlatformNamesFromMSBuild();
return true;
}
}
bool IProjectAllowChangeConfigurations.RenameProjectPlatform(string oldName, string newName)
{
lock (SyncRoot) {
foreach (MSBuild.BuildPropertyGroup g in project.PropertyGroups) {
if (g.IsImported) {
continue;
}
MSBuild.BuildProperty prop = MSBuildInternals.GetProperty(g, "Platform");
if (prop != null && prop.Value == oldName) {
prop.Value = newName;
}
string gConfiguration, gPlatform;
MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition,
out gConfiguration,
out gPlatform);
if (gPlatform == oldName) {
g.Condition = CreateCondition(gConfiguration, newName);
}
}
LoadConfigurationPlatformNamesFromMSBuild();
return true;
}
}
bool IProjectAllowChangeConfigurations.AddProjectConfiguration(string newName, string copyFrom)
{
lock (SyncRoot) {
bool copiedGroup = false;
if (copyFrom != null) {
foreach (MSBuild.BuildPropertyGroup g
in Linq.ToList(Linq.CastTo<MSBuild.BuildPropertyGroup>(project.PropertyGroups)))
{
if (g.IsImported) {
continue;
}
string gConfiguration, gPlatform;
MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition,
out gConfiguration,
out gPlatform);
if (gConfiguration == copyFrom) {
CopyProperties(g, newName, gPlatform);
copiedGroup = true;
}
}
}
if (!copiedGroup) {
project.AddNewPropertyGroup(false).Condition = CreateCondition(newName, null);
}
LoadConfigurationPlatformNamesFromMSBuild();
return true;
}
}
bool IProjectAllowChangeConfigurations.AddProjectPlatform(string newName, string copyFrom)
{
lock (SyncRoot) {
bool copiedGroup = false;
if (copyFrom != null) {
foreach (MSBuild.BuildPropertyGroup g
in Linq.ToList(Linq.CastTo<MSBuild.BuildPropertyGroup>(project.PropertyGroups)))
{
if (g.IsImported) {
continue;
}
string gConfiguration, gPlatform;
MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition,
out gConfiguration,
out gPlatform);
if (gPlatform == copyFrom) {
CopyProperties(g, gConfiguration, newName);
copiedGroup = true;
}
}
}
if (!copiedGroup) {
project.AddNewPropertyGroup(false).Condition = CreateCondition(null, newName);
}
LoadConfigurationPlatformNamesFromMSBuild();
return true;
}
}
/// <summary>
/// copy properties from g into a new property group for newConfiguration and newPlatform
/// </summary>
void CopyProperties(MSBuild.BuildPropertyGroup g, string newConfiguration, string newPlatform)
{
MSBuild.BuildPropertyGroup ng = project.AddNewPropertyGroup(false);
ng.Condition = CreateCondition(newConfiguration, newPlatform);
foreach (MSBuild.BuildProperty p in g) {
ng.AddNewProperty(p.Name, p.Value);
}
}
bool IProjectAllowChangeConfigurations.RemoveProjectConfiguration(string name)
{
lock (SyncRoot) {
string otherConfigurationName = null;
foreach (string configName in this.ConfigurationNames) {
if (configName != name) {
otherConfigurationName = name;
break;
}
}
if (otherConfigurationName == null) {
throw new InvalidOperationException("cannot remove the last configuration");
}
foreach (MSBuild.BuildPropertyGroup g
in Linq.ToList(Linq.CastTo<MSBuild.BuildPropertyGroup>(project.PropertyGroups)))
{
if (g.IsImported) {
continue;
}
MSBuild.BuildProperty prop = MSBuildInternals.GetProperty(g, "Configuration");
if (prop != null && prop.Value == name) {
prop.Value = otherConfigurationName;
}
string gConfiguration, gPlatform;
MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition,
out gConfiguration,
out gPlatform);
if (gConfiguration == name) {
project.RemovePropertyGroup(g);
}
}
LoadConfigurationPlatformNamesFromMSBuild();
return true;
}
}
bool IProjectAllowChangeConfigurations.RemoveProjectPlatform(string name)
{
lock (SyncRoot) {
string otherPlatformName = null;
foreach (string platformName in this.PlatformNames) {
if (platformName != name) {
otherPlatformName = name;
break;
}
}
if (otherPlatformName == null) {
throw new InvalidOperationException("cannot remove the last platform");
}
foreach (MSBuild.BuildPropertyGroup g
in Linq.ToList(Linq.CastTo<MSBuild.BuildPropertyGroup>(project.PropertyGroups)))
{
if (g.IsImported) {
continue;
}
MSBuild.BuildProperty prop = MSBuildInternals.GetProperty(g, "Platform");
if (prop != null && prop.Value == name) {
prop.Value = otherPlatformName;
}
string gConfiguration, gPlatform;
MSBuildInternals.GetConfigurationAndPlatformFromCondition(g.Condition,
out gConfiguration,
out gPlatform);
if (gPlatform == name) {
project.RemovePropertyGroup(g);
}
}
LoadConfigurationPlatformNamesFromMSBuild();
return true;
}
}
#endregion
}
}

305
src/Main/Base/Project/Src/Project/Solution/Solution.cs

@ -668,11 +668,32 @@ namespace ICSharpCode.SharpDevelop.Project @@ -668,11 +668,32 @@ namespace ICSharpCode.SharpDevelop.Project
preferences.ActivePlatform))
{
l.Project.ActiveConfiguration = l.Configuration;
if (l.Platform == "Any CPU") {
l.Project.ActivePlatform = "AnyCPU";
} else {
l.Project.ActivePlatform = l.Platform;
}
l.Project.ActivePlatform = FixPlatformNameForProject(l.Platform);
}
}
/// <summary>
/// This is a special case in MSBuild we need to take care of.
/// </summary>
static string FixPlatformNameForProject(string platformName)
{
if (platformName == "Any CPU") {
return "AnyCPU";
} else {
return platformName;
}
}
/// <summary>
/// This is a special case in MSBuild we need to take care of.
/// Opposite of FixPlatformNameForProject
/// </summary>
static string FixPlatformNameForSolution(string platformName)
{
if (platformName == "AnyCPU") {
return "Any CPU";
} else {
return platformName;
}
}
@ -690,6 +711,50 @@ namespace ICSharpCode.SharpDevelop.Project @@ -690,6 +711,50 @@ namespace ICSharpCode.SharpDevelop.Project
this.Platform = platform;
this.SolutionItem = solutionItem;
}
public void SetSolutionConfigurationPlatform(ProjectSection section, string newConfiguration, string newPlatform)
{
if (this.SolutionItem == null)
return;
string oldName = this.SolutionItem.Name;
this.SolutionItem.Name = this.Project.IdGuid + "." + newConfiguration + "|" + newPlatform + ".Build.0";
string newName = this.SolutionItem.Name;
if (StripBuild0(ref oldName) && StripBuild0(ref newName)) {
oldName += ".ActiveCfg";
newName += ".ActiveCfg";
foreach (SolutionItem item in section.Items) {
if (item.Name == oldName)
item.Name = newName;
}
}
}
public void SetProjectConfigurationPlatform(ProjectSection section, string newConfiguration, string newPlatform)
{
this.Configuration = newConfiguration;
this.Platform = newPlatform;
if (this.SolutionItem == null)
return;
this.SolutionItem.Location = newConfiguration + "|" + newPlatform;
string thisName = this.SolutionItem.Name;
if (StripBuild0(ref thisName)) {
thisName += ".ActiveCfg";
foreach (SolutionItem item in section.Items) {
if (item.Name == thisName)
item.Location = this.SolutionItem.Location;
}
}
}
internal static bool StripBuild0(ref string s)
{
if (s.EndsWith(".Build.0")) {
s = s.Substring(0, s.Length - ".Build.0".Length);
return true;
} else {
return false;
}
}
}
internal List<ProjectConfigurationPlatformMatching>
@ -697,7 +762,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -697,7 +762,7 @@ namespace ICSharpCode.SharpDevelop.Project
{
List<ProjectConfigurationPlatformMatching> results = new List<ProjectConfigurationPlatformMatching>();
ProjectSection prjSec = GetProjectConfigurationsSection();
Dictionary<string, SolutionItem> dict = new Dictionary<string, SolutionItem>();
Dictionary<string, SolutionItem> dict = new Dictionary<string, SolutionItem>(StringComparer.InvariantCultureIgnoreCase);
foreach (SolutionItem item in prjSec.Items) {
dict[item.Name] = item;
}
@ -721,25 +786,25 @@ namespace ICSharpCode.SharpDevelop.Project @@ -721,25 +786,25 @@ namespace ICSharpCode.SharpDevelop.Project
return results;
}
internal SolutionItem CreateMatchingItem(string solutionConfiguration, string solutionPlatform, IProject project)
internal SolutionItem CreateMatchingItem(string solutionConfiguration, string solutionPlatform, IProject project, string initialLocation)
{
SolutionItem item = new SolutionItem(project.IdGuid + "." + solutionConfiguration + "|"
+ solutionPlatform + ".Build.0", "");
+ solutionPlatform + ".Build.0", initialLocation);
GetProjectConfigurationsSection().Items.Add(item);
GetProjectConfigurationsSection().Items.Add(new SolutionItem(project.IdGuid + "." + solutionConfiguration + "|"
+ solutionPlatform + ".ActiveCfg", initialLocation));
return item;
}
#endregion
#region Configurations management
#region Rename Solution Configuration/Platform
public void RenameSolutionConfiguration(string oldName, string newName)
{
foreach (string platform in GetPlatformNames()) {
foreach (ProjectConfigurationPlatformMatching m
in GetActiveConfigurationsAndPlatformsForProjects(oldName, platform))
{
if (m.SolutionItem == null)
continue;
m.SolutionItem.Name = m.Project.IdGuid + "." + newName + "|" + platform + ".Build.0";
m.SetSolutionConfigurationPlatform(GetProjectConfigurationsSection(), newName, platform);
}
}
foreach (SolutionItem item in GetSolutionConfigurationsSection().Items) {
@ -756,9 +821,7 @@ namespace ICSharpCode.SharpDevelop.Project @@ -756,9 +821,7 @@ namespace ICSharpCode.SharpDevelop.Project
foreach (ProjectConfigurationPlatformMatching m
in GetActiveConfigurationsAndPlatformsForProjects(configuration, oldName))
{
if (m.SolutionItem == null)
continue;
m.SolutionItem.Name = m.Project.IdGuid + "." + configuration + "|" + newName + ".Build.0";
m.SetSolutionConfigurationPlatform(GetProjectConfigurationsSection(), configuration, newName);
}
}
foreach (SolutionItem item in GetSolutionConfigurationsSection().Items) {
@ -769,6 +832,218 @@ namespace ICSharpCode.SharpDevelop.Project @@ -769,6 +832,218 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
#endregion
#region Rename Project Configuration/Platform
public bool RenameProjectConfiguration(IProject project, string oldName, string newName)
{
IProjectAllowChangeConfigurations pacc = project as IProjectAllowChangeConfigurations;
if (pacc == null)
return false;
if (!pacc.RenameProjectConfiguration(oldName, newName))
return false;
// project configuration was renamed successfully, adjust solution:
foreach (SolutionItem item in GetProjectConfigurationsSection().Items) {
if (item.Name.ToLowerInvariant().StartsWith(project.IdGuid.ToLowerInvariant())) {
if (AbstractProject.GetConfigurationNameFromKey(item.Location) == oldName) {
item.Location = newName + "|" + AbstractProject.GetPlatformNameFromKey(item.Location);
}
}
}
return true;
}
public bool RenameProjectPlatform(IProject project, string oldName, string newName)
{
IProjectAllowChangeConfigurations pacc = project as IProjectAllowChangeConfigurations;
if (pacc == null)
return false;
if (!pacc.RenameProjectPlatform(FixPlatformNameForProject(oldName), FixPlatformNameForProject(newName)))
return false;
// project configuration was renamed successfully, adjust solution:
foreach (SolutionItem item in GetProjectConfigurationsSection().Items) {
if (item.Name.ToLowerInvariant().StartsWith(project.IdGuid.ToLowerInvariant())) {
if (AbstractProject.GetPlatformNameFromKey(item.Location) == oldName) {
item.Location = AbstractProject.GetConfigurationNameFromKey(item.Location) + "|" + newName;
}
}
}
return true;
}
#endregion
#region Add Solution Configuration/Platform
/// <summary>
/// Creates a new solution configuration.
/// </summary>
/// <param name="newName">Name of the new configuration</param>
/// <param name="copyFrom">Name of existing configuration to copy values from, or null</param>
/// <param name="createInProjects">true to also create the new configuration in all projects</param>
public void AddSolutionConfiguration(string newName, string copyFrom, bool createInProjects)
{
foreach (string platform in this.GetPlatformNames()) {
AddSolutionConfigurationPlatform(newName, platform, copyFrom, createInProjects, false);
}
}
public void AddSolutionPlatform(string newName, string copyFrom, bool createInProjects)
{
foreach (string configuration in this.GetConfigurationNames()) {
AddSolutionConfigurationPlatform(configuration, newName, copyFrom, createInProjects, true);
}
}
void AddSolutionConfigurationPlatform(string newConfiguration, string newPlatform,
string copyFrom, bool createInProjects, bool addPlatform)
{
List<ProjectConfigurationPlatformMatching> matchings;
if (string.IsNullOrEmpty(copyFrom)) {
matchings = new List<ProjectConfigurationPlatformMatching>();
} else {
if (addPlatform) {
matchings = GetActiveConfigurationsAndPlatformsForProjects(newConfiguration, copyFrom);
} else {
matchings = GetActiveConfigurationsAndPlatformsForProjects(copyFrom, newPlatform);
}
}
GetSolutionConfigurationsSection().Items.Add(new SolutionItem(newConfiguration + "|" + newPlatform,
newConfiguration + "|" + newPlatform));
foreach (IProject project in this.Projects) {
// get old project configuration and platform
string projectConfiguration, projectPlatform;
ProjectConfigurationPlatformMatching matching = matchings.Find(
delegate(ProjectConfigurationPlatformMatching m) { return m.Project == project; });
if (matching != null) {
projectConfiguration = matching.Configuration;
projectPlatform = matching.Platform;
} else {
projectConfiguration = Linq.ToArray(project.ConfigurationNames)[0];
projectPlatform = FixPlatformNameForSolution(Linq.ToArray(project.PlatformNames)[0]);
}
if (createInProjects) {
ICollection<string> existingInProject = addPlatform ? project.PlatformNames : project.ConfigurationNames;
if (existingInProject.Contains(addPlatform ? newPlatform : newConfiguration)) {
// target platform/configuration already exists, so reference it
if (addPlatform) {
projectPlatform = newPlatform;
} else {
projectConfiguration = newConfiguration;
}
} else {
// create in project
IProjectAllowChangeConfigurations pacc = project as IProjectAllowChangeConfigurations;
if (pacc != null) {
if (addPlatform) {
if (pacc.AddProjectPlatform(FixPlatformNameForProject(newPlatform),
FixPlatformNameForProject(projectPlatform))) {
projectPlatform = newPlatform;
}
} else {
if (pacc.AddProjectConfiguration(newConfiguration, projectConfiguration)) {
projectConfiguration = newConfiguration;
}
}
}
}
}
// create item combining solution configuration with project configuration
CreateMatchingItem(newConfiguration, newPlatform, project, projectConfiguration + "|" + projectPlatform);
}
}
#endregion
#region Remove Solution Configuration/Platform
/// <summary>
/// Gets the configuration|platform name from a conf item, e.g.
/// "Release|Any CPU" from
/// "{7115F3A9-781C-4A95-90AE-B5AB53C4C588}.Release|Any CPU.Build.0"
/// </summary>
static string GetKeyFromProjectConfItem(string name)
{
int pos = name.IndexOf('.');
if (pos < 0) return null;
name = name.Substring(pos + 1);
if (!ProjectConfigurationPlatformMatching.StripBuild0(ref name)) {
pos = name.LastIndexOf('.');
if (pos < 0) return null;
name = name.Substring(0, pos);
}
return name;
}
public void RemoveSolutionConfiguration(string name)
{
GetSolutionConfigurationsSection().Items.RemoveAll(
delegate(SolutionItem item) {
return AbstractProject.GetConfigurationNameFromKey(item.Name) == name;
});
GetProjectConfigurationsSection().Items.RemoveAll(
delegate(SolutionItem item) {
return AbstractProject.GetConfigurationNameFromKey(GetKeyFromProjectConfItem(item.Name)) == name;
});
}
public void RemoveSolutionPlatform(string name)
{
GetSolutionConfigurationsSection().Items.RemoveAll(
delegate(SolutionItem item) {
return AbstractProject.GetPlatformNameFromKey(item.Name) == name;
});
GetProjectConfigurationsSection().Items.RemoveAll(
delegate(SolutionItem item) {
return AbstractProject.GetPlatformNameFromKey(GetKeyFromProjectConfItem(item.Name)) == name;
});
}
#endregion
#region Remove Project Configuration/Platform
public bool RemoveProjectConfiguration(IProject project, string name)
{
IProjectAllowChangeConfigurations pacc = project as IProjectAllowChangeConfigurations;
if (pacc == null)
return false;
if (!pacc.RemoveProjectConfiguration(name))
return false;
string otherConfigurationName = "other";
foreach (string configName in project.ConfigurationNames) {
otherConfigurationName = configName;
}
// project configuration was removed successfully, adjust solution:
foreach (SolutionItem item in GetProjectConfigurationsSection().Items) {
if (item.Name.ToLowerInvariant().StartsWith(project.IdGuid.ToLowerInvariant())) {
if (AbstractProject.GetConfigurationNameFromKey(item.Location) == name) {
// removed configuration was in use here, replace with other configuration
item.Location = otherConfigurationName + "|" + AbstractProject.GetPlatformNameFromKey(item.Location);
}
}
}
return true;
}
public bool RemoveProjectPlatform(IProject project, string name)
{
IProjectAllowChangeConfigurations pacc = project as IProjectAllowChangeConfigurations;
if (pacc == null)
return false;
if (!pacc.RemoveProjectPlatform(name))
return false;
string otherPlatformName = "other";
foreach (string platformName in project.PlatformNames) {
otherPlatformName = platformName;
}
// project configuration was removed successfully, adjust solution:
foreach (SolutionItem item in GetProjectConfigurationsSection().Items) {
if (item.Name.ToLowerInvariant().StartsWith(project.IdGuid.ToLowerInvariant())) {
if (AbstractProject.GetPlatformNameFromKey(item.Location) == name) {
// removed configuration was in use here, replace with other configuration
item.Location = AbstractProject.GetConfigurationNameFromKey(item.Location) + "|" + otherPlatformName;
}
}
}
return true;
}
#endregion
#endregion
#region Load

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

Binary file not shown.
Loading…
Cancel
Save