RenameBlock.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
  3. *
  4. * This file is part of the QCAD project.
  5. *
  6. * QCAD is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * QCAD is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with QCAD.
  18. */
  19. include("scripts/Block/Block.js");
  20. include("../BlockDialog.js");
  21. /**
  22. * \class RenameBlock
  23. * \ingroup ecma_block
  24. * \brief Renames the active (selected) block.
  25. */
  26. function RenameBlock(guiAction) {
  27. Block.call(this, guiAction);
  28. }
  29. RenameBlock.prototype = new Block();
  30. RenameBlock.prototype.beginEvent = function() {
  31. Block.prototype.beginEvent.call(this);
  32. var blockId = Block.getActiveBlockId();
  33. if (blockId===RObject.INVALID_ID) {
  34. this.terminate();
  35. return;
  36. }
  37. var doc = this.getDocument();
  38. var block = doc.queryBlock(blockId);
  39. var dlg = this.createDialog(doc, block);
  40. if (isNull(dlg)) {
  41. this.terminate();
  42. return;
  43. }
  44. var newBlock = dlg.show();
  45. if (isNull(newBlock)) {
  46. this.terminate();
  47. return;
  48. }
  49. var op = new RAddObjectOperation(newBlock);
  50. op.setText(this.getToolTitle());
  51. var di = this.getDocumentInterface();
  52. di.applyOperation(op);
  53. di.clearPreview();
  54. di.repaintViews();
  55. this.terminate();
  56. };
  57. RenameBlock.prototype.createDialog = function(doc, block) {
  58. return new BlockDialog(doc, block, true, true);
  59. };