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