diff options
author | Mike Krüger <mkrueger@xamarin.com> | 2011-07-28 11:39:08 +0400 |
---|---|---|
committer | Mike Krüger <mkrueger@xamarin.com> | 2011-07-28 11:39:08 +0400 |
commit | 3968c94d64af085d2bc3bec0599177dd0a68807c (patch) | |
tree | a9eb00d0d1da834e321f3d88572c5a3661c24d8e /main | |
parent | ee3421823555a114477035e7bf60ad7b8260896f (diff) |
When creating Xcode projects, groups are generated to organize the
files (i.e. hide .m files in a "support" group).
Diffstat (limited to 'main')
3 files changed, 67 insertions, 11 deletions
diff --git a/main/src/addins/MonoDevelop.MacDev/XcodeIntegration/PBXGroup.cs b/main/src/addins/MonoDevelop.MacDev/XcodeIntegration/PBXGroup.cs index ec1552c03f..4dabe79a1a 100644 --- a/main/src/addins/MonoDevelop.MacDev/XcodeIntegration/PBXGroup.cs +++ b/main/src/addins/MonoDevelop.MacDev/XcodeIntegration/PBXGroup.cs @@ -33,15 +33,21 @@ namespace MonoDevelop.MacDev.XcodeIntegration class PBXGroup : XcodeObject { string name; - List<PBXFileReference> children; + List<XcodeObject> children; + + public string Name { + get { + return name; + } + } public PBXGroup (string name) { this.name = name; - this.children = new List<PBXFileReference> (); + this.children = new List<XcodeObject> (); } - public void AddChild (PBXFileReference file) + public void AddChild (XcodeObject file) { this.children.Add (file); } @@ -52,14 +58,23 @@ namespace MonoDevelop.MacDev.XcodeIntegration } } + static string QuoteOnDemand (string name) + { + if (name.IndexOf (' ') >= 0) + return "\"" + name + "\""; + return name; + } + public override string ToString () { var sb = new StringBuilder (); sb.AppendFormat ("{0} = {{\n\t\t\tisa = {1};\n\t\t\tchildren = (\n", Token, Type); - foreach (PBXFileReference file in children) - sb.AppendFormat ("\t\t\t\t{0},\n", file.Token); - sb.AppendFormat ("\t\t\t);\n\t\t\tname = {0};\n\t\t\tsourceTree = \"<group>\";\n\t\t}};", name); + children.Sort ((x, y) => x.ToString ().CompareTo (y.ToString ())); + foreach (var child in children) + sb.AppendFormat ("\t\t\t\t{0},\n", child.Token); + var quotedName = QuoteOnDemand (name); + sb.AppendFormat ("\t\t\t);\n\t\t\tname = {0};\n\t\t\tsourceTree = \"<group>\";\n\t\t}};", quotedName); return sb.ToString (); } diff --git a/main/src/addins/MonoDevelop.MacDev/XcodeIntegration/XcodeProject.cs b/main/src/addins/MonoDevelop.MacDev/XcodeIntegration/XcodeProject.cs index cef1c4c99b..0a4a63a829 100644 --- a/main/src/addins/MonoDevelop.MacDev/XcodeIntegration/XcodeProject.cs +++ b/main/src/addins/MonoDevelop.MacDev/XcodeIntegration/XcodeProject.cs @@ -28,6 +28,8 @@ using System; using System.IO; using System.Text; using System.Collections.Generic; +using System.Linq; + namespace MonoDevelop.MacDev.XcodeIntegration { @@ -38,6 +40,7 @@ namespace MonoDevelop.MacDev.XcodeIntegration List<PBXFileReference> files; List<PBXBuildFile> sources; PBXGroup group; + List<PBXGroup> groups; PBXFileReference target; PBXNativeTarget nativeTarget; XCConfigurationList nativeConfigurationList; @@ -51,12 +54,15 @@ namespace MonoDevelop.MacDev.XcodeIntegration public XcodeProject (string name, string sdkRoot, string configName) { this.name = name; - this.group = new PBXGroup ("CustomTemplate"); + group = new PBXGroup ("CustomTemplate"); this.frameworksBuildPhase = new PBXFrameworksBuildPhase (); this.resourcesBuildPhase = new PBXResourcesBuildPhase (); this.sourcesBuildPhase = new PBXSourcesBuildPhase (); this.files = new List<PBXFileReference> (); this.sources = new List<PBXBuildFile> (); + this.groups = new List<PBXGroup> (); + this.groups.Add (group); + this.target = new PBXFileReference (name, string.Format ("{0}.app", name), "BUILT_PRODUCTS_DIR"); this.nativeConfigurationList = new XCConfigurationList (); this.projectConfigurationList = new XCConfigurationList (); @@ -111,6 +117,18 @@ namespace MonoDevelop.MacDev.XcodeIntegration return buildfile; } + PBXBuildFile AddFile (PBXGroup grp, string name, string path, string tree) + { + var fileref = new PBXFileReference (name, path, tree); + var buildfile = new PBXBuildFile (fileref); + + files.Add (fileref); + sources.Add (buildfile); + grp.AddChild (fileref); + + return buildfile; + } + void AddResource (string name, string path) { resourcesBuildPhase.AddResource (AddFile (name, path, "\"<group>\"")); @@ -127,7 +145,26 @@ namespace MonoDevelop.MacDev.XcodeIntegration //sourcesBuildPhase.AddSource (AddFile (Path.GetFileName (name), Path.GetDirectoryName (name), "\"<group>\"")); sourcesBuildPhase.AddSource (AddFile (name, name, "\"<group>\"")); } - + + internal void AddSource (PBXGroup grp, string name) + { + //sourcesBuildPhase.AddSource (AddFile (Path.GetFileName (name), Path.GetDirectoryName (name), "\"<group>\"")); + sourcesBuildPhase.AddSource (AddFile (grp, name, name, "\"<group>\"")); + } + + internal PBXGroup AddGroup (string name) + { + var result = new PBXGroup (name); + this.group.AddChild (result); + groups.Insert (0, result); + return result; + } + + internal PBXGroup GetGroup (string name) + { + return groups.FirstOrDefault (g => g.Name == name); + } + public void AddResource (string name) { AddResource (name, name); @@ -179,7 +216,8 @@ namespace MonoDevelop.MacDev.XcodeIntegration sb.Append ("/* End PBXFrameworksBuildPhase section */\n\n"); sb.Append ("/* Begin PBXGroup section */\n"); - sb.AppendFormat (" {0}\n", group); + foreach (var grp in groups) + sb.AppendFormat (" {0}\n", grp); sb.Append ("/* End PBXGroup section */\n\n"); sb.Append ("/* Begin PBXNativeTarget section */\n"); @@ -211,7 +249,7 @@ namespace MonoDevelop.MacDev.XcodeIntegration sb.Append (" };\n"); sb.AppendFormat (" rootObject = {0};\n", project.Token); sb.Append ("}"); - + Console.WriteLine (sb); return sb.ToString (); } } diff --git a/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeSyncedType.cs b/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeSyncedType.cs index 21579daddf..dc036ca316 100644 --- a/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeSyncedType.cs +++ b/main/src/addins/MonoDevelop.MacDev/XcodeSyncing/XcodeSyncedType.cs @@ -104,10 +104,13 @@ namespace MonoDevelop.MacDev.XcodeSyncing }); } + const string supportingFilesGroup = "Supporting Files"; public override void AddToProject (XcodeProject project, FilePath syncProjectDir) { project.AddSource (Type.ObjCName + ".h"); - project.AddSource (Type.ObjCName + ".m"); + + var grp = project.GetGroup (supportingFilesGroup) ?? project.AddGroup (supportingFilesGroup); + project.AddSource (grp, Type.ObjCName + ".m"); } public override string[] GetTargetRelativeFileNames () |