lib/osx/sugarcube-repl/repl.rb in sugarcube-2.12.3 vs lib/osx/sugarcube-repl/repl.rb in sugarcube-3.0.0

- old
+ new

@@ -1,8 +1,7 @@ module SugarCube - module Repl - module_function + class << Repl def window(index=nil) if index NSApplication.sharedApplication.windows[index] else @@ -18,28 +17,28 @@ window.windowController end def adjust_init(view) if view.is_a?(NSView) - @sugarcube_restore = { + @restore = { frame: SugarCube::Repl.frame, } end end def blink(color=nil) return unless check_sugarcube_view - blinking_view = NSView.alloc.initWithFrame([[0,0], @sugarcube_view.frame.size]) + blinking_view = NSView.alloc.initWithFrame([[0,0], @adjust_item.frame.size]) color = color.nscolor if color.respond_to?(:nscolor) blinking_view.backgroundColor = color blinking_view.alpha = 0 - if @sugarcube_view.window - blinking_view.frame = @sugarcube_view.convertRect([[0, 0], @sugarcube_view.frame.size], toView: @sugarcube_view.window) - @sugarcube_view.window.addSubview(blinking_view) + if @adjust_item.window + blinking_view.frame = @adjust_item.convertRect([[0, 0], @adjust_item.frame.size], toView: @adjust_item.window) + @adjust_item.window.addSubview(blinking_view) else - @sugarcube_view.addSubview(blinking_view) + @adjust_item.addSubview(blinking_view) end duration = 0.2 NSAnimationContext.runAnimationGroup(-> (context) do context.duration = duration * 2 @@ -62,26 +61,16 @@ end) end) end) end - def get_tree_selector(item) - if item.is_a? NSView - return :subviews - elsif item.is_a? NSWindow - item = item.contentView - return :subviews - elsif item.is_a? NSWindowController - return -> (ctlr) { [ctlr.window] } - elsif item.is_a? NSViewController - return -> (ctlr) { [ctlr.view] } - elsif item.is_a? NSMenu - return :itemArray - elsif item.is_a? NSMenuItem - return -> (menu_item) { [menu_item.menu] } - else - nil - end + def register_platform_tree_selectors + register_tree_selector(NSView, :subviews) + register_tree_selector(NSWindow) { |window| window.contentView.subviews } + register_tree_selector(NSWindowController) { |ctlr| [ctlr.window] } + register_tree_selector(NSViewController) { |ctlr| [ctlr.view] } + register_tree_selector(NSMenu, :itemArray) + register_tree_selector(NSMenuItem) { |menu_item| [menu_item.menu] } end def draw_tree_item(item) if item.is_a? NSView item.sugarcube_to_s superview: false