Sha256: 4795cd726730d330d4ed354f967c32a4203db489d403cd4f832e52bc79517187

Contents?: true

Size: 1.41 KB

Versions: 5

Compression:

Stored size: 1.41 KB

Contents

class Shoes
  module Swt
    class Dialog
      SWT = ::Swt::SWT
      ALERT_STYLE   = SWT::OK | SWT::ICON_INFORMATION
      CONFIRM_STYLE = SWT::YES | SWT::NO | SWT::ICON_QUESTION

      def alert(msg = '')
        open_message_box ALERT_STYLE, msg
        nil
      end

      def confirm(msg = '')
        answer_id = open_message_box CONFIRM_STYLE, msg
        confirmed? answer_id
      end

      def dialog_chooser(title, folder = false, style = :open)
        style = (style == :save ? ::Swt::SWT::SAVE : ::Swt::SWT::OPEN)
        shell = ::Swt::Widgets::Shell.new Shoes.display
        fd = folder ? ::Swt::Widgets::DirectoryDialog.new(shell, style) : ::Swt::Widgets::FileDialog.new(shell, style)
        fd.setText title
        fd.open
      end

      def ask_color(title)
        shell = ::Swt::Widgets::Shell.new Shoes.display
        cd = ::Swt::Widgets::ColorDialog.new shell
        cd.setText title
        color = cd.open
        color ? ::Shoes::Color.new(color.red, color.green, color.blue, ::Shoes::Color::OPAQUE) : ::Shoes::Color.new(0, 0, 0, ::Shoes::Color::OPAQUE)
      end

      private

      def open_message_box(style, msg)
        shell = ::Swt::Widgets::Shell.new ::Swt.display
        @message_box = ::Swt::Widgets::MessageBox.new shell, style
        @message_box.message = msg.to_s
        @message_box.open
      end

      def confirmed?(answer_id)
        answer_id == SWT::YES
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
shoes-swt-4.0.0.pre8 lib/shoes/swt/dialog.rb
shoes-swt-4.0.0.pre7 lib/shoes/swt/dialog.rb
shoes-swt-4.0.0.pre6 lib/shoes/swt/dialog.rb
shoes-swt-4.0.0.pre5 lib/shoes/swt/dialog.rb
shoes-swt-4.0.0.pre4 lib/shoes/swt/dialog.rb