Class: IronNails::View::View
- Inherits:
-
Object
- Object
- IronNails::View::View
- Extended by:
- Forwardable
- Includes:
- Core::Observable, Logging::ClassLogger
- Defined in:
- lib/ironnails/view/view.rb
Overview
encapsulates what IronNails sees as a view. That is the xaml proxy and some meta data for IronNails.
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
gets the collection of children for this view.
-
#container ⇒ Object
gets or sets the name of the component that will contain this view.
-
#controller ⇒ Object
gets or sets the name of the controller this view is associated with.
-
#element_name ⇒ Object
gets or sets the element name on the canvas for this view.
-
#loaded ⇒ Object
readonly
gets the flag that indicates if this view needs to be initialized or not.
-
#name ⇒ Object
gets or sets the name of this view.
-
#parent ⇒ Object
gets or sets the parent of this view.
-
#proxy ⇒ Object
gets or sets the xaml proxy that is associated with this view.
Instance Method Summary collapse
-
#<=>(view) ⇒ Object
(also: #compare_to)
sorting comparer for ordering lists.
-
#==(view) ⇒ Object
(also: #===, #equals)
equality comparer for easier selection.
-
#add_child(options) ⇒ Object
adds a child view definition to this view.
-
#add_control(target, control_proxy) ⇒ Object
adds this view to a component in an existing view.
- #added? ⇒ Boolean
-
#configure ⇒ Object
configures the view, it loads it and then triggers the observers for further configuration.
-
#data_context=(value) ⇒ Object
sets the data context of this view.
- #dispatcher ⇒ Object
- #find(view_name) ⇒ Object
-
#has_child?(view) ⇒ Boolean
returns whether this child view is alread contained by this view or not.
-
#has_container? ⇒ Boolean
indicates whether this view has to be rendered inside a component.
-
#has_datacontext? ⇒ Boolean
indicates whether this view has a data context set already or not.
-
#has_parent? ⇒ Boolean
indicates whether this view has a parent.
-
#initialize(options) ⇒ View
constructor
A new instance of View.
-
#instance ⇒ Object
configures and then returns an instance of the loaded view.
-
#load(mode = :complete) ⇒ Object
loads this view into memory and adds the children if needed.
-
#loaded? ⇒ Boolean
indicates whether we initialized this view already or not.
-
#on_proxy(&b) ⇒ Object
executes the code block on the view.
-
#sets_datacontext? ⇒ Boolean
indicates whether this view has to set its datacontext in order to function.
-
#show ⇒ Object
configures and then shows the window.
Methods included from Core::Observable
#add_observer, #count_observers, #delete_observer, #delete_observers, #notify_observers
Methods included from Logging::ClassLogger
Constructor Details
#initialize(options) ⇒ View
Returns a new instance of View.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ironnails/view/view.rb', line 40 def initialize() .each do |k, v| if k == :view_name @name = v else instance_variable_set "@#{k}", v end end @element_name ||= name @children = [] end |
Instance Attribute Details
#children ⇒ Object (readonly)
gets the collection of children for this view
38 39 40 |
# File 'lib/ironnails/view/view.rb', line 38 def children @children end |
#container ⇒ Object
gets or sets the name of the component that will contain this view
29 30 31 |
# File 'lib/ironnails/view/view.rb', line 29 def container @container end |
#controller ⇒ Object
gets or sets the name of the controller this view is associated with
32 33 34 |
# File 'lib/ironnails/view/view.rb', line 32 def controller @controller end |
#element_name ⇒ Object
gets or sets the element name on the canvas for this view
20 21 22 |
# File 'lib/ironnails/view/view.rb', line 20 def element_name @element_name end |
#loaded ⇒ Object (readonly)
gets the flag that indicates if this view needs to be initialized or not
35 36 37 |
# File 'lib/ironnails/view/view.rb', line 35 def loaded @loaded end |
#name ⇒ Object
gets or sets the name of this view
17 18 19 |
# File 'lib/ironnails/view/view.rb', line 17 def name @name end |
#parent ⇒ Object
gets or sets the parent of this view
26 27 28 |
# File 'lib/ironnails/view/view.rb', line 26 def parent @parent end |
#proxy ⇒ Object
gets or sets the xaml proxy that is associated with this view
23 24 25 |
# File 'lib/ironnails/view/view.rb', line 23 def proxy @proxy end |
Instance Method Details
#<=>(view) ⇒ Object Also known as: compare_to
sorting comparer for ordering lists
180 181 182 |
# File 'lib/ironnails/view/view.rb', line 180 def <=>(view) self.name <=> command.view.name end |
#==(view) ⇒ Object Also known as: ===, equals
equality comparer for easier selection
172 173 174 |
# File 'lib/ironnails/view/view.rb', line 172 def ==(view) view.respond_to?(:name) ? self.name == view.name : self.name = view.to_sym end |
#add_child(options) ⇒ Object
adds a child view definition to this view.
127 128 129 130 131 132 133 |
# File 'lib/ironnails/view/view.rb', line 127 def add_child() child = children.find { |vw| vw.name == [:name] } children.delete(child) unless child.nil? children << View.new(.merge(:parent => self, :controller => controller)) logger.debug("added child view (#{[:name]} to #{name})", IRONNAILS_FRAMEWORKNAME) self end |
#add_control(target, control_proxy) ⇒ Object
adds this view to a component in an existing view
77 78 79 80 |
# File 'lib/ironnails/view/view.rb', line 77 def add_control(target, control_proxy) proxy.add_control(target, control_proxy) self end |
#added? ⇒ Boolean
52 53 54 |
# File 'lib/ironnails/view/view.rb', line 52 def added? @added end |
#configure ⇒ Object
configures the view, it loads it and then triggers the observers for further configuration
121 122 123 124 |
# File 'lib/ironnails/view/view.rb', line 121 def configure load notify_observers :configuring, self end |
#data_context=(value) ⇒ Object
sets the data context of this view
104 105 106 |
# File 'lib/ironnails/view/view.rb', line 104 def data_context=(value) self.proxy.data_context = value end |
#dispatcher ⇒ Object
82 83 84 |
# File 'lib/ironnails/view/view.rb', line 82 def dispatcher proxy.instance.dispatcher end |
#find(view_name) ⇒ Object
166 167 168 169 |
# File 'lib/ironnails/view/view.rb', line 166 def find(view_name) return self if name == view_name.to_sym || view_name.nil? children.find { |cv| cv.name == view_name } end |
#has_child?(view) ⇒ Boolean
returns whether this child view is alread contained by this view or not
136 137 138 |
# File 'lib/ironnails/view/view.rb', line 136 def has_child?(view) children.any? { |vw| vw == view } end |
#has_container? ⇒ Boolean
indicates whether this view has to be rendered inside a component
62 63 64 |
# File 'lib/ironnails/view/view.rb', line 62 def has_container? !container.nil? end |
#has_datacontext? ⇒ Boolean
indicates whether this view has a data context set already or not
162 163 164 |
# File 'lib/ironnails/view/view.rb', line 162 def has_datacontext? !proxy.nil? && !proxy.instance.data_context.nil? end |
#has_parent? ⇒ Boolean
indicates whether this view has a parent
72 73 74 |
# File 'lib/ironnails/view/view.rb', line 72 def has_parent? !parent.nil? end |
#instance ⇒ Object
configures and then returns an instance of the loaded view
115 116 117 118 |
# File 'lib/ironnails/view/view.rb', line 115 def instance configure proxy.instance end |
#load(mode = :complete) ⇒ Object
loads this view into memory and adds the children if needed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/ironnails/view/view.rb', line 87 def load(mode = :complete) unless @loaded || mode == :reload self.proxy = XamlProxy.load(name) proxy.instance.name = element_name.to_s.to_clr_string if has_parent? @loaded = true #notify_observers :loaded, self end if has_container? && has_parent? && mode == :complete && !added? parent.add_control(container, proxy) @added = true end children.each { |cv| cv.load } logger.debug("loaded view #{name}", IRONNAILS_FRAMEWORKNAME) self end |
#loaded? ⇒ Boolean
indicates whether we initialized this view already or not
57 58 59 |
# File 'lib/ironnails/view/view.rb', line 57 def loaded? @loaded end |
#on_proxy(&b) ⇒ Object
executes the code block on the view
151 152 153 154 155 |
# File 'lib/ironnails/view/view.rb', line 151 def on_proxy(&b) load #proxy.instance_eval(&b) b.call proxy end |
#sets_datacontext? ⇒ Boolean
indicates whether this view has to set its datacontext in order to function
67 68 69 |
# File 'lib/ironnails/view/view.rb', line 67 def sets_datacontext? !has_parent? || !!@sets_datacontext end |
#show ⇒ Object
configures and then shows the window
109 110 111 112 |
# File 'lib/ironnails/view/view.rb', line 109 def show configure self.proxy.show end |