Method: JSON::Editor::PopUpMenu#paste_node_appending

Defined in:
lib/gems/json_pure-1.1.3/lib/json/editor.rb

#paste_node_appending(item) ⇒ Object

Paste the data in the clipboard into the selected Array or Hash by appending it.



321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# File 'lib/gems/json_pure-1.1.3/lib/json/editor.rb', line 321

def paste_node_appending(item)
  if current = selection.selected
    if @clipboard_data
      case current.type
      when 'Array'
        Editor.data2model(@clipboard_data, model, current)
        expand_collapse(current)
      when 'Hash'
        if @clipboard_data.is_a? Hash
          parent = current.parent
          hash = Editor.model2data(current)
          model.remove(current)
          hash.update(@clipboard_data)
          Editor.data2model(hash, model, parent)
          if parent
            expand_collapse(parent)
          elsif @expanded
            expand_all
          end
          window.change
        else
          toplevel.display_status(
            "Cannot paste non-#{current.type} data into '#{current.type}'!")
        end
      else
        toplevel.display_status(
          "Cannot paste node below '#{current.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