Method: JSON::Editor::PopUpMenu#paste_node_inserting_before

Defined in:
lib/json/editor.rb

#paste_node_inserting_before(item) ⇒ Object

Paste the data in the clipboard into the selected Array inserting it before the selected element.



358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
# File 'lib/json/editor.rb', line 358

def paste_node_inserting_before(item)
  if current = selection.selected
    if @clipboard_data
      parent = current.parent or return
      parent_type = parent.type
      if parent_type == 'Array'
        selected_index = parent.each_with_index do |c, i|
          break i if c == current
        end
        Editor.data2model(@clipboard_data, model, parent) do |m|
          m.insert_before(parent, current)
        end
        expand_collapse(current)
        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("Nothing to paste in clipboard!")
    end
  else
      toplevel.display_status("Append a node into the root first!")
  end
end