forked from baldurk/renderdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockContentCollection.cs
More file actions
175 lines (148 loc) · 4.32 KB
/
DockContentCollection.cs
File metadata and controls
175 lines (148 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
namespace WeifenLuo.WinFormsUI.Docking
{
public class DockContentCollection : ReadOnlyCollection<IDockContent>
{
private static List<IDockContent> _emptyList = new List<IDockContent>(0);
internal DockContentCollection()
: base(new List<IDockContent>())
{
}
internal DockContentCollection(DockPane pane)
: base(_emptyList)
{
m_dockPane = pane;
}
private DockPane m_dockPane = null;
private DockPane DockPane
{
get { return m_dockPane; }
}
public new IDockContent this[int index]
{
get
{
if (DockPane == null)
return Items[index] as IDockContent;
else
return GetVisibleContent(index);
}
}
internal int Add(IDockContent content)
{
#if DEBUG
if (DockPane != null)
throw new InvalidOperationException();
#endif
if (Contains(content))
return IndexOf(content);
Items.Add(content);
return Count - 1;
}
internal void AddAt(IDockContent content, int index)
{
#if DEBUG
if (DockPane != null)
throw new InvalidOperationException();
#endif
if (index < 0 || index > Items.Count - 1)
return;
if (Contains(content))
return;
Items.Insert(index, content);
}
public new bool Contains(IDockContent content)
{
if (DockPane == null)
return Items.Contains(content);
else
return (GetIndexOfVisibleContents(content) != -1);
}
public new int Count
{
get
{
if (DockPane == null)
return base.Count;
else
return CountOfVisibleContents;
}
}
public new int IndexOf(IDockContent content)
{
if (DockPane == null)
{
if (!Contains(content))
return -1;
else
return Items.IndexOf(content);
}
else
return GetIndexOfVisibleContents(content);
}
internal void Remove(IDockContent content)
{
if (DockPane != null)
throw new InvalidOperationException();
if (!Contains(content))
return;
Items.Remove(content);
}
private int CountOfVisibleContents
{
get
{
#if DEBUG
if (DockPane == null)
throw new InvalidOperationException();
#endif
int count = 0;
foreach (IDockContent content in DockPane.Contents)
{
if (content.DockHandler.DockState == DockPane.DockState)
count++;
}
return count;
}
}
private IDockContent GetVisibleContent(int index)
{
#if DEBUG
if (DockPane == null)
throw new InvalidOperationException();
#endif
int currentIndex = -1;
foreach (IDockContent content in DockPane.Contents)
{
if (content.DockHandler.DockState == DockPane.DockState)
currentIndex++;
if (currentIndex == index)
return content;
}
throw (new ArgumentOutOfRangeException());
}
private int GetIndexOfVisibleContents(IDockContent content)
{
#if DEBUG
if (DockPane == null)
throw new InvalidOperationException();
#endif
if (content == null)
return -1;
int index = -1;
foreach (IDockContent c in DockPane.Contents)
{
if (c.DockHandler.DockState == DockPane.DockState)
{
index++;
if (c == content)
return index;
}
}
return -1;
}
}
}