RenameDialog.qml 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright (c) 2022 Ultimaker B.V.
  2. // Uranium is released under the terms of the LGPLv3 or higher.
  3. import QtQuick 2.1
  4. import QtQuick.Controls 2.0
  5. import QtQuick.Window 2.1
  6. import UM 1.5 as UM
  7. import Cura 1.0 as Cura
  8. UM.Dialog
  9. {
  10. id: base
  11. property string object: ""
  12. property alias newName: nameField.text
  13. property bool validName: true
  14. property string validationError
  15. property string dialogTitle: catalog.i18nc("@title:window", "Rename")
  16. property string explanation: catalog.i18nc("@info", "Please provide a new name.")
  17. title: dialogTitle
  18. minimumWidth: UM.Theme.getSize("small_popup_dialog").width
  19. minimumHeight: UM.Theme.getSize("small_popup_dialog").height
  20. width: minimumWidth
  21. height: minimumHeight
  22. property variant catalog: UM.I18nCatalog { name: "cura" }
  23. signal textChanged(string text)
  24. signal selectText()
  25. onSelectText:
  26. {
  27. nameField.selectAll();
  28. nameField.focus = true;
  29. }
  30. Column
  31. {
  32. anchors.fill: parent
  33. UM.Label
  34. {
  35. text: base.explanation + "\n" //Newline to make some space using system theming.
  36. width: parent.width
  37. wrapMode: Text.WordWrap
  38. }
  39. Cura.TextField
  40. {
  41. id: nameField
  42. width: parent.width
  43. text: base.object
  44. maximumLength: 40
  45. selectByMouse: true
  46. onTextChanged: base.textChanged(text)
  47. }
  48. UM.Label
  49. {
  50. visible: !base.validName
  51. text: base.validationError
  52. }
  53. }
  54. Item
  55. {
  56. ButtonGroup {
  57. buttons: [cancelButton, okButton]
  58. checkedButton: okButton
  59. }
  60. }
  61. rightButtons: [
  62. Cura.SecondaryButton
  63. {
  64. id: cancelButton
  65. text: catalog.i18nc("@action:button","Cancel")
  66. onClicked: base.reject()
  67. },
  68. Cura.PrimaryButton
  69. {
  70. id: okButton
  71. text: catalog.i18nc("@action:button", "OK")
  72. onClicked: base.accept()
  73. enabled: base.validName
  74. }
  75. ]
  76. }