lib/shoes/swt/app.rb in shoes-swt-4.0.0.pre7 vs lib/shoes/swt/app.rb in shoes-swt-4.0.0.pre8

- old
+ new

@@ -1,9 +1,9 @@ class Shoes module Swt shoes_icon = ::Shoes::ICON - if shoes_icon.include? '.jar!' + if shoes_icon.include? 'uri:classloader' ICON = File.join(Dir.tmpdir, 'shoes-icon.png').freeze open ICON, 'wb' do |fw| open shoes_icon, 'rb' do |fr| fw.write fr.read end @@ -20,20 +20,41 @@ include Common::Clickable attr_reader :dsl, :real, :shell, :click_listener def initialize(dsl) + if self.class.main_app_closed? + Shoes.logger.error <<-EOS +Sorry! You can't start another Shoes.app at after the main one has already +finished like that! If you need multiple windows, try it more like this: + + Shoes.app do + para "first!" + Shoes.app do + para "second!" + end + end +EOS + exit 1 + end + @dsl = dsl + ::Swt::Widgets::Display.app_name = @dsl.app_title + + ::Shoes::Swt::App.setup_system_colors + ::Shoes::Swt::Font.setup_fonts + @background = Color.new(@dsl.opts[:background] || ::Shoes::COLORS.fetch(:system_background)) @started = false initialize_shell initialize_real ::Shoes::Swt.register self attach_event_listeners initialize_scroll_bar + @redrawing_aspect = RedrawingAspect.new self, Shoes.display end def open # If something called quit during the app block's initial evaluation @@ -150,17 +171,31 @@ ::Swt.display.sleep unless ::Swt.display.readAndDispatch end end def self.setup_system_colors + # Skip it if we've already loaded the color! + return if ::Shoes::COLORS[:system_background] + # just one color for now background_color = Shoes.display.getSystemColor(::Swt::SWT::COLOR_WIDGET_BACKGROUND) - ::Shoes::DSL.define_shoes_color(:system_background, background_color.red, + ::Shoes::DSL.define_shoes_color(:system_background, + background_color.red, background_color.green, background_color.blue) end + # Because SWT shutdown is hard to reverse, we only let you do it once + # and warn you if you try to run again afterward. + def self.main_app_closed? + @main_app_closed + end + + def self.mark_main_app_closed + @main_app_closed = true + end + private def initialize_scroll_bar scroll_bar = @shell.vertical_bar scroll_bar.increment = 10 @@ -187,9 +222,10 @@ end def main_window_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 } end end def main_window_style