ask_for_element (JSONTreeView)

         # File lib/json/editor.rb, line 902
    902:       def ask_for_element(parent = nil, default_type = nil, value_text = @content)
    903:         type_input = value_input = nil
    904:
    905:         dialog = Dialog.new(
    906:           "New element into #{parent ? parent.type : 'root'}",
    907:           nil, nil,
    908:           [ Stock::OK, Dialog::RESPONSE_ACCEPT ],
    909:           [ Stock::CANCEL, Dialog::RESPONSE_REJECT ]
    910:         )
    911:         hbox = HBox.new(false, 5)
    912:         hbox.pack_start(Label.new("Type:"), false)
    913:         hbox.pack_start(type_input = ComboBox.new(true))
    914:         default_active = 0
    915:         types = parent ? ALL_TYPES : CONTAINER_TYPES
    916:         types.each_with_index do |t, i|
    917:           type_input.append_text(t)
    918:           if t == default_type
    919:             default_active = i
    920:           end
    921:         end
    922:         type_input.active = default_active
    923:         dialog.vbox.pack_start(hbox, false)
    924:         type_input.signal_connect(:changed) do
    925:           configure_value(value_input, types[type_input.active])
    926:         end
    927:
    928:         hbox = HBox.new(false, 5)
    929:         hbox.pack_start(Label.new("Value:"), false)
    930:         hbox.pack_start(value_input = Entry.new)
    931:         value_input.width_chars = 60
    932:         value_input.text = value_text if value_text
    933:         configure_value(value_input, types[type_input.active])
    934:
    935:         dialog.vbox.pack_start(hbox, false)
    936:
    937:         dialog.signal_connect('key-press-event''key-press-event', &DEFAULT_DIALOG_KEY_PRESS_HANDLER)
    938:         dialog.show_all
    939:         self.focus = dialog
    940:         dialog.run do |response|
    941:           if response == Dialog::RESPONSE_ACCEPT
    942:             type = types[type_input.active]
    943:             @content = case type
    944:             when 'Numeric'
    945:               if (t = value_input.text) == 'Infinity'
    946:                 1 / 0.0
    947:               else
    948:                 Integer(t) rescue Float(t) rescue 0
    949:               end
    950:             else
    951:               value_input.text
    952:             end.to_s
    953:             return type, @content
    954:           end
    955:         end
    956:         return
    957:       ensure
    958:         dialog.destroy if dialog
    959:       end