Sha256: ee96da0e790c2da37a31b7aa14cd35d5c0945d0b84e385148f2325b5f4fd33fc

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

require 'clevic/action_builder.rb'
require 'clevic/swing/action.rb'
require 'clevic/swing/extensions.rb'

require 'changes'

module Clevic

module ActionBuilder
  # Create a new separator and add a new separator.
  def separator
    Separator.new.tap do |action|
      add_action action
      collect_actions << action
    end
  end
  
  def create_action( &block )
    Action.new( self ).tap( &block )
  end
  
  # set up the code to be executed when an action is triggered,
  def action_method_or_block( action, options, &block )
    # connect the action to some code
    if options.has_key?( :method )
      action.handler do |event|
        puts "#{__FILE__}:#{__LINE__}:action.name: #{action.name.inspect}"
        action_triggered do
          # active is from Qt checkbox-menu-items
          send_args = [ options[:method], options.has_key?( :checkable ) ? action.menu_item.selected? : nil ].compact
          send( *send_args )
        end
      end
    else
      unless block.nil?
        # TODO not sure why triggered is outside here, but not in the method section
        action_triggered do
          action.handler do |event|
            yield( event )
          end
        end
      end
    end
  end
end

end # Clevic

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
clevic-0.13.0.b3 lib/clevic/swing/action_builder.rb
clevic-0.13.0.b2 lib/clevic/swing/action_builder.rb
clevic-0.13.0.b1 lib/clevic/swing/action_builder.rb