1 using System.Collections.ObjectModel;
2 using System.Collections.Generic;
3 
4 namespace WeifenLuo.WinFormsUI.Docking
5 {
6     public class DockPaneCollection : ReadOnlyCollection<DockPane>
7     {
DockPaneCollection()8         internal DockPaneCollection()
9             : base(new List<DockPane>())
10         {
11         }
12 
Add(DockPane pane)13         internal int Add(DockPane pane)
14         {
15             if (Items.Contains(pane))
16                 return Items.IndexOf(pane);
17 
18             Items.Add(pane);
19             return Count - 1;
20         }
21 
AddAt(DockPane pane, int index)22         internal void AddAt(DockPane pane, int index)
23         {
24             if (index < 0 || index > Items.Count - 1)
25                 return;
26 
27             if (Contains(pane))
28                 return;
29 
30             Items.Insert(index, pane);
31         }
32 
Dispose()33         internal void Dispose()
34         {
35             if (PatchController.EnableNestedDisposalFix == true)
36             {
37                 List<DockPane> collection = new List<DockPane>(Items);
38                 foreach (var dockPane in collection)
39                 {
40                     dockPane.Close();
41                 }
42 
43                 collection.Clear();
44                 return;
45             }
46 
47             for (int i=Count - 1; i>=0; i--)
48                 this[i].Close();
49         }
50 
Remove(DockPane pane)51         internal void Remove(DockPane pane)
52         {
53             Items.Remove(pane);
54         }
55     }
56 }
57