Method: JSON::Editor::JSONTreeView#ask_for_order

Defined in:
lib/json/editor.rb

#ask_for_orderObject

Ask for an order criteria for sorting, using x for the element in question. Returns the order criterium, and true/false for reverse sorting.



893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
# File 'lib/json/editor.rb', line 893

def ask_for_order
  dialog = Dialog.new(
    "Give an order criterium for 'x'.",
    nil, nil,
    [ Stock::OK, Dialog::RESPONSE_ACCEPT ],
    [ Stock::CANCEL, Dialog::RESPONSE_REJECT ]
  )
  hbox = HBox.new(false, 5)

  hbox.add(Label.new("Order:"))
  hbox.pack_start(order_input = Entry.new)
  order_input.text = @order || 'x'

  hbox.pack_start(reverse_checkbox = CheckButton.new('Reverse'))

  dialog.vbox.add(hbox)

  dialog.show_all
  dialog.run do |response| 
    if response == Dialog::RESPONSE_ACCEPT
      return @order = order_input.text, reverse_checkbox.active?
    end
  end
  return
ensure
  dialog.destroy if dialog
end