Sha256: 403e45bfdacf82431dbf007d38c7e3566bdf5599e81eb0bfbc3301ea8214bf79

Contents?: true

Size: 1.4 KB

Versions: 4

Compression:

Stored size: 1.4 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 :text, :command, :priority
  
      # 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]
        # 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)
        @command.new.run#(:with_key => with_key)
      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

4 entries across 4 versions & 1 rubygems

Version Path
redcar-0.3.10.1dev plugins/application/lib/application/menu/item.rb
redcar-0.3.10.0dev plugins/application/lib/application/menu/item.rb
redcar-0.3.9 plugins/application/lib/application/menu/item.rb
redcar-0.3.9.0dev plugins/application/lib/application/menu/item.rb