877: def ask_for_element(parent = nil, default_type = nil, value_text = @content)
878: type_input = value_input = nil
879:
880: dialog = Dialog.new(
881: "New element into #{parent ? parent.type : 'root'}",
882: nil, nil,
883: [ Stock::OK, Dialog::RESPONSE_ACCEPT ],
884: [ Stock::CANCEL, Dialog::RESPONSE_REJECT ]
885: )
886: hbox = HBox.new(false, 5)
887: hbox.add(Label.new("Type:"))
888: hbox.pack_start(type_input = ComboBox.new(true))
889: default_active = 0
890: types = parent ? ALL_TYPES : CONTAINER_TYPES
891: types.each_with_index do |t, i|
892: type_input.append_text(t)
893: if t == default_type
894: default_active = i
895: end
896: end
897: type_input.active = default_active
898: dialog.vbox.add(hbox)
899: type_input.signal_connect(:changed) do
900: configure_value(value_input, types[type_input.active])
901: end
902:
903: hbox = HBox.new(false, 5)
904: hbox.add(Label.new("Value:"))
905: hbox.pack_start(value_input = Entry.new)
906: value_input.text = value_text if value_text
907: configure_value(value_input, types[type_input.active])
908:
909: dialog.vbox.add(hbox)
910:
911: dialog.signal_connect('key-press-event''key-press-event', &DEFAULT_DIALOG_KEY_PRESS_HANDLER)
912: dialog.show_all
913: self.focus = dialog
914: dialog.run do |response|
915: if response == Dialog::RESPONSE_ACCEPT
916: type = types[type_input.active]
917: @content = case type
918: when 'Numeric'
919: Integer(value_input.text) rescue Float(value_input.text) rescue 0
920: else
921: value_input.text
922: end.to_s
923: return type, @content
924: end
925: end
926: return
927: ensure
928: dialog.destroy if dialog
929: end