Method: SugarCube::Repl.tree

Defined in:
lib/cocoa/sugarcube-repl/repl.rb

.tree(item = nil, selector = nil, &sel_blk) ⇒ Object

Parameters:

  • item (defaults to: nil)

    this can be a tree-like item (View, ViewController, CALayer, Menu) or an integer, in which case it will select that window. Defalt is to display the keyWindow

  • selector (defaults to: nil)

    If you pass an unsupported object to tree, you will need to pass a selector as well - this method should return an array of items which are passed recursively to tree



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/cocoa/sugarcube-repl/repl.rb', line 252

def tree(item=nil, selector=nil, &sel_blk)
  item = get_tree_item(item)

  if sel_blk && selector
    raise "You can't hand me a block AND a selector.  I don't know what to do with them!"
  elsif sel_blk
    selector = sel_blk
  elsif ! selector
    if item.is_a? CALayer
      selector = :sublayers
    elsif defined?(SKNode) && item.is_a?(SKNode)
      selector = :children
    else
      selector = get_tree_selector(item)
    end

    if !selector && @sugarcube_tree_selectors
      klass = item.class
      while klass && !selector
        selector = @sugarcube_tree_selectors[klass]
        klass = klass.superclass
      end
    end

    unless selector
      raise "Unable to determine a SugarCube::Repl::tree selector for #{item.class.to_s}"
    end
  end

  @sugarcube_items = SugarCube::Repl::build_tree(item, selector)
  if @sugarcube_collapsed_items
    @sugarcube_collapsed_items.keep_if { |v| @sugarcube_items.include? v }
  end
  if self.respond_to? :draw_tree
    draw_tree(item, selector)
  else
    SugarCube::Repl::draw_tree(item, selector)
  end
  puts ''

  return item
end