sort (EditMenu)

         # File lib/json/editor.rb, line 611
    611:       def sort(item)
    612:         if current = selection.selected
    613:           if current.type == 'Array'
    614:             parent = current.parent
    615:             ary = Editor.model2data(current)
    616:             order, reverse = ask_for_order
    617:             order or return
    618:             begin
    619:               block = eval "lambda { |x| #{order} }"
    620:               if reverse
    621:                 ary.sort! { |a,b| block[b] <=> block[a] }
    622:               else
    623:                 ary.sort! { |a,b| block[a] <=> block[b] }
    624:               end
    625:             rescue => e
    626:               Editor.error_dialog(self, "Failed to sort Array with #{order}: #{e}!")
    627:             else
    628:               Editor.data2model(ary, model, parent) do |m|
    629:                 m.insert_before(parent, current)
    630:               end
    631:               model.remove(current)
    632:               expand_collapse(parent)
    633:               window.change
    634:               toplevel.display_status("Array has been sorted.")
    635:             end
    636:           else
    637:             toplevel.display_status("Only Array nodes can be sorted!")
    638:           end
    639:         else
    640:             toplevel.display_status("Select an Array to sort first!")
    641:         end
    642:       end