Browse Source

Allow changing the active solution configuration in the build menu.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@892 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 20 years ago
parent
commit
e46db83c0a
  1. 10
      AddIns/ICSharpCode.SharpDevelop.addin
  2. 29
      src/Main/Base/Project/Src/Commands/BuildCommands.cs
  3. 38
      src/Main/Base/Project/Src/Project/AbstractProject.cs
  4. 9
      src/Main/Base/Project/Src/Project/ConfigurationGuiHelper.cs
  5. 3
      src/Main/Base/Project/Src/Project/IProject.cs
  6. 36
      src/Main/Base/Project/Src/Project/MSBuildEngine.cs
  7. 17
      src/Main/Base/Project/Src/Project/MSBuildProject.cs
  8. 74
      src/Main/Base/Project/Src/Project/Solution/Solution.cs
  9. 47
      src/Main/Base/Project/Src/Project/Solution/SolutionPreferences.cs

10
AddIns/ICSharpCode.SharpDevelop.addin

@ -1173,7 +1173,7 @@
</MenuItem> </MenuItem>
</Condition> <!-- end PROJECT menu --> </Condition> <!-- end PROJECT menu -->
<MenuItem id = "Run" label = "${res:XML.MainMenu.BuildMenu}" type="Menu"> <MenuItem id = "Build" label = "${res:XML.MainMenu.BuildMenu}" type="Menu">
<ComplexCondition action="Disable"> <ComplexCondition action="Disable">
<Or> <Or>
<And> <And>
@ -1211,10 +1211,16 @@
<MenuItem id = "Clean project" <MenuItem id = "Clean project"
label = "${res:XML.MainMenu.BuildMenu.CleanProject}" label = "${res:XML.MainMenu.BuildMenu.CleanProject}"
class = "ICSharpCode.SharpDevelop.Project.Commands.CleanProject"/> class = "ICSharpCode.SharpDevelop.Project.Commands.CleanProject"/>
<MenuItem id = "Publis&amp;h project" <MenuItem id = "Publish project"
label = "${res:XML.MainMenu.BuildMenu.PublishProject}" label = "${res:XML.MainMenu.BuildMenu.PublishProject}"
class = "ICSharpCode.SharpDevelop.Project.Commands.PublishProject"/> class = "ICSharpCode.SharpDevelop.Project.Commands.PublishProject"/>
</Condition> </Condition>
<MenuItem id = "Separator2" type = "Separator" />
<MenuItem id = "SetConfiguration"
label = "Set configuration"
type = "Menu">
<MenuItem id = "ConfigurationBuilder" type = "Builder" class = "ICSharpCode.SharpDevelop.Project.Commands.SetConfigurationMenuBuilder"/>
</MenuItem>
</ComplexCondition> </ComplexCondition>
</MenuItem> <!-- end RUN menu --> </MenuItem> <!-- end RUN menu -->

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

@ -1,18 +1,19 @@
// <file> // <file>
// <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright> // <copyright see="prj:///doc/copyright.txt">2002-2005 AlphaSierraPapa</copyright>
// <license see="prj:///doc/license.txt">GNU General Public License</license> // <license see="prj:///doc/license.txt">GNU General Public License</license>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/> // <owner name="Daniel Grunwald" email="mike@icsharpcode.net"/>
// <version>$Revision$</version> // <version>$Revision$</version>
// </file> // </file>
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.CodeDom.Compiler; using System.CodeDom.Compiler;
using System.Windows.Forms;
using ICSharpCode.SharpDevelop.Project; using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.Core; using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Project.Commands namespace ICSharpCode.SharpDevelop.Project.Commands
{ {
public class Build : AbstractMenuCommand public class Build : AbstractMenuCommand
@ -167,4 +168,28 @@ namespace ICSharpCode.SharpDevelop.Project.Commands
} }
} }
} }
public class SetConfigurationMenuBuilder : ISubmenuBuilder
{
public ToolStripItem[] BuildSubmenu(Codon codon, object owner)
{
if (ProjectService.OpenSolution == null)
return new ToolStripItem[0];
IList<string> configurationNames = ProjectService.OpenSolution.GetConfigurationNames();
string activeConfiguration = ProjectService.OpenSolution.Preferences.ActiveConfiguration;
ToolStripMenuItem[] items = new ToolStripMenuItem[configurationNames.Count];
for (int i = 0; i < items.Length; i++) {
items[i] = new ToolStripMenuItem(configurationNames[i]);
items[i].Click += SetConfigurationItemClick;
items[i].Checked = activeConfiguration == configurationNames[i];
}
return items;
}
void SetConfigurationItemClick(object sender, EventArgs e)
{
ToolStripMenuItem item = (ToolStripMenuItem)sender;
ProjectService.OpenSolution.Preferences.ActiveConfiguration = item.Text;
}
}
} }

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

@ -43,7 +43,7 @@ namespace ICSharpCode.SharpDevelop.Project
return key.Substring(key.IndexOf('|') + 1); return key.Substring(key.IndexOf('|') + 1);
} }
public string[] GetConfigurationNames() public List<string> GetConfigurationNames()
{ {
List<string> configurationNames = new List<string>(); List<string> configurationNames = new List<string>();
foreach (string key in configurations.Keys) { foreach (string key in configurations.Keys) {
@ -61,11 +61,10 @@ namespace ICSharpCode.SharpDevelop.Project
if (!configurationNames.Contains(this.Configuration)) { if (!configurationNames.Contains(this.Configuration)) {
configurationNames.Add(this.Configuration); configurationNames.Add(this.Configuration);
} }
configurationNames.Sort(); return configurationNames;
return configurationNames.ToArray();
} }
public string[] GetPlatformNames() public List<string> GetPlatformNames()
{ {
List<string> platformNames = new List<string>(); List<string> platformNames = new List<string>();
foreach (string key in configurations.Keys) { foreach (string key in configurations.Keys) {
@ -83,8 +82,7 @@ namespace ICSharpCode.SharpDevelop.Project
if (!platformNames.Contains(this.Platform)) { if (!platformNames.Contains(this.Platform)) {
platformNames.Add(this.Platform); platformNames.Add(this.Platform);
} }
platformNames.Sort(); return platformNames;
return platformNames.ToArray();
} }
/// <summary> /// <summary>
@ -211,8 +209,28 @@ namespace ICSharpCode.SharpDevelop.Project
} }
} }
[Browsable(false)] string activeConfiguration, activePlatform;
public string Platform {
get {
return activePlatform;
}
set {
activePlatform = value;
}
}
public string Configuration { public string Configuration {
get {
return activeConfiguration;
}
set {
activeConfiguration = value;
}
}
[Browsable(false)]
public string DefaultConfiguration {
get { get {
// is always stored in BaseConfiguration // is always stored in BaseConfiguration
return BaseConfiguration["Configuration"]; return BaseConfiguration["Configuration"];
@ -223,7 +241,7 @@ namespace ICSharpCode.SharpDevelop.Project
} }
[Browsable(false)] [Browsable(false)]
public string Platform { public string DefaultPlatform {
get { get {
// is always stored in BaseConfiguration // is always stored in BaseConfiguration
return BaseConfiguration["Platform"]; return BaseConfiguration["Platform"];
@ -513,8 +531,8 @@ namespace ICSharpCode.SharpDevelop.Project
} }
if (oldBaseValue != null) { if (oldBaseValue != null) {
// copy old base value to all configurations // copy old base value to all configurations
string[] configurationNames = GetConfigurationNames(); IEnumerable<string> configurationNames = GetConfigurationNames();
string[] platformNames = GetPlatformNames(); IEnumerable<string> platformNames = GetPlatformNames();
switch (location & PropertyStorageLocations.ConfigurationAndPlatformSpecific) { switch (location & PropertyStorageLocations.ConfigurationAndPlatformSpecific) {
case PropertyStorageLocations.ConfigurationAndPlatformSpecific: case PropertyStorageLocations.ConfigurationAndPlatformSpecific:
foreach (string cN in configurationNames) { foreach (string cN in configurationNames) {

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

@ -518,10 +518,15 @@ namespace ICSharpCode.SharpDevelop.Project
void FillBoxes() void FillBoxes()
{ {
List<string> items;
configurationComboBox.Items.Clear(); configurationComboBox.Items.Clear();
configurationComboBox.Items.AddRange(helper.Project.GetConfigurationNames()); items = helper.Project.GetConfigurationNames();
items.Sort();
configurationComboBox.Items.AddRange(items.ToArray());
platformComboBox.Items.Clear(); platformComboBox.Items.Clear();
platformComboBox.Items.AddRange(helper.Project.GetPlatformNames()); items = helper.Project.GetPlatformNames();
items.Sort();
platformComboBox.Items.AddRange(items.ToArray());
ResetIndex(); ResetIndex();
} }

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

@ -58,10 +58,11 @@ namespace ICSharpCode.SharpDevelop.Project
string Configuration { string Configuration {
get; get;
set;
} }
string Platform { string Platform {
get; get;
set;
} }
string AssemblyName { string AssemblyName {

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

@ -58,6 +58,36 @@ namespace ICSharpCode.SharpDevelop.Project
} }
} }
string configuration;
/// <summary>
/// The configuration of the solution or project that should be builded.
/// Use null to build the default configuration.
/// </summary>
public string Configuration {
get {
return configuration;
}
set {
configuration = value;
}
}
string platform;
/// <summary>
/// The platform of the solution or project that should be builded.
/// Use null to build the default platform.
/// </summary>
public string Platform {
get {
return platform;
}
set {
platform = value;
}
}
public CompilerResults Run(string buildFile) public CompilerResults Run(string buildFile)
{ {
return Run(buildFile, null); return Run(buildFile, null);
@ -108,6 +138,12 @@ namespace ICSharpCode.SharpDevelop.Project
LoggingService.Debug("Run MSBuild on " + buildFile); LoggingService.Debug("Run MSBuild on " + buildFile);
Engine engine = new Engine(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory()); Engine engine = new Engine(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory());
if (this.engine.Configuration != null) {
engine.GlobalProperties.SetProperty("Configuration", this.engine.Configuration);
}
if (this.engine.Platform != null) {
engine.GlobalProperties.SetProperty("Platform", this.engine.Platform);
}
foreach (KeyValuePair<string, string> entry in MSBuildProperties) { foreach (KeyValuePair<string, string> entry in MSBuildProperties) {
engine.GlobalProperties.SetProperty(entry.Key, entry.Value); engine.GlobalProperties.SetProperty(entry.Key, entry.Value);
} }

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

@ -422,11 +422,13 @@ namespace ICSharpCode.SharpDevelop.Project
// isDirty = TaskService.Errors != 0; // isDirty = TaskService.Errors != 0;
// } // }
public static CompilerResults RunMSBuild(string fileName, string target) public static CompilerResults RunMSBuild(string fileName, string target, string configuration, string platform)
{ {
WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView)).BringPadToFront(); WorkbenchSingleton.Workbench.GetPad(typeof(CompilerMessageView)).BringPadToFront();
// BeforeBuild(); // BeforeBuild();
MSBuildEngine engine = new MSBuildEngine(); MSBuildEngine engine = new MSBuildEngine();
engine.Configuration = configuration;
engine.Platform = platform;
engine.MessageView = TaskService.BuildMessageViewCategory; engine.MessageView = TaskService.BuildMessageViewCategory;
if (target == null) { if (target == null) {
return engine.Run(fileName); return engine.Run(fileName);
@ -435,26 +437,31 @@ namespace ICSharpCode.SharpDevelop.Project
// AfterBuild(); // AfterBuild();
} }
public CompilerResults RunMSBuild(string target)
{
return RunMSBuild(this.FileName, target, this.Configuration, this.Platform);
}
public override CompilerResults Build() public override CompilerResults Build()
{ {
return RunMSBuild(FileName, "Build"); return RunMSBuild("Build");
} }
public override CompilerResults Rebuild() public override CompilerResults Rebuild()
{ {
return RunMSBuild(FileName, "Rebuild"); return RunMSBuild("Rebuild");
} }
public override CompilerResults Clean() public override CompilerResults Clean()
{ {
CompilerResults result = RunMSBuild(FileName, "Clean"); CompilerResults result = RunMSBuild("Clean");
isDirty = true; isDirty = true;
return result; return result;
} }
public override CompilerResults Publish() public override CompilerResults Publish()
{ {
return RunMSBuild(FileName, "Publish"); return RunMSBuild("Publish");
} }
public override string ToString() public override string ToString()

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

@ -18,9 +18,6 @@ using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.SharpDevelop.Project namespace ICSharpCode.SharpDevelop.Project
{ {
/// <summary>
/// Description of Solution.
/// </summary>
public class Solution : SolutionFolder, IDisposable public class Solution : SolutionFolder, IDisposable
{ {
// contains <guid>, (IProject/ISolutionFolder) pairs. // contains <guid>, (IProject/ISolutionFolder) pairs.
@ -486,19 +483,22 @@ namespace ICSharpCode.SharpDevelop.Project
return true; return true;
} }
public const string SolutionPlatformsSectionName = "SolutionConfigurationPlatforms";
public const string ProjectConfigurationSectionName = "ProjectConfigurationPlatforms";
public bool FixSolutionConfiguration(IEnumerable<IProject> projects) public bool FixSolutionConfiguration(IEnumerable<IProject> projects)
{ {
ProjectSection solSec = null; ProjectSection solSec = null;
ProjectSection prjSec = null; ProjectSection prjSec = null;
bool changed = false; bool changed = false;
foreach (ProjectSection sec in Sections) { foreach (ProjectSection sec in Sections) {
if (sec.Name == "SolutionConfigurationPlatforms") if (sec.Name == SolutionPlatformsSectionName)
solSec = sec; solSec = sec;
else if (sec.Name == "ProjectConfigurationPlatforms") else if (sec.Name == ProjectConfigurationSectionName)
prjSec = sec; prjSec = sec;
} }
if (solSec == null) { if (solSec == null) {
solSec = new ProjectSection("SolutionConfigurationPlatforms", "preSolution"); solSec = new ProjectSection(SolutionPlatformsSectionName, "preSolution");
Sections.Insert(0, solSec); Sections.Insert(0, solSec);
solSec.Items.Add(new SolutionItem("Debug|Any CPU", "Debug|Any CPU")); solSec.Items.Add(new SolutionItem("Debug|Any CPU", "Debug|Any CPU"));
solSec.Items.Add(new SolutionItem("Release|Any CPU", "Release|Any CPU")); solSec.Items.Add(new SolutionItem("Release|Any CPU", "Release|Any CPU"));
@ -506,7 +506,7 @@ namespace ICSharpCode.SharpDevelop.Project
changed = true; changed = true;
} }
if (prjSec == null) { if (prjSec == null) {
prjSec = new ProjectSection("ProjectConfigurationPlatforms", "postSolution"); prjSec = new ProjectSection(ProjectConfigurationSectionName, "postSolution");
Sections.Add(prjSec); Sections.Add(prjSec);
LoggingService.Warn("!! Inserted ProjectConfigurationPlatforms !!"); LoggingService.Warn("!! Inserted ProjectConfigurationPlatforms !!");
changed = true; changed = true;
@ -535,6 +535,52 @@ namespace ICSharpCode.SharpDevelop.Project
return changed; return changed;
} }
public IList<string> GetConfigurationNames()
{
List<string> configurationNames = new List<string>();
foreach (ProjectSection sec in ProjectService.OpenSolution.Sections) {
if (sec.Name != SolutionPlatformsSectionName)
continue;
foreach (SolutionItem item in sec.Items) {
string name = AbstractProject.GetConfigurationNameFromKey(item.Name);
if (!configurationNames.Contains(name))
configurationNames.Add(name);
}
}
return configurationNames;
}
public IList<string> GetPlatformNames()
{
List<string> platformNames = new List<string>();
foreach (ProjectSection sec in ProjectService.OpenSolution.Sections) {
if (sec.Name != SolutionPlatformsSectionName)
continue;
foreach (SolutionItem item in sec.Items) {
string name = AbstractProject.GetPlatformNameFromKey(item.Name);
if (!platformNames.Contains(name))
platformNames.Add(name);
}
}
return platformNames;
}
public void ApplySolutionConfigurationToProjects(string configuration)
{
// TODO: Use assignments from project configuration section
foreach (IProject p in Projects) {
p.Configuration = configuration;
}
}
public void ApplySolutionPlatformToProjects(string platform)
{
// TODO: Use assignments from project configuration section
foreach (IProject p in Projects) {
p.Platform = platform;
}
}
static Solution solutionBeingLoaded; static Solution solutionBeingLoaded;
public static Solution SolutionBeingLoaded { public static Solution SolutionBeingLoaded {
@ -582,25 +628,29 @@ namespace ICSharpCode.SharpDevelop.Project
} }
#endregion #endregion
public CompilerResults RunMSBuild(string target)
{
return MSBuildProject.RunMSBuild(FileName, target, preferences.ActiveConfiguration, preferences.ActivePlatform);
}
public CompilerResults Build() public CompilerResults Build()
{ {
return MSBuildProject.RunMSBuild(FileName, null); return RunMSBuild(null);
} }
public CompilerResults Rebuild() public CompilerResults Rebuild()
{ {
return MSBuildProject.RunMSBuild(FileName, "Rebuild"); return RunMSBuild("Rebuild");
} }
public CompilerResults Clean() public CompilerResults Clean()
{ {
return MSBuildProject.RunMSBuild(FileName, "Clean"); return RunMSBuild("Clean");
} }
public CompilerResults Publish() public CompilerResults Publish()
{ {
return MSBuildProject.RunMSBuild(FileName, "Publish"); return RunMSBuild("Publish");
} }
} }
} }

47
src/Main/Base/Project/Src/Project/Solution/SolutionPreferences.cs

@ -6,6 +6,7 @@
// </file> // </file>
using System; using System;
using System.Collections.Generic;
using ICSharpCode.Core; using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Project namespace ICSharpCode.SharpDevelop.Project
@ -13,14 +14,15 @@ namespace ICSharpCode.SharpDevelop.Project
public class SolutionPreferences : IMementoCapable public class SolutionPreferences : IMementoCapable
{ {
Solution solution; Solution solution;
string startupProject = "";
string activeConfiguration = "Debug";
string activePlatform = "AnyCPU";
internal SolutionPreferences(Solution solution) internal SolutionPreferences(Solution solution)
{ {
this.solution = solution; this.solution = solution;
} }
string startupProject = "";
public IProject StartupProject { public IProject StartupProject {
get { get {
if (startupProject.Length == 0) if (startupProject.Length == 0)
@ -36,13 +38,37 @@ namespace ICSharpCode.SharpDevelop.Project
} }
} }
public string ActiveConfiguration {
get {
return activeConfiguration;
}
set {
if (value == null) throw new ArgumentNullException();
activeConfiguration = value;
solution.ApplySolutionConfigurationToProjects(value);
}
}
public string ActivePlatform {
get {
return activePlatform;
}
set {
if (value == null) throw new ArgumentNullException();
activePlatform = value;
solution.ApplySolutionPlatformToProjects(value);
}
}
/// <summary> /// <summary>
/// Creates a new memento from the state. /// Creates a new memento from the state.
/// </summary> /// </summary>
public Properties CreateMemento() public Properties CreateMemento()
{ {
Properties p = new Properties(); Properties p = new Properties();
p.Set("StartupProject", startupProject); p.Set("StartupProject", startupProject);
p.Set("ActiveConfiguration", activeConfiguration);
p.Set("ActivePlatform", activePlatform);
return p; return p;
} }
@ -51,7 +77,20 @@ namespace ICSharpCode.SharpDevelop.Project
/// </summary> /// </summary>
public void SetMemento(Properties memento) public void SetMemento(Properties memento)
{ {
startupProject = memento.Get("StartupProject", ""); startupProject = memento.Get("StartupProject", "");
string configuration = memento.Get("ActiveConfiguration", activeConfiguration);
string platform = memento.Get("ActivePlatform", activePlatform);
// validate configuration and platform:
IList<string> available = solution.GetConfigurationNames();
if (!available.Contains(configuration))
configuration = available[0];
available = solution.GetPlatformNames();
if (!available.Contains(platform))
platform = available[0];
this.ActiveConfiguration = configuration;
this.ActivePlatform = platform;
} }
} }
} }

Loading…
Cancel
Save