Method: JSON::Editor::PopUpMenu#insert_new_node
- Defined in:
- lib/json/editor.rb
#insert_new_node(item) ⇒ Object
Insert a new node into an Array before the selected element.
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 |
# File 'lib/json/editor.rb', line 417 def insert_new_node(item) if current = selection.selected parent = current.parent or return parent_parent = parent.parent parent_type = parent.type if parent_type == 'Array' selected_index = parent.each_with_index do |c, i| break i if c == current end type, content = ask_for_element(parent) type or return iter = model.insert_before(parent, current) iter.type, iter.content = type, content toplevel.display_status("Inserted an element to " + "'#{parent_type}' before index #{selected_index}.") window.change else toplevel.display_status( "Cannot insert node below '#{parent_type}'!") end else toplevel.display_status("Append a node into the root first!") end end |