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, keyval = nil, 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
253 254 255 |
# File 'lib/json/editor.rb', line 253 def method_missing(*a, &b) treeview.__send__(*a, &b) end |
Instance Attribute Details
#menu ⇒ Object (readonly)
Returns the menu.
220 221 222 |
# File 'lib/json/editor.rb', line 220 def @menu end |
#treeview ⇒ Object (readonly)
Returns the Gtk::TreeView of this menu.
217 218 219 |
# File 'lib/json/editor.rb', line 217 def treeview @treeview end |
Instance Method Details
#add_item(label, keyval = nil, 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.
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 |
# File 'lib/json/editor.rb', line 230 def add_item(label, keyval = nil, klass = MenuItem, &callback) label = "#{label} (C-#{keyval.chr})" if keyval item = klass.new(label) item.signal_connect(:activate, &callback) if keyval self.signal_connect(:'key-press-event') do |item, event| if event.state & Gdk::Window::ModifierType::CONTROL_MASK != 0 and event.keyval == keyval callback.call item end end end .append item item end |
#add_separator ⇒ Object
Adds a Gtk::SeparatorMenuItem to this instance’s #menu.
223 224 225 |
# File 'lib/json/editor.rb', line 223 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.
249 250 251 |
# File 'lib/json/editor.rb', line 249 def create raise NotImplementedError end |
#initialize(treeview) ⇒ Object
Creates a Menu, that includes MenuExtension. treeview is the Gtk::TreeView, on which it operates.
211 212 213 214 |
# File 'lib/json/editor.rb', line 211 def initialize(treeview) @treeview = treeview @menu = Menu.new end |