lib/shoes/swt/app.rb in shoes-swt-4.0.0.pre11 vs lib/shoes/swt/app.rb in shoes-swt-4.0.0.pre12

- old
+ new

@@ -66,11 +66,11 @@ force_shell_size @shell.open @started = true self.fullscreen = true if dsl.start_as_fullscreen? flush - ::Swt.event_loop { ::Shoes::Swt.main_app.disposed? } if main_app? + ::Swt.event_loop { ::Shoes::Swt.apps.all?(&:disposed?) } if main_app? end def quit @image.dispose @background.dispose @@ -229,18 +229,26 @@ new_width = @dsl.width + frame_x_decorations new_height = @dsl.height + frame_y_decorations @shell.setSize(new_width, new_height) end - def main_window_on_close + def on_close lambda do |_event| - ::Swt.display.dispose - ::Shoes::Swt::App.mark_main_app_closed - Dir[File.join(Dir.tmpdir, "__shoes4_*.png")].each { |f| File.delete f } + # Only do final cleanup if this is the last open window around + if finished? + ::Swt.display.dispose + ::Shoes::Swt::App.mark_main_app_closed + Dir[File.join(Dir.tmpdir, "__shoes4_*.png")].each { |f| File.delete f } + end end end + def finished? + # When closing we're done if we're the last undisposed window around + ::Shoes::Swt.apps.reject(&:disposed?) == [self] + end + def main_window_style style = ::Swt::SWT::CLOSE | ::Swt::SWT::MIN | ::Swt::SWT::V_SCROLL style |= ::Swt::SWT::RESIZE | ::Swt::SWT::MAX if @dsl.opts[:resizable] style |= ::Swt::SWT::APPLICATION_MODAL if @dsl.opts[:modal] style |= ::Swt::SWT::ON_TOP if @dsl.opts[:always_on_top] @@ -280,10 +288,10 @@ attach_click_listener end def attach_shell_event_listeners @shell.addControlListener ShellControlListener.new(self) - @shell.addListener(::Swt::SWT::Close, main_window_on_close) if main_app? + @shell.addListener(::Swt::SWT::Close, on_close) @shell.addListener(::Swt::SWT::Close, unregister_app) end def unregister_app proc do |_event|