From 851fa495d732e8b97050541a2867394c6f3402fc Mon Sep 17 00:00:00 2001
From: Daniel Grunwald <daniel@danielgrunwald.de>
Date: Thu, 17 Jul 2008 20:58:18 +0000
Subject: [PATCH] Set SolutionPath environment variable when building C++
 projects.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3234 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
---
 samples/CppBackendBinding/CppProject.cs | 32 ++++++++++++++++++++-----
 samples/CppBackendBinding/FileGroup.cs  |  4 ++++
 2 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/samples/CppBackendBinding/CppProject.cs b/samples/CppBackendBinding/CppProject.cs
index 26ad202188..fa947907ef 100644
--- a/samples/CppBackendBinding/CppProject.cs
+++ b/samples/CppBackendBinding/CppProject.cs
@@ -79,13 +79,21 @@ namespace CppBackendBinding
 				}
 				foreach (FileItem item in items) {
 					FileGroup group = groups.Find(fg => fg.ItemType == item.ProjectItem.ItemType);
-					if (groups != null) {
+					if (group != null) {
 						group.XmlElement.AppendChild(item.XmlElement);
 					} else {
 						LoggingService.Warn("Couldn't find filter for item type " + item.ProjectItem.ItemType + ", the item was not saved!");
 					}
 				}
-				document.Save(fileName);
+				using (XmlWriter writer = XmlWriter.Create(fileName, new XmlWriterSettings {
+				                                           	NewLineOnAttributes = true,
+				                                           	Indent = true,
+				                                           	IndentChars = "\t",
+				                                           	Encoding = Encoding.Default
+				                                           }))
+				{
+					document.Save(writer);
+				}
 			}
 		}
 		
@@ -113,6 +121,17 @@ namespace CppBackendBinding
 			}
 		}
 		
+		public override ItemType GetDefaultItemType(string fileName)
+		{
+			string extension = Path.GetExtension(fileName);
+			if (string.Equals(extension, ".c", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".cpp", StringComparison.OrdinalIgnoreCase))
+				return ItemType.Compile;
+			else if (string.Equals(extension, ".h", StringComparison.OrdinalIgnoreCase))
+				return ItemType.Header;
+			else
+				return base.GetDefaultItemType(fileName);
+		}
+		
 		#region IProjectAllowChangeConfigurations
 		// TODO: Configuration/Platform handling
 		bool IProjectAllowChangeConfigurations.RenameProjectConfiguration(string oldName, string newName)
@@ -222,6 +241,7 @@ namespace CppBackendBinding
 			p.StartInfo.CreateNoWindow = true;
 			p.StartInfo.UseShellExecute = false;
 			p.StartInfo.EnvironmentVariables["VCBUILD_DEFAULT_CFG"] = options.Configuration + "|" + options.Platform;
+			p.StartInfo.EnvironmentVariables["SolutionPath"] = ParentSolution.Directory;
 			
 			p.EnableRaisingEvents = true;
 			p.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) {
@@ -229,8 +249,8 @@ namespace CppBackendBinding
 					BuildError error = ParseError(e.Data);
 					if (error != null)
 						feedbackSink.ReportError(error);
-//					else
-					feedbackSink.ReportMessage(e.Data);
+					else
+						feedbackSink.ReportMessage(e.Data);
 				}
 			};
 			p.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) {
@@ -238,8 +258,8 @@ namespace CppBackendBinding
 					BuildError error = ParseError(e.Data);
 					if (error != null)
 						feedbackSink.ReportError(error);
-//					else
-					feedbackSink.ReportError(new BuildError(null, e.Data));
+					else
+						feedbackSink.ReportError(new BuildError(null, e.Data));
 				}
 			};
 			p.Exited += delegate(object sender, EventArgs e) {
diff --git a/samples/CppBackendBinding/FileGroup.cs b/samples/CppBackendBinding/FileGroup.cs
index ab0033bbf3..ec65ee926a 100644
--- a/samples/CppBackendBinding/FileGroup.cs
+++ b/samples/CppBackendBinding/FileGroup.cs
@@ -23,6 +23,10 @@ namespace CppBackendBinding
 		
 		public FileGroup(CppProject project, XmlElement filterElement)
 		{
+			if (project == null)
+				throw new ArgumentNullException("project");
+			if (filterElement == null)
+				throw new ArgumentNullException("filterElement");
 			this.Project = project;
 			this.XmlElement = filterElement;
 			switch (filterElement.GetAttribute("UniqueIdentifier")) {