* Triggered when brick view replace button has been clicked. * @protected * @param {Brick} brick
(brick)
| 889 | * @param {Brick} brick |
| 890 | */ |
| 891 | async brickReplaceButtonDidClick (brick) { |
| 892 | // Show only bricks of the same type in the modal view |
| 893 | const modalView = this.getLibraryModalView() |
| 894 | modalView.applyFilter(brickMeta => brickMeta.type === brick.getMeta().type) |
| 895 | |
| 896 | // Ignore event when library modal view is already visible |
| 897 | if (modalView.isVisible()) { |
| 898 | return |
| 899 | } |
| 900 | |
| 901 | let name = brick.getMeta().name |
| 902 | try { |
| 903 | name = await modalView.prompt(name) |
| 904 | } catch (error) { |
| 905 | // Stop here when user cancels the modal view |
| 906 | return |
| 907 | } |
| 908 | |
| 909 | // Replace brick only if a different one is selected |
| 910 | if (name !== brick.getMeta().name) { |
| 911 | const replacement = this.getBrickFactory().create(name) |
| 912 | if ((brick instanceof Encoder) && (replacement instanceof Encoder)) { |
| 913 | // Apply the same reverse state on the replacement brick |
| 914 | replacement.setReverse(brick.isReverse()) |
| 915 | } |
| 916 | this.replaceBrick(brick, replacement) |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | /** |
| 921 | * Triggered when view add button has been clicked. |
no test coverage detected