Extended maintenance of Ruby versions 1.8.7 and 1.9.2 will end on July 31, 2014. Read more

In Files

  • json/lib/json/editor.rb

JSON::Editor::MenuExtension

This module bundles some method, that can be used to create a menu. It should be included into the class in question.

Attributes

treeview[R]

Returns the Gtk::TreeView of this menu.

Public Class Methods

new(treeview) click to toggle source

Creates a Menu, that includes MenuExtension. treeview is the Gtk::TreeView, on which it operates.

 
               # File json/lib/json/editor.rb, line 212
def initialize(treeview)
  @treeview = treeview
  @menu = Menu.new
end
            

Public Instance Methods

add_item(label, keyval = nil, klass = MenuItem, &callback) click to toggle source

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 json/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') 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
            
add_separator() click to toggle source

Adds a Gtk::SeparatorMenuItem to this instance’s menu.

 
               # File json/lib/json/editor.rb, line 224
def add_separator
  menu.append SeparatorMenuItem.new
end
            
create() click to toggle source

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.

 
               # File json/lib/json/editor.rb, line 250
def create
  raise NotImplementedError
end
            
method_missing(*a, &b) click to toggle source
 
               # File json/lib/json/editor.rb, line 254
def method_missing(*a, &b)
  treeview.__send__(*a, &b)
end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus