Module: JSON::Editor::MenuExtension
- Includes:
- Gtk
- Included in:
- EditMenu, FileMenu, OptionsMenu, PopUpMenu
- Defined in:
- lib/json/editor.rb
Overview
This module bundles some method, that can be used to create a menu. It should be included into the class in question.
Instance Attribute Summary collapse
-
#menu ⇒ Object
readonly
Returns the menu.
-
#treeview ⇒ Object
readonly
Returns the Gtk::TreeView of this menu.
Instance Method Summary collapse
-
#add_item(label, klass = MenuItem, &callback) ⇒ Object
Adds a Gtk::MenuItem to this instance’s #menu.
-
#add_separator ⇒ Object
Adds a Gtk::SeparatorMenuItem to this instance’s #menu.
-
#create ⇒ Object
This method should be implemented in subclasses to create the #menu of this instance.
-
#initialize(treeview) ⇒ Object
Creates a Menu, that includes MenuExtension.
- #method_missing(*a, &b) ⇒ Object
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*a, &b) ⇒ Object
223 224 225 |
# File 'lib/json/editor.rb', line 223 def method_missing(*a, &b) treeview.__send__(*a, &b) end |
Instance Attribute Details
#menu ⇒ Object (readonly)
Returns the menu.
199 200 201 |
# File 'lib/json/editor.rb', line 199 def @menu end |
#treeview ⇒ Object (readonly)
Returns the Gtk::TreeView of this menu.
196 197 198 |
# File 'lib/json/editor.rb', line 196 def treeview @treeview end |
Instance Method Details
#add_item(label, klass = MenuItem, &callback) ⇒ Object
Adds a Gtk::MenuItem to this instance’s #menu. label is the label string, klass is the item type, and callback is the procedure, that is called if the item is activated.
209 210 211 212 213 214 |
# File 'lib/json/editor.rb', line 209 def add_item(label, klass = MenuItem, &callback) item = klass.new(label) item.signal_connect(:activate, &callback) .append item item end |
#add_separator ⇒ Object
Adds a Gtk::SeparatorMenuItem to this instance’s #menu.
202 203 204 |
# File 'lib/json/editor.rb', line 202 def add_separator .append SeparatorMenuItem.new end |
#create ⇒ Object
This method should be implemented in subclasses to create the #menu of this instance. It has to be called after an instance of this class is created, to build the menu.
219 220 221 |
# File 'lib/json/editor.rb', line 219 def create raise NotImplementedError end |
#initialize(treeview) ⇒ Object
Creates a Menu, that includes MenuExtension. treeview is the Gtk::TreeView, on which it operates.
190 191 192 193 |
# File 'lib/json/editor.rb', line 190 def initialize(treeview) @treeview = treeview @menu = Menu.new end |