RenameDialog.qml 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. buttonSpacing: UM.Theme.getSize("default_margin").width
  12. property string object: ""
  13. property alias newName: nameField.text
  14. property bool validName: true
  15. property string validationError
  16. property string dialogTitle: catalog.i18nc("@title:window", "Rename")
  17. property string explanation: catalog.i18nc("@info", "Please provide a new name.")
  18. property string okButtonText: catalog.i18nc("@action:button", "OK")
  19. property list<Item> extraInfo
  20. title: dialogTitle
  21. backgroundColor: UM.Theme.getColor("main_background")
  22. minimumWidth: UM.Theme.getSize("small_popup_dialog").width
  23. minimumHeight: UM.Theme.getSize("small_popup_dialog").height
  24. width: minimumWidth
  25. height: minimumHeight
  26. property variant catalog: UM.I18nCatalog { name: "cura" }
  27. signal textChanged(string text)
  28. signal selectText()
  29. onSelectText:
  30. {
  31. nameField.selectAll();
  32. nameField.focus = true;
  33. }
  34. Column
  35. {
  36. anchors.fill: parent
  37. UM.Label
  38. {
  39. text: base.explanation + "\n" //Newline to make some space using system theming.
  40. width: parent.width
  41. wrapMode: Text.WordWrap
  42. }
  43. Cura.TextField
  44. {
  45. id: nameField
  46. width: parent.width
  47. text: base.object
  48. maximumLength: 40
  49. selectByMouse: true
  50. onTextChanged: base.textChanged(text)
  51. }
  52. Row
  53. {
  54. children: extraInfo
  55. }
  56. UM.Label
  57. {
  58. visible: !base.validName
  59. text: base.validationError
  60. }
  61. }
  62. leftButtons:
  63. [
  64. Cura.TertiaryButton
  65. {
  66. id: cancelButton
  67. text: catalog.i18nc("@action:button","Cancel")
  68. onClicked: base.reject()
  69. }
  70. ]
  71. rightButtons:
  72. [
  73. Cura.PrimaryButton
  74. {
  75. id: okButton
  76. text: base.okButtonText
  77. onClicked: base.accept()
  78. enabled: base.validName
  79. }
  80. ]
  81. }