808: def ask_for_hash_pair(parent)
809: key_input = type_input = value_input = nil
810:
811: dialog = Dialog.new("New (key, value) pair for Hash", nil, nil,
812: [ Stock::OK, Dialog::RESPONSE_ACCEPT ],
813: [ Stock::CANCEL, Dialog::RESPONSE_REJECT ]
814: )
815:
816: hbox = HBox.new(false, 5)
817: hbox.pack_start(Label.new("Key:"))
818: hbox.pack_start(key_input = Entry.new)
819: key_input.text = @key || ''
820: dialog.vbox.add(hbox)
821: key_input.signal_connect(:activate) do
822: if parent.any? { |c| c.content == key_input.text }
823: toplevel.display_status('Key already exists in Hash!')
824: key_input.text = ''
825: else
826: toplevel.display_status('Key has been changed.')
827: end
828: end
829:
830: hbox = HBox.new(false, 5)
831: hbox.add(Label.new("Type:"))
832: hbox.pack_start(type_input = ComboBox.new(true))
833: ALL_TYPES.each { |t| type_input.append_text(t) }
834: type_input.active = @type || 0
835: dialog.vbox.add(hbox)
836:
837: type_input.signal_connect(:changed) do
838: value_input.editable = false
839: case ALL_TYPES[type_input.active]
840: when 'Array', 'Hash'
841: value_input.text = ''
842: when 'TrueClass'
843: value_input.text = 'true'
844: when 'FalseClass'
845: value_input.text = 'false'
846: when 'NilClass'
847: value_input.text = 'null'
848: else
849: value_input.text = ''
850: value_input.editable = true
851: end
852: end
853:
854: hbox = HBox.new(false, 5)
855: hbox.add(Label.new("Value:"))
856: hbox.pack_start(value_input = Entry.new)
857: value_input.text = @value || ''
858: dialog.vbox.add(hbox)
859:
860: dialog.signal_connect('key-press-event''key-press-event', &DEFAULT_DIALOG_KEY_PRESS_HANDLER)
861: dialog.show_all
862: self.focus = dialog
863: dialog.run do |response|
864: if response == Dialog::RESPONSE_ACCEPT
865: @key = key_input.text
866: type = ALL_TYPES[@type = type_input.active]
867: content = value_input.text
868: return @key, type, content
869: end
870: end
871: return
872: ensure
873: dialog.destroy
874: end