Sha256: d356b068c9d901836652ff3e5e772e80ca942ea5ce410441ee27c6292e682b7a

Contents?: true

Size: 1.85 KB

Versions: 37

Compression:

Stored size: 1.85 KB

Contents

module Redcar
  class Menu
    class Item
      class Separator < Item
        def initialize(options={})
          super(nil, options)
        end
        
        def is_unique?
          true
        end
      end
      
      attr_reader :command, :priority, :value, :type, :active
  
      # Create a new Item, with the given text to display in the menu, and
      # either:
      #   the Redcar::Command that is run when the item is selected.
      #   or a block to run when the item is selected
      def initialize(text, options={}, &block)
        @text = text
        
        if options.respond_to?('[]')
          @command = options[:command] || block
          @priority = options[:priority]
          @value = options[:value]
          @type = options[:type]
          @active = options[:active] ? true : false
        # This branch is for compatibility with old code. Please use :command 
        # option in new code
        # FIXME: Should this be removed at some point?
        else
          @command = options || block
        end
        
        @priority ||= Menu::DEFAULT_PRIORITY
      end
      
      # Call this to signal that the menu item has been selected by the user.
      def selected(with_key=false)
        if @value
          @command.new.run(:value => @value)
        else  
          @command.new.run#(:with_key => with_key)
        end
      end
      
      def type
        @type
      end
      
      def type
        @type
      end
      
      def text
        @text.is_a?(Proc) ? @text.call : @text
      end
      
      def lazy_text?
        @text.is_a?(Proc)
      end
      
      def merge(other)
        @command = other.command
        @priority = other.priority
      end
      
      def ==(other)
        text == other.text and command == other.command
      end
      
      def is_unique?
        false
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 2 rubygems

Version Path
redcar-0.12.1 plugins/application/lib/application/menu/item.rb
redcar-0.12 plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.27dev plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.26dev plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.25dev plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.24dev plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.23dev plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.22dev plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.21dev plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.20dev plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.19dev plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.18dev plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.17dev plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.16dev-java plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.15dev-java plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.14dev-java plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.13dev-java plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.12dev-java plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.11dev-java plugins/application/lib/application/menu/item.rb
redcar-dev-0.12.10dev-java plugins/application/lib/application/menu/item.rb