Class: IronNails::View::XamlProxy
- Inherits:
-
Object
- Object
- IronNails::View::XamlProxy
- Includes:
- Core::Observable, Logging::ClassLogger, Extensions::EventSupport, Extensions::SubViewSupport, Extensions::TimerSupport
- Defined in:
- lib/ironnails/view/xaml_proxy.rb
Overview
The IronNails::View::XamlProxy class wraps a xaml file and brings it alive
Instance Attribute Summary collapse
-
#instance ⇒ Object
readonly
gets the instance of the view.
-
#view_extension ⇒ Object
gets or sets the extension for the view file.
-
#view_name ⇒ Object
gets or sets the name of the view.
-
#view_path ⇒ Object
readonly
returns the path to the file for the current view.
Class Method Summary collapse
-
.load(view_name) ⇒ Object
creates an instance of the view specified by the
view_name
.
Instance Method Summary collapse
- #get_property(element, method, *args, &b) ⇒ Object
-
#initialize(name) ⇒ XamlProxy
constructor
A new instance of XamlProxy.
- #invoke(element, method, *args, &b) ⇒ Object
-
#load_view ⇒ Object
loads the view into the instance variable.
- #method_missing(sym, *args, &blk) ⇒ Object
- #play_storyboard(storyboard_name) ⇒ Object
-
#refresh ⇒ Object
tells this proxy to render itself with the changed information.
-
#show ⇒ Object
shows the proxied view.
- #stop_storyboard(storyboard_name) ⇒ Object
- #visibility=(visi) ⇒ Object
Methods included from Core::Observable
#add_observer, #count_observers, #delete_observer, #delete_observers, #notify_observers
Methods included from Extensions::SubViewSupport
Methods included from Extensions::TimerSupport
#add_timer, #attached?, #start_timer, #stop_timer
Methods included from Extensions::CommandSupport
Methods included from Extensions::ThreadingSupport
Methods included from Extensions::EventSupport
Methods included from Logging::ClassLogger
Constructor Details
#initialize(name) ⇒ XamlProxy
Returns a new instance of XamlProxy.
144 145 146 147 |
# File 'lib/ironnails/view/xaml_proxy.rb', line 144 def initialize(name) @view_name = name @view_extension = ".xaml" end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &blk) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/ironnails/view/xaml_proxy.rb', line 196 def method_missing(sym, *args, &blk) # First we check if we can find a named control # When we can't find a control we'll check if we can find # a method on the view instance by that name, if that is the # case we will call that method otherwise we'll return the control # if we found one. When no method or control could be found we # delegate to the default behavior obj = @instance.find_name(sym.to_s.to_clr_string) nmsym = sym.to_s.camelize.to_sym if @instance.respond_to?(nmsym) && obj.nil? @instance.send sym, *args, &blk else obj.nil? ? super : obj end end |
Instance Attribute Details
#instance ⇒ Object (readonly)
gets the instance of the view
135 136 137 |
# File 'lib/ironnails/view/xaml_proxy.rb', line 135 def instance @instance end |
#view_extension ⇒ Object
gets or sets the extension for the view file. defaults to xaml
139 140 141 |
# File 'lib/ironnails/view/xaml_proxy.rb', line 139 def view_extension @view_extension end |
#view_name ⇒ Object
gets or sets the name of the view
132 133 134 |
# File 'lib/ironnails/view/xaml_proxy.rb', line 132 def view_name @view_name end |
#view_path ⇒ Object (readonly)
returns the path to the file for the current view. this is the file we’ll be the proxy for
142 143 144 |
# File 'lib/ironnails/view/xaml_proxy.rb', line 142 def view_path @view_path end |
Class Method Details
.load(view_name) ⇒ Object
creates an instance of the view specified by the view_name
215 216 217 218 219 |
# File 'lib/ironnails/view/xaml_proxy.rb', line 215 def load(view_name) vw = new view_name.to_s vw.load_view vw end |
Instance Method Details
#get_property(element, method, *args, &b) ⇒ Object
177 178 179 |
# File 'lib/ironnails/view/xaml_proxy.rb', line 177 def get_property(element, method, *args, &b) send(element.to_sym).send(method.to_sym, *args, &b) end |
#invoke(element, method, *args, &b) ⇒ Object
173 174 175 |
# File 'lib/ironnails/view/xaml_proxy.rb', line 173 def invoke(element, method, *args, &b) instance.send(element.to_sym).send(method.to_sym, *args, &b) end |
#load_view ⇒ Object
loads the view into the instance variable
150 151 152 153 154 |
# File 'lib/ironnails/view/xaml_proxy.rb', line 150 def load_view @instance = XamlReader.load_from_path view_path if File.exists? view_path @instance = view_name.to_s.classify.new if @instance.nil? @instance end |
#play_storyboard(storyboard_name) ⇒ Object
181 182 183 184 |
# File 'lib/ironnails/view/xaml_proxy.rb', line 181 def play_storyboard(storyboard_name) storyboard = instance.resources[storyboard_name.to_s.to_clr_string] storyboard.begin instance unless storyboard.nil? end |
#refresh ⇒ Object
tells this proxy to render itself with the changed information
192 193 194 |
# File 'lib/ironnails/view/xaml_proxy.rb', line 192 def refresh @instance.refresh end |
#show ⇒ Object
shows the proxied view
169 170 171 |
# File 'lib/ironnails/view/xaml_proxy.rb', line 169 def show WpfApplication.current.has_main_window? ? instance.show : instance end |
#stop_storyboard(storyboard_name) ⇒ Object
186 187 188 189 |
# File 'lib/ironnails/view/xaml_proxy.rb', line 186 def stop_storyboard(storyboard_name) storyboard = instance.resources[storyboard_name.to_s.to_clr_string] storyboard.stop instance unless storyboard.nil? end |
#visibility=(visi) ⇒ Object
164 165 166 |
# File 'lib/ironnails/view/xaml_proxy.rb', line 164 def visibility=(visi) instance.visibility = visi.to_sym.to_visibility if instance.respond_to?(:visibility) end |