5
// Geoff Norton <gnorton@novell.com>
6
// Jeffrey Stedfast <jeff@xamarin.com>
8
// Copyright (c) 2011 Novell, Inc.
9
// Copyright (c) 2011 Xamarin Inc.
11
// Permission is hereby granted, free of charge, to any person obtaining a copy
12
// of this software and associated documentation files (the "Software"), to deal
13
// in the Software without restriction, including without limitation the rights
14
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
// copies of the Software, and to permit persons to whom the Software is
16
// furnished to do so, subject to the following conditions:
18
// The above copyright notice and this permission notice shall be included in
19
// all copies or substantial portions of the Software.
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
31
using System.Collections;
32
using System.Collections.Generic;
34
namespace MonoDevelop.MacDev.XcodeIntegration
36
public class PBXGroup : XcodeObject, IEnumerable<XcodeObject>
38
XcodeObjectSortDirection sort;
39
List<XcodeObject> children;
42
public PBXGroup (string name, XcodeObjectSortDirection sortDirection = XcodeObjectSortDirection.Ascending)
44
children = new List<XcodeObject> ();
45
this.sort = sortDirection;
49
public override string Name {
51
return name ?? "Main Group";
55
public void AddChild (XcodeObject child)
60
public override XcodeType Type {
62
return XcodeType.PBXGroup;
66
public PBXGroup GetGroup (string name)
68
foreach (var v in children)
69
if (v is PBXGroup && v.Name == name)
74
public override string ToString ()
76
var sb = new StringBuilder ();
79
sb.AppendFormat ("{0} /* {1} */ = {{\n", Token, Name);
81
sb.AppendFormat ("{0} = {{\n", Token);
82
sb.AppendFormat ("\t\t\tisa = {0};\n", Type);
83
sb.AppendFormat ("\t\t\tchildren = (\n");
84
if (sort != XcodeObjectSortDirection.None)
85
children.Sort (new XcodeObjectComparer (sort));
86
foreach (var child in children)
87
sb.AppendFormat ("\t\t\t\t{0} /* {1} */,\n", child.Token, child.Name);
88
sb.AppendFormat ("\t\t\t);\n");
90
sb.AppendFormat ("\t\t\tname = \"{0}\";\n", name);
91
sb.AppendFormat ("\t\t\tsourceTree = \"<group>\";\n");
92
sb.AppendFormat ("\t\t}};");
94
return sb.ToString ();
97
#region IEnumerable implementation
98
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator ()
100
return ((System.Collections.IEnumerable)children).GetEnumerator ();
103
public IEnumerator<XcodeObject> GetEnumerator ()
105
return children.GetEnumerator ();