You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -9,50 +9,111 @@ Partial Public MustInherit Class MathElement
9
9
'++
10
10
11
11
Private_ParentAsMathElement
12
-
PublicPropertyParentAsMathElement
12
+
13
+
''' <summary>
14
+
''' Returns the element which attached this element.
15
+
''' </summary>
16
+
PublicReadOnlyPropertyParentAsMathElement
13
17
Get
14
18
Return_Parent
15
19
EndGet
16
-
Set(ByValvalueAsMathElement)
17
-
If_ParentIsNotNothingThen
18
-
' REMOVING THE CURRENT PARENT
19
-
IfvalueIsNothingThen
20
-
IfParent.Children.Contains(Me)Then
21
-
ThrowNewInvalidOperationException("Reseting the Parent property wasn't posssible because the parent still claims it owns the current element.")
22
-
Else
23
-
24
-
' Perform some cleanup
25
-
_Parent=Nothing
26
-
_ParentDocument=Nothing
27
-
_Selection=Nothing
28
-
29
-
' Raise the corresponding event
30
-
RaiseEventRemovedFromParent(Me,EventArgs.Empty)
31
-
32
-
EndIf
33
-
Else
34
-
' TODO: Maybe we can check if value is _Parent before throwing
35
-
' For now, we shall not do so, in order to find duplicate
36
-
' code errors
37
-
ThrowNewInvalidOperationException("Unable to modify the parent of an element after it has been set. Use Clone() to get a parent-free copy of this element, or remove it from its current parent.")
38
-
EndIf
20
+
EndProperty
21
+
22
+
''' <summary>
23
+
''' Changes the Parent of NewChild to this element
24
+
''' </summary>
25
+
''' <param name="NewChild">The element to attach to this element</param>
26
+
PublicSubAttach(ByValNewChildAsMathElement)
27
+
IfNewChildIsNothingThenThrowNewArgumentNullException("NewChild","The Attach method can't be used with a null argument.")
28
+
NewChild.SetParent(Me)
29
+
EndSub
30
+
31
+
''' <summary>
32
+
''' Reset the Parent of Child to null.
33
+
''' </summary>
34
+
''' <param name="Child"></param>
35
+
''' <remarks></remarks>
36
+
PublicSubDetach(ByValChildAsMathElement)
37
+
IfChild.ParentIsMeThenChild.ResetParent()_
38
+
ElseThrowNewArgumentException("Child must be a child of this element.")
39
+
EndSub
40
+
41
+
''' <summary>
42
+
''' Changes the value of the Parent property of this element.
43
+
''' </summary>
44
+
''' <param name="value">The new value for the Parent property</param>
45
+
''' <exception cref="InvalidOperationException">This functions throws an InvalidOperationException when this element already have a parent.</exception>
46
+
''' <exception cref="ArgumentException">This functions throws an ArgumentException when this element can't have 'value' as parent.</exception>
47
+
PrivateSubSetParent(ByValvalueAsMathElement)
48
+
If_ParentIsNotNothingThen
49
+
50
+
IfvalueIs_ParentThen
51
+
52
+
#IfDEBUGThen
53
+
' DON'T DO ANYTHING
54
+
Trace.TraceWarning("Multiple refefinition of the Parent property of an element. Spaghetti code suspected.")
55
+
#EndIf
56
+
39
57
Else
40
-
' ADDING A NEW PARENT
41
-
Ifvalue.Children.IsValidChild(Me)Then
42
58
43
-
' Perform the change
44
-
_Parent=value
59
+
' REMOVE THE CURRENT PARENT, AND RETRY
60
+
Try
45
61
46
-
' Raise the corresponding event
47
-
RaiseEventAttachedToParent(Me,EventArgs.Empty)
62
+
ResetParent()
63
+
SetParent(value)
64
+
65
+
CatchexAsException
66
+
67
+
ThrowNewInvalidOperationException("Unable to modify the parent of an element after it has been added to a children list. Please remove this element from its parent, or use the Clone() function to get a parent-free copy of this element.",ex)
68
+
69
+
EndTry
48
70
49
-
Else
50
-
ThrowNewArgumentException("This element is not recognised as a valid child of its new parent.","Parent")
51
-
EndIf
52
71
EndIf
53
-
EndSet
54
-
EndProperty
55
72
73
+
Else
74
+
75
+
' ADD THE NEW PARENT
76
+
Ifvalue.Children.CanContains(Me)Then
77
+
78
+
' Perform the change
79
+
_Parent=value
80
+
81
+
' Raise the corresponding event
82
+
RaiseEventAttachedToParent(Me,EventArgs.Empty)
83
+
84
+
Else
85
+
ThrowNewArgumentException("This element is not recognised as a valid child of its new parent.","Parent")
86
+
EndIf
87
+
88
+
EndIf
89
+
EndSub
90
+
91
+
''' <summary>
92
+
''' Resets the Parent property for this element.
93
+
''' </summary>
94
+
PrivateSubResetParent()
95
+
96
+
IfParent.Children.Contains(Me)Then
97
+
98
+
ThrowNewInvalidOperationException("Reseting the Parent property wasn't posssible because the parent still claims it owns the current element.")
99
+
100
+
Else
101
+
102
+
' Perform some cleanup
103
+
_Parent=Nothing
104
+
_ParentDocument=Nothing
105
+
_Selection=Nothing
106
+
107
+
' Raise the corresponding event
108
+
RaiseDetachedFromParent()
109
+
110
+
EndIf
111
+
112
+
EndSub
113
+
114
+
''' <summary>
115
+
''' Returns the last element in the Parent chain. If this element is hosted in a document, this function returns the same as ParentDocument.
0 commit comments