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

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*a, &b) ⇒ Object



254
255
256
# File 'lib/json/editor.rb', line 254

def method_missing(*a, &b)
  treeview.__send__(*a, &b)
end

Instance Attribute Details

Returns the menu.



221
222
223
# File 'lib/json/editor.rb', line 221

def menu
  @menu
end

#treeviewObject (readonly)

Returns the Gtk::TreeView of this menu.



218
219
220
# File 'lib/json/editor.rb', line 218

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.



231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# 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') 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_separatorObject

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



224
225
226
# File 'lib/json/editor.rb', line 224

def add_separator
  menu.append SeparatorMenuItem.new
end

#createObject

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.

Raises:

  • (NotImplementedError)


250
251
252
# File 'lib/json/editor.rb', line 250

def create
  raise NotImplementedError
end

#initialize(treeview) ⇒ Object

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



212
213
214
215
# File 'lib/json/editor.rb', line 212

def initialize(treeview)
  @treeview = treeview
  @menu = Menu.new
end