826: def ask_for_hash_pair(parent)
827: key_input = type_input = value_input = nil
828:
829: dialog = Dialog.new("New (key, value) pair for Hash", nil, nil,
830: [ Stock::OK, Dialog::RESPONSE_ACCEPT ],
831: [ Stock::CANCEL, Dialog::RESPONSE_REJECT ]
832: )
833: dialog.width_request = 640
834:
835: hbox = HBox.new(false, 5)
836: hbox.pack_start(Label.new("Key:"), false)
837: hbox.pack_start(key_input = Entry.new)
838: key_input.text = @key || ''
839: dialog.vbox.pack_start(hbox, false)
840: key_input.signal_connect(:activate) do
841: if parent.any? { |c| c.content == key_input.text }
842: toplevel.display_status('Key already exists in Hash!')
843: key_input.text = ''
844: else
845: toplevel.display_status('Key has been changed.')
846: end
847: end
848:
849: hbox = HBox.new(false, 5)
850: hbox.pack_start(Label.new("Type:"), false)
851: hbox.pack_start(type_input = ComboBox.new(true))
852: ALL_TYPES.each { |t| type_input.append_text(t) }
853: type_input.active = @type || 0
854: dialog.vbox.pack_start(hbox, false)
855:
856: type_input.signal_connect(:changed) do
857: value_input.editable = false
858: case ALL_TYPES[type_input.active]
859: when 'Array', 'Hash'
860: value_input.text = ''
861: when 'TrueClass'
862: value_input.text = 'true'
863: when 'FalseClass'
864: value_input.text = 'false'
865: when 'NilClass'
866: value_input.text = 'null'
867: else
868: value_input.text = ''
869: value_input.editable = true
870: end
871: end
872:
873: hbox = HBox.new(false, 5)
874: hbox.pack_start(Label.new("Value:"), false)
875: hbox.pack_start(value_input = Entry.new)
876: value_input.width_chars = 60
877: value_input.text = @value || ''
878: dialog.vbox.pack_start(hbox, false)
879:
880: dialog.signal_connect('key-press-event''key-press-event', &DEFAULT_DIALOG_KEY_PRESS_HANDLER)
881: dialog.show_all
882: self.focus = dialog
883: dialog.run do |response|
884: if response == Dialog::RESPONSE_ACCEPT
885: @key = key_input.text
886: type = ALL_TYPES[@type = type_input.active]
887: content = value_input.text
888: return @key, type, content
889: end
890: end
891: return
892: ensure
893: dialog.destroy
894: end