-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCobaltControl.cs
101 lines (79 loc) · 2.67 KB
/
CobaltControl.cs
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
using System.Collections.Generic;
using System.Web.UI;
using Cobalt.Html;
using Cobalt.Web;
namespace Cobalt {
/// <summary>
/// CobaltElement that behaves as a UserControl
/// </summary>
public abstract class CobaltControl : CobaltElement {
#region Constructors
/// <summary>
/// CobaltControls may create empty elements
/// </summary>
protected CobaltControl() :
base(new HtmlNode[] { }) {
this._PrepareCobaltControl();
}
/// <summary>
/// Creates a new CobaltControl from the provided Html
/// </summary>
public CobaltControl(string html)
: base(HtmlNode.Parse(html)) {
this._PrepareCobaltControl();
}
#endregion
#region Properties
//has this control been built yet or not
private bool _HasBeenConstructed;
//holds if the control has performed the finalize phase
private bool _HasFinalized;
/// <summary>
/// Returns the currently selected nodes for this control
/// </summary>
public override IEnumerable<HtmlNode> Selected {
get {
this._CheckForConstruction();
return base.Selected;
}
set {
this._CheckForConstruction();
base.Selected = value;
}
}
#endregion
#region Event Methods
/// <summary>
/// Called before this control can be queried to allow
/// any setup code to run in advance
/// </summary>
protected virtual void OnConstruct() { }
/// <summary>
/// Used to finalize any changes after Ready actions have been applied
/// </summary>
protected virtual void OnFinalize() { }
#endregion
#region Private Methods
//prepares the construct event to be called
private void _PrepareCobaltControl() {
this._HasBeenConstructed = false;
this._HasFinalized = false;
CobaltContext.Current.RegisterFinalizeEvent(CobaltContext.Current.Rendering, this.PerformFinalize);
}
//performs the contruct event if needed
private void _CheckForConstruction() {
if (this._HasBeenConstructed) { return; }
this._HasBeenConstructed = true;
this.OnConstruct();
}
/// <summary>
/// Forces a call to OnFinalize
/// </summary>
internal void PerformFinalize() {
if (this._HasFinalized) { return; }
this._HasFinalized = true;
this.OnFinalize();
}
#endregion
}
}