| Module | MenuExtension |
| In: |
lib/json/editor.rb
|
This module bundles some method, that can be used to create a menu. It should be included into the class in question.
| menu | [R] | Returns the menu. |
| treeview | [R] | Returns the Gtk::TreeView of this menu. |
Creates a Menu, that includes MenuExtension. treeview is the Gtk::TreeView, on which it operates.
# File lib/json/editor.rb, line 212 def initialize(treeview) @treeview = treeview @menu = Menu.new end
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.
# File lib/json/editor.rb, line 231 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''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 menu.append item item end
Adds a Gtk::SeparatorMenuItem to this instance‘s menu.
# File lib/json/editor.rb, line 224 def add_separator menu.append SeparatorMenuItem.new end