PropertiesDialog.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * PropertiesDialog.js
  3. *
  4. * @author realor
  5. */
  6. import { Dialog } from './Dialog.js'
  7. import { I18N } from '../i18n/I18N.js'
  8. class PropertiesDialog extends Dialog {
  9. constructor(application, object) {
  10. super('title.properties')
  11. this.application = application
  12. this.object = object
  13. this.setI18N(this.application.i18n)
  14. this.setSize(640, 500)
  15. let json = JSON.stringify(object.userData, null, 2)
  16. this.editorView = this.addCodeEditor('editor', 'label.properties', json, { language: 'json', height: 'calc(100% - 50px' })
  17. this.errorElem = document.createElement('div')
  18. this.errorElem.className = 'error'
  19. this.bodyElem.appendChild(this.errorElem)
  20. this.addButton('accept', 'button.accept', () => {
  21. this.onAccept()
  22. })
  23. this.cancelButton = this.addButton('cancel', 'button.cancel', () => this.onCancel())
  24. }
  25. onShow() {
  26. this.editorView.focus()
  27. }
  28. onAccept() {
  29. try {
  30. const json = this.editorView.state.doc.toString()
  31. let properties = JSON.parse(json)
  32. this.object.userData = properties
  33. this.application.notifyObjectsChanged(this.object, this)
  34. this.hide()
  35. } catch (ex) {
  36. this.errorElem.innerHTML = String(ex)
  37. }
  38. }
  39. onCancel() {
  40. this.hide()
  41. }
  42. }
  43. export { PropertiesDialog }