Class: HandyToolbox::Menu

Inherits:
Object
  • Object
show all
Defined in:
lib/handy_toolbox/menu.rb

Direct Known Subclasses

MenuLoader

Constant Summary collapse

ICON =
' + '.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, group) ⇒ Menu

Returns a new instance of Menu.



8
9
10
11
12
13
14
15
16
17
# File 'lib/handy_toolbox/menu.rb', line 8

def initialize(parent, group)
  @id = Ids.next
  @parent = parent
  @group = group
  @children = []

  if !parent.nil?
    @children << MenuBack.new(parent)
  end
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



6
7
8
# File 'lib/handy_toolbox/menu.rb', line 6

def children
  @children
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/handy_toolbox/menu.rb', line 6

def id
  @id
end

#parentObject (readonly)

Returns the value of attribute parent.



6
7
8
# File 'lib/handy_toolbox/menu.rb', line 6

def parent
  @parent
end

#toolsObject (readonly)

Returns the value of attribute tools.



6
7
8
# File 'lib/handy_toolbox/menu.rb', line 6

def tools
  @tools
end

Instance Method Details

#iconObject



44
45
46
# File 'lib/handy_toolbox/menu.rb', line 44

def icon
  ICON
end

Yields:



19
20
21
22
23
# File 'lib/handy_toolbox/menu.rb', line 19

def menu(group, &block)
  menu = Menu.new(self, group)
  children << menu
  yield menu if block_given?
end


25
26
27
28
29
# File 'lib/handy_toolbox/menu.rb', line 25

def menu_loader(group, loader_class)
  loader = loader_class.new
  menu = MenuLoader.new(self, group, loader)
  children << menu
end

#plugin(plugin_class) ⇒ Object



35
36
37
38
# File 'lib/handy_toolbox/menu.rb', line 35

def plugin(plugin_class)
  plugin = plugin_class.new
  plugin.on_attach(self)
end

#to_sObject



40
41
42
# File 'lib/handy_toolbox/menu.rb', line 40

def to_s
  @group
end

#tool(cmd, opts = {}) ⇒ Object



31
32
33
# File 'lib/handy_toolbox/menu.rb', line 31

def tool(cmd, opts = {})
  children << ToolMenuItem.new(parent, Tool.new(cmd, opts))
end