lib/cocoa/sugarcube-repl/repl.rb in sugarcube-2.8.2 vs lib/cocoa/sugarcube-repl/repl.rb in sugarcube-2.9.1

- old
+ new

@@ -221,12 +221,22 @@ self.origin left, top end alias c center + def set_default(item) + @sugarcube_default_item = item + end + + def clear_default + @sugarcube_default_item = nil + end + def get_tree_item(item) - if item.nil? || item.is_a?(Fixnum) + if item.nil? && @sugarcube_default_item + @sugarcube_default_item + elsif item.nil? || item.is_a?(Fixnum) window(item) else item end end @@ -253,10 +263,18 @@ 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 @@ -270,9 +288,14 @@ SugarCube::Repl::draw_tree(item, selector) end puts '' return item + end + + def register_tree_selector(klass, selector=nil, &sel_blk) + @sugarcube_tree_selectors ||= {} + @sugarcube_tree_selectors[klass] = selector || sel_blk end # Draws the tree items def draw_tree(item, selector, tab=nil, is_last=true, items_index=0) space = ' '