lib/glimmer/swt/shell_proxy.rb in glimmer-dsl-opal-0.10.0 vs lib/glimmer/swt/shell_proxy.rb in glimmer-dsl-opal-0.10.1
- old
+ new
@@ -45,13 +45,11 @@
HEIGHT_MIN = 0
def initialize(args)
@args = args
@children = []
- # TODO consider the implication of emptying the body
- Document.find('body').empty unless ENV['RUBY_ENV'] == 'test'
- render
+ render # TODO attach to specific element
@layout = FillLayoutProxy.new(self, [])
@layout.margin_width = 0
@layout.margin_height = 0
self.minimum_size = Point.new(WIDTH_MIN, HEIGHT_MIN)
DisplayProxy.instance.shells << self
@@ -93,11 +91,11 @@
end
def dom
i = 0
body_id = id
- body_class = ([name] + css_classes.to_a).join(' ')
+ body_class = ([name, 'hide'] + css_classes.to_a).join(' ')
@dom ||= html {
div(id: body_id, class: body_class) {
# TODO consider supporting the idea of dynamic CSS building on close of shell that adds only as much CSS as needed for widgets that were mentioned
style(class: 'common-style') {
style_dom_css
@@ -113,13 +111,37 @@
}
}
}.to_s
end
- def open
- # TODO consider the idea of delaying rendering till the open method
- # TODO make it start as hidden and show shell upon open
-# DisplayProxy.instance.shells << self
+ def open(async: true)
+ work = lambda do
+ unless @open
+ DisplayProxy.instance.shells.select(&:open?).reject {|s| s == self}.map(&:hide)
+ dom_element.remove_class('hide')
+ @open = true
+ end
+ end
+ if async
+ DisplayProxy.instance.async_exec(&work)
+ else
+ work.call
+ end
+ end
+
+ def hide
+ dom_element.add_class('hide')
+ @open = false
+ end
+
+ def close
+ DisplayProxy.instance.shells.delete(self)
+ dom_element.remove
+ @open = false
+ end
+
+ def open?
+ @open
end
end
end
end