| 1 | /* |
| 2 | Copyright - 2017 2023 - wwwouaiebe - Contact: https://www.ouaie.be/ |
| 3 | |
| 4 | This program is free software; |
| 5 | you can redistribute it and/or modify it under the terms of the |
| 6 | GNU General Public License as published by the Free Software Foundation; |
| 7 | either version 3 of the License, or any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program; if not, write to the Free Software |
| 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | /* |
| 19 | Changes: |
| 20 | - v4.0.0: |
| 21 | - created from v3.6.0 |
| 22 | Doc reviewed 202208 |
| 23 | */ |
| 24 | |
| 25 | /* ---------------------------------------------------------------------------------------------------------------------------*/ |
| 26 | /** |
| 27 | Simple container to store a menu item |
| 28 | */ |
| 29 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
| 30 | |
| 31 | class MenuItem { |
| 32 | |
| 33 | /** |
| 34 | The text to be displayed in the menu |
| 35 | @type {String} |
| 36 | */ |
| 37 | |
| 38 | #itemText; |
| 39 | |
| 40 | /** |
| 41 | A flag indicating if the menu item can be selected in the menu. Non selectable menu items are |
| 42 | displayed in gray in the menu |
| 43 | @type {Boolean} |
| 44 | */ |
| 45 | |
| 46 | #isActive; |
| 47 | |
| 48 | /** |
| 49 | The action to execute when the item is selected |
| 50 | @type {function} |
| 51 | */ |
| 52 | |
| 53 | #action; |
| 54 | |
| 55 | /** |
| 56 | The constructor |
| 57 | @param {String} itemText The text to be displayed in the menu |
| 58 | @param {Boolean} isActive A flag indicating if the menu item can be selected in the menu |
| 59 | @param {function} action The action to execute when the item is selected |
| 60 | */ |
| 61 | |
| 62 | constructor ( itemText, isActive, action ) { |
| 63 | Object.freeze ( this ); |
| 64 | this.#itemText = itemText; |
| 65 | this.#isActive = isActive; |
| 66 | this.#action = action; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | The text to be displayed in the menu |
| 71 | @type {String} |
| 72 | */ |
| 73 | |
| 74 | get itemText ( ) { return this.#itemText; } |
| 75 | |
| 76 | /** |
| 77 | A flag indicating if the menu item can be selected in the menu. Non selectable menu items are |
| 78 | displayed in gray in the menu |
| 79 | @type {Boolean} |
| 80 | */ |
| 81 | |
| 82 | get isActive ( ) { return this.#isActive; } |
| 83 | |
| 84 | /** |
| 85 | Execute the action registered for the item |
| 86 | */ |
| 87 | |
| 88 | doAction ( ) { this.#action ( ); } |
| 89 | } |
| 90 | |
| 91 | export default MenuItem; |
| 92 | |
| 93 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
| 94 |