1 #region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
2 /************************************************************************************
4 ' Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
5 ' Copyright 2000-2002 Philip A. Craig
7 ' This software is provided 'as-is', without any express or implied warranty. In no
8 ' event will the authors be held liable for any damages arising from the use of this
11 ' Permission is granted to anyone to use this software for any purpose, including
12 ' commercial applications, and to alter it and redistribute it freely, subject to the
13 ' following restrictions:
15 ' 1. The origin of this software must not be misrepresented; you must not claim that
16 ' you wrote the original software. If you use this software in a product, an
17 ' acknowledgment (see the following) in the product documentation is required.
19 ' Portions Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
20 ' or Copyright 2000-2002 Philip A. Craig
22 ' 2. Altered source versions must be plainly marked as such, and must not be
23 ' misrepresented as being the original software.
25 ' 3. This notice may not be removed or altered from any source distribution.
27 '***********************************************************************************/
31 using System.Collections;
36 /// Summary description for ProjectConfigCollection.
38 public class ProjectConfigCollection : CollectionBase
40 protected NUnitProject project;
42 public ProjectConfigCollection( NUnitProject project )
44 this.project = project;
49 public NUnitProject Project
51 get { return project; }
54 public ArrayList Names
58 ArrayList names = new ArrayList();
60 foreach( ProjectConfig config in InnerList )
61 names.Add( config.Name );
67 public ProjectConfig this[int index]
69 get { return (ProjectConfig)InnerList[index]; }
72 public ProjectConfig this[string name]
76 int index = IndexOf( name );
77 return index >= 0 ? (ProjectConfig)InnerList[index]: null;
84 public void Add( ProjectConfig config )
87 config.Project = this.Project;
90 public void Add( string name )
92 Add( new ProjectConfig( name ) );
95 public void Remove( ProjectConfig config )
97 string name = config.Name;
98 bool wasActive = name == this.Project.ActiveConfigName;
99 List.Remove( config );
102 public void Remove( string name )
104 int index = IndexOf( name );
107 bool wasActive = name == this.Project.ActiveConfigName;
112 public int IndexOf( ProjectConfig config )
114 return InnerList.IndexOf( config );
117 public int IndexOf( string name )
119 for( int index = 0; index < InnerList.Count; index++ )
121 ProjectConfig config = (ProjectConfig)InnerList[index];
122 if( config.Name == name )
129 public bool Contains( ProjectConfig config )
131 return InnerList.Contains( config );
134 public bool Contains( string name )
136 return IndexOf( name ) >= 0;
139 protected override void OnRemoveComplete( int index, object obj )
141 ProjectConfig config = obj as ProjectConfig;
142 this.Project.OnProjectChange( ProjectChangeType.RemoveConfig, config.Name );
145 protected override void OnInsertComplete( int index, object obj )
147 ProjectConfig config = obj as ProjectConfig;
148 project.OnProjectChange( ProjectChangeType.AddConfig, config.Name );
149 config.Changed += new EventHandler( OnConfigChanged );
152 protected override void OnSetComplete( int index, object oldValue, object newValue )
154 ProjectConfig oldConfig = oldValue as ProjectConfig;
155 ProjectConfig newConfig = newValue as ProjectConfig;
156 bool active = oldConfig.Name == project.ActiveConfigName;
158 project.OnProjectChange( ProjectChangeType.UpdateConfig, newConfig.Name );
161 private void OnConfigChanged( object sender, EventArgs e )
163 ProjectConfig config = sender as ProjectConfig;
164 project.OnProjectChange( ProjectChangeType.UpdateConfig, config.Name );