RenameDialog.qml 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. title: dialogTitle
  19. minimumWidth: UM.Theme.getSize("small_popup_dialog").width
  20. minimumHeight: UM.Theme.getSize("small_popup_dialog").height
  21. width: minimumWidth
  22. height: minimumHeight
  23. property variant catalog: UM.I18nCatalog { name: "cura" }
  24. signal textChanged(string text)
  25. signal selectText()
  26. onSelectText:
  27. {
  28. nameField.selectAll();
  29. nameField.focus = true;
  30. }
  31. Column
  32. {
  33. anchors.fill: parent
  34. UM.Label
  35. {
  36. text: base.explanation + "\n" //Newline to make some space using system theming.
  37. width: parent.width
  38. wrapMode: Text.WordWrap
  39. }
  40. Cura.TextField
  41. {
  42. id: nameField
  43. width: parent.width
  44. text: base.object
  45. maximumLength: 40
  46. selectByMouse: true
  47. onTextChanged: base.textChanged(text)
  48. }
  49. UM.Label
  50. {
  51. visible: !base.validName
  52. text: base.validationError
  53. }
  54. }
  55. rightButtons: [
  56. Cura.SecondaryButton
  57. {
  58. id: cancelButton
  59. text: catalog.i18nc("@action:button","Cancel")
  60. onClicked: base.reject()
  61. },
  62. Cura.PrimaryButton
  63. {
  64. id: okButton
  65. text: catalog.i18nc("@action:button", "OK")
  66. onClicked: base.accept()
  67. enabled: base.validName
  68. }
  69. ]
  70. }